summaryrefslogtreecommitdiff
path: root/app/models/Category.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-03-16 22:52:07 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-03-16 22:52:07 +0100
commit59b2ae54caf7a23b459193ba73b17d7c9c3317af (patch)
treecefa1849d7366ed7234c4350933838fac1272730 /app/models/Category.php
parent8c2b3bfc30caa22258b9569b8a228db0adc90618 (diff)
Fix bug #24 : les flux ont désormais une catégorie par défaut
Diffstat (limited to 'app/models/Category.php')
-rwxr-xr-xapp/models/Category.php36
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);