aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-25 00:12:18 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-25 00:12:18 +0200
commit6723babdd65d946cdc7e315d7f11fb3ca0e455d3 (patch)
treee45359332c04fc5c935fbedecd1ade50b6430463 /app/models
parent4924f4c6d6d03d39471de363b8d368c8edad8f3d (diff)
ajouts graphique + ajout suppression vieux articles
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/Category.php22
-rwxr-xr-xapp/models/Entry.php31
-rw-r--r--app/models/Feed.php6
-rwxr-xr-xapp/models/RSSConfiguration.php16
4 files changed, 65 insertions, 10 deletions
diff --git a/app/models/Category.php b/app/models/Category.php
index e0b8f564d..1713f615c 100755
--- a/app/models/Category.php
+++ b/app/models/Category.php
@@ -23,6 +23,10 @@ class Category extends Model {
public function color () {
return $this->color;
}
+ public function nbFlux () {
+ $catDAO = new CategoryDAO ();
+ return $catDAO->countFlux ($this->id ());
+ }
public function _id ($value) {
$this->id = $value;
@@ -76,7 +80,7 @@ class CategoryDAO extends Model_pdo {
public function deleteCategory ($id) {
$sql = 'DELETE FROM category WHERE id=?';
- $stm = $this->bd->prepare ($sql);
+ $stm = $this->bd->prepare ($sql);
$values = array ($id);
@@ -106,20 +110,30 @@ class CategoryDAO extends Model_pdo {
public function listCategories () {
$sql = 'SELECT * FROM category';
- $stm = $this->bd->prepare ($sql);
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC));
}
public function count () {
- $sql = 'SELECT COUNT (*) AS count FROM category';
- $stm = $this->bd->prepare ($sql);
+ $sql = 'SELECT COUNT(*) AS count FROM category';
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
return $res[0]['count'];
}
+
+ public function countFlux ($id) {
+ $sql = 'SELECT COUNT(*) AS count FROM feed WHERE category=?';
+ $stm = $this->bd->prepare ($sql);
+ $values = array ($id);
+ $stm->execute ($values);
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+ return $res[0]['count'];
+ }
}
class HelperCategory {
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 437aa8050..6fcc821f4 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -161,6 +161,22 @@ class EntryDAO extends Model_pdo {
}
}
+ public function cleanOldEntries ($nb_month) {
+ $date = 60 * 60 * 24 * 30 * $nb_month;
+ $sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0';
+ $stm = $this->bd->prepare ($sql);
+
+ $values = array (
+ time () - $date
+ );
+
+ if ($stm && $stm->execute ($values)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public function searchById ($id) {
$sql = 'SELECT * FROM entry WHERE id=?';
$stm = $this->bd->prepare ($sql);
@@ -191,7 +207,7 @@ class EntryDAO extends Model_pdo {
}
$sql = 'SELECT * FROM entry' . $where . ' ORDER BY date' . $order;
- $stm = $this->bd->prepare ($sql);
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
@@ -241,13 +257,22 @@ class EntryDAO extends Model_pdo {
}
public function count () {
- $sql = 'SELECT COUNT (*) AS count FROM entry';
- $stm = $this->bd->prepare ($sql);
+ $sql = 'SELECT COUNT(*) AS count FROM entry';
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
return $res[0]['count'];
}
+
+ public function countNotRead () {
+ $sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0';
+ $stm = $this->bd->prepare ($sql);
+ $stm->execute ();
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+ return $res[0]['count'];
+ }
}
class HelperEntry {
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 8a3f826bd..cf1b3e06a 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -161,7 +161,7 @@ class FeedDAO extends Model_pdo {
public function listFeeds () {
$sql = 'SELECT * FROM feed';
- $stm = $this->bd->prepare ($sql);
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
@@ -179,8 +179,8 @@ class FeedDAO extends Model_pdo {
}
public function count () {
- $sql = 'SELECT COUNT (*) AS count FROM feed';
- $stm = $this->bd->prepare ($sql);
+ $sql = 'SELECT COUNT(*) AS count FROM feed';
+ $stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php
index da5028da3..8ee1717b3 100755
--- a/app/models/RSSConfiguration.php
+++ b/app/models/RSSConfiguration.php
@@ -5,6 +5,7 @@ class RSSConfiguration extends Model {
private $default_view;
private $display_posts;
private $sort_order;
+ private $old_entries;
public function __construct () {
$confDAO = new RSSConfigurationDAO ();
@@ -12,6 +13,7 @@ class RSSConfiguration extends Model {
$this->_defaultView ($confDAO->default_view);
$this->_displayPosts ($confDAO->display_posts);
$this->_sortOrder ($confDAO->sort_order);
+ $this->_oldEntries ($confDAO->old_entries);
}
public function postsPerPage () {
@@ -26,6 +28,9 @@ class RSSConfiguration extends Model {
public function sortOrder () {
return $this->sort_order;
}
+ public function oldEntries () {
+ return $this->old_entries;
+ }
public function _postsPerPage ($value) {
if (is_int ($value)) {
@@ -55,6 +60,13 @@ class RSSConfiguration extends Model {
$this->sort_order = 'low_to_high';
}
}
+ public function _oldEntries ($value) {
+ if (is_int (intval ($value))) {
+ $this->old_entries = $value;
+ } else {
+ $this->old_entries = 3;
+ }
+ }
}
class RSSConfigurationDAO extends Model_array {
@@ -62,6 +74,7 @@ class RSSConfigurationDAO extends Model_array {
public $default_view = 'all';
public $display_posts = 'no';
public $sort_order = 'low_to_high';
+ public $old_entries = 3;
public function __construct () {
parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
@@ -78,6 +91,9 @@ class RSSConfigurationDAO extends Model_array {
if (isset ($this->array['sort_order'])) {
$this->sort_order = $this->array['sort_order'];
}
+ if (isset ($this->array['old_entries'])) {
+ $this->old_entries = $this->array['old_entries'];
+ }
}
public function save ($values) {