aboutsummaryrefslogtreecommitdiff
path: root/app/models/Entry.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/Entry.php')
-rwxr-xr-xapp/models/Entry.php31
1 files changed, 28 insertions, 3 deletions
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 {