diff options
| author | 2012-10-22 18:00:13 +0200 | |
|---|---|---|
| committer | 2012-10-22 18:00:13 +0200 | |
| commit | 0426541acbeb44d240e6dbf7a93f3a104bea61b4 (patch) | |
| tree | 209a425c5afee9e627d11023b262326812be1fbc /app/models/Category.php | |
| parent | fb57be5a5af3a2fb46b2dbf2b503ffe78eb5cf49 (diff) | |
Grosse màj : ajout de la configuration + ajouts divers fonctionnalités
Diffstat (limited to 'app/models/Category.php')
| -rwxr-xr-x | app/models/Category.php | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/app/models/Category.php b/app/models/Category.php new file mode 100755 index 000000000..5b5d45b15 --- /dev/null +++ b/app/models/Category.php @@ -0,0 +1,113 @@ +<?php + +class Category extends Model { + private $id; + private $name; + private $color; + + public function __construct ($name = '', $color = '#0062BE') { + $this->_name ($name); + $this->_color ($color); + } + + public function id () { + return small_hash ($this->name . Configuration::selApplication ()); + } + public function name () { + return $this->name; + } + public function color () { + return $this->color; + } + + public function _name ($value) { + $this->name = $value; + } + public function _color ($value) { + if (preg_match ('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { + $this->color = $value; + } else { + $this->color = '#0062BE'; + } + } +} + +class CategoryDAO extends Model_array { + public function __construct () { + parent::__construct (PUBLIC_PATH . '/data/db/Categories.array.php'); + } + + public function addCategory ($values) { + $id = $values['id']; + unset ($values['id']); + + if (!isset ($this->array[$id])) { + $this->array[$id] = array (); + + foreach ($values as $key => $value) { + $this->array[$id][$key] = $value; + } + } else { + return false; + } + } + + public function updateCategory ($id, $values) { + foreach ($values as $key => $value) { + $this->array[$id][$key] = $value; + } + } + + public function deleteCategory ($id) { + if (isset ($this->array[$id])) { + unset ($this->array[$id]); + } + } + + public function searchById ($id) { + $list = HelperCategory::daoToCategory ($this->array); + + if (isset ($list[$id])) { + return $list[$id]; + } else { + return false; + } + } + + public function listCategories () { + $list = $this->array; + + if (!is_array ($list)) { + $list = array (); + } + + return HelperCategory::daoToCategory ($list); + } + + public function count () { + return count ($this->array); + } + + public function save () { + $this->writeFile ($this->array); + } +} + +class HelperCategory { + public static function daoToCategory ($listDAO) { + $list = array (); + + if (!is_array ($listDAO)) { + $listDAO = array ($listDAO); + } + + foreach ($listDAO as $key => $dao) { + $list[$key] = new Category ( + $dao['name'], + $dao['color'] + ); + } + + return $list; + } +} |
