aboutsummaryrefslogtreecommitdiff
path: root/app/models/Category.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-03-12 23:24:52 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-03-12 23:24:52 +0100
commitc62ec2a14428b528e20896d4e62fa08891e1399c (patch)
treecdf6cbbd2d1b9182d385db36ec0c86b08bcf442e /app/models/Category.php
parent8c562972062fbf3d750bd62893de248022850c23 (diff)
Grosse mise à jour du design, pas mal de trucs cassés au niveau du panneau de configuration
Diffstat (limited to 'app/models/Category.php')
-rwxr-xr-xapp/models/Category.php42
1 files changed, 29 insertions, 13 deletions
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);