From c62ec2a14428b528e20896d4e62fa08891e1399c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 12 Mar 2013 23:24:52 +0100 Subject: Grosse mise à jour du design, pas mal de trucs cassés au niveau du panneau de configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/Category.php | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'app/models/Category.php') diff --git a/app/models/Category.php b/app/models/Category.php index ceecea453..ef214137e 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -4,12 +4,13 @@ class Category extends Model { private $id = false; private $name; private $color; - + private $feeds = null; + public function __construct ($name = '', $color = '#0062BE') { $this->_name ($name); $this->_color ($color); } - + public function id () { if (!$this->id) { return small_hash ($this->name . Configuration::selApplication ()); @@ -31,7 +32,15 @@ class Category extends Model { $catDAO = new CategoryDAO (); return $catDAO->countNotRead ($this->id ()); } - + public function feeds () { + if (is_null ($this->feeds)) { + $feedDAO = new FeedDAO (); + return $feedDAO->listByCategory ($this->id ()); + } else { + return $this->feeds; + } + } + public function _id ($value) { $this->id = $value; } @@ -45,6 +54,13 @@ class Category extends Model { $this->color = '#0062BE'; } } + public function _feeds ($values) { + if (!is_array ($values)) { + $values = array ($values); + } + + $this->feeds = $values; + } } class CategoryDAO extends Model_pdo { @@ -64,7 +80,7 @@ class CategoryDAO extends Model_pdo { return false; } } - + public function updateCategory ($id, $valuesTmp) { $sql = 'UPDATE category SET name=?, color=? WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -81,7 +97,7 @@ class CategoryDAO extends Model_pdo { return false; } } - + public function deleteCategory ($id) { $sql = 'DELETE FROM category WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -94,24 +110,24 @@ class CategoryDAO extends Model_pdo { return false; } } - + public function searchById ($id) { $sql = 'SELECT * FROM category WHERE id=?'; $stm = $this->bd->prepare ($sql); - + $values = array ($id); - + $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'; $stm = $this->bd->prepare ($sql); @@ -119,7 +135,7 @@ class CategoryDAO extends Model_pdo { return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC)); } - + public function count () { $sql = 'SELECT COUNT(*) AS count FROM category'; $stm = $this->bd->prepare ($sql); @@ -128,7 +144,7 @@ class CategoryDAO extends Model_pdo { return $res[0]['count']; } - + public function countFeed ($id) { $sql = 'SELECT COUNT(*) AS count FROM feed WHERE category=?'; $stm = $this->bd->prepare ($sql); @@ -138,7 +154,7 @@ class CategoryDAO extends Model_pdo { return $res[0]['count']; } - + public function countNotRead ($id) { $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE category=? AND e.is_read=0'; $stm = $this->bd->prepare ($sql); -- cgit v1.2.3