diff options
| author | 2013-03-16 22:52:07 +0100 | |
|---|---|---|
| committer | 2013-03-16 22:52:07 +0100 | |
| commit | 59b2ae54caf7a23b459193ba73b17d7c9c3317af (patch) | |
| tree | cefa1849d7366ed7234c4350933838fac1272730 /app/models/Category.php | |
| parent | 8c2b3bfc30caa22258b9569b8a228db0adc90618 (diff) | |
Fix bug #24 : les flux ont désormais une catégorie par défaut
Diffstat (limited to 'app/models/Category.php')
| -rwxr-xr-x | app/models/Category.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/Category.php b/app/models/Category.php index ef214137e..a7f900880 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -127,6 +127,22 @@ class CategoryDAO extends Model_pdo { return false; } } + public function searchByName ($name) { + $sql = 'SELECT * FROM category WHERE name=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ($name); + + $stm->execute ($values); + $res = $stm->fetchAll (PDO::FETCH_ASSOC); + $cat = HelperCategory::daoToCategory ($res); + + if (isset ($cat[0])) { + return $cat[0]; + } else { + return false; + } + } public function listCategories () { $sql = 'SELECT * FROM category ORDER BY name'; @@ -136,6 +152,26 @@ class CategoryDAO extends Model_pdo { return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC)); } + public function getDefault () { + $def_cat = $this->searchByName ('Sans catégorie'); + + if (!$def_cat) { + $cat = new Category ('Sans catégorie'); + + $values = array ( + 'id' => $cat->id (), + 'name' => $cat->name (), + 'color' => $cat->color () + ); + + $this->addCategory ($values); + + $def_cat = $cat; + } + + return $def_cat; + } + public function count () { $sql = 'SELECT COUNT(*) AS count FROM category'; $stm = $this->bd->prepare ($sql); |
