aboutsummaryrefslogtreecommitdiff
path: root/app/models
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
parent8c562972062fbf3d750bd62893de248022850c23 (diff)
Grosse mise à jour du design, pas mal de trucs cassés au niveau du panneau de configuration
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/Category.php42
-rwxr-xr-xapp/models/Entry.php120
-rw-r--r--app/models/Feed.php56
3 files changed, 136 insertions, 82 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);
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 4790a1681..f2aebbd24 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -11,7 +11,7 @@ class Entry extends Model {
private $is_read;
private $is_favorite;
private $feed;
-
+
public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '',
$link = '', $pubdate = 0, $is_read = false, $is_favorite = false) {
$this->_guid ($guid);
@@ -24,7 +24,7 @@ class Entry extends Model {
$this->_isFavorite ($is_favorite);
$this->_feed ($feed);
}
-
+
public function id () {
if(is_null($this->id)) {
return small_hash ($this->guid . Configuration::selApplication ());
@@ -125,21 +125,21 @@ class EntryDAO extends Model_pdo {
return false;
}
}
-
+
public function updateEntry ($id, $valuesTmp) {
if (isset ($valuesTmp['content'])) {
$valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content'])));
}
-
+
$set = '';
foreach ($valuesTmp as $key => $v) {
$set .= $key . '=?, ';
}
$set = substr ($set, 0, -2);
-
+
$sql = 'UPDATE entry SET ' . $set . ' WHERE id=?';
$stm = $this->bd->prepare ($sql);
-
+
foreach ($valuesTmp as $v) {
$values[] = $v;
}
@@ -151,21 +151,21 @@ class EntryDAO extends Model_pdo {
return false;
}
}
-
+
public function updateEntries ($valuesTmp) {
if (isset ($valuesTmp['content'])) {
$valuesTmp['content'] = base64_encode (gzdeflate (serialize ($valuesTmp['content'])));
}
-
+
$set = '';
foreach ($valuesTmp as $key => $v) {
$set .= $key . '=?, ';
}
$set = substr ($set, 0, -2);
-
+
$sql = 'UPDATE entry SET ' . $set;
$stm = $this->bd->prepare ($sql);
-
+
foreach ($valuesTmp as $v) {
$values[] = $v;
}
@@ -176,7 +176,7 @@ class EntryDAO extends Model_pdo {
return false;
}
}
-
+
public function cleanOldEntries ($nb_month) {
$date = 60 * 60 * 24 * 30 * $nb_month;
$sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0';
@@ -185,52 +185,52 @@ class EntryDAO extends Model_pdo {
$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);
-
+
$values = array ($id);
-
+
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$entry = HelperEntry::daoToEntry ($res);
-
+
if (isset ($entry[0])) {
return $entry[0];
} else {
return false;
}
}
-
+
public function listEntries ($mode, $order = 'high_to_low') {
$where = '';
if ($mode == 'not_read') {
$where = ' WHERE is_read=0';
}
-
+
if ($order == 'low_to_high') {
$order = ' DESC';
} else {
$order = '';
}
-
+
$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
$stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$this->nbItems = $res[0]['count'];
-
+
$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
$fin = $this->nbItemsPerPage;
-
+
$sql = 'SELECT * FROM entry' . $where
. ' ORDER BY date' . $order
. ' LIMIT ' . $deb . ', ' . $fin;
@@ -239,77 +239,111 @@ class EntryDAO extends Model_pdo {
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function listFavorites ($mode, $order = 'high_to_low') {
$where = ' WHERE is_favorite=1';
if ($mode == 'not_read') {
$where .= ' AND is_read=0';
}
-
+
if ($order == 'low_to_high') {
$order = ' DESC';
} else {
$order = '';
}
-
+
$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
$stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$this->nbItems = $res[0]['count'];
-
+
if($this->nbItemsPerPage < 0) {
$sql = 'SELECT * FROM entry' . $where
. ' ORDER BY date' . $order;
} else {
$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
$fin = $this->nbItemsPerPage;
-
+
$sql = 'SELECT * FROM entry' . $where
. ' ORDER BY date' . $order
. ' LIMIT ' . $deb . ', ' . $fin;
}
$stm = $this->bd->prepare ($sql);
-
+
$stm->execute ();
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function listByCategory ($cat, $mode, $order = 'high_to_low') {
$where = ' WHERE category=?';
if ($mode == 'not_read') {
$where .= ' AND is_read=0';
}
-
+
if ($order == 'low_to_high') {
$order = ' DESC';
} else {
$order = '';
}
-
+
$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where;
$stm = $this->bd->prepare ($sql);
$values = array ($cat);
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$this->nbItems = $res[0]['count'];
-
+
$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
$fin = $this->nbItemsPerPage;
$sql = 'SELECT * FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where
. ' ORDER BY date' . $order
. ' LIMIT ' . $deb . ', ' . $fin;
-
+
$stm = $this->bd->prepare ($sql);
-
+
$values = array ($cat);
-
+
+ $stm->execute ($values);
+
+ return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
+ }
+
+ public function listByFeed ($feed, $mode, $order = 'high_to_low') {
+ $where = ' WHERE id_feed=?';
+ if ($mode == 'not_read') {
+ $where .= ' AND is_read=0';
+ }
+
+ if ($order == 'low_to_high') {
+ $order = ' DESC';
+ } else {
+ $order = '';
+ }
+
+ $sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
+ $stm = $this->bd->prepare ($sql);
+ $values = array ($feed);
+ $stm->execute ($values);
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+ $this->nbItems = $res[0]['count'];
+
+ $deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+ $fin = $this->nbItemsPerPage;
+ $sql = 'SELECT * FROM entry e' . $where
+ . ' ORDER BY date' . $order
+ . ' LIMIT ' . $deb . ', ' . $fin;
+
+ $stm = $this->bd->prepare ($sql);
+
+ $values = array ($feed);
+
$stm->execute ($values);
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function count () {
$sql = 'SELECT COUNT(*) AS count FROM entry';
$stm = $this->bd->prepare ($sql);
@@ -318,25 +352,25 @@ class EntryDAO extends Model_pdo {
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'];
}
-
+
public function countFavorites () {
$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_favorite=1';
$stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
-
+
return $res[0]['count'];
}
-
+
// gestion de la pagination directement via le DAO
private $nbItemsPerPage = 1;
private $currentPage = 1;
@@ -347,13 +381,13 @@ class EntryDAO extends Model_pdo {
public function _currentPage ($value) {
$this->currentPage = $value;
}
-
+
public function getPaginator ($entries) {
$paginator = new Paginator ($entries);
$paginator->_nbItems ($this->nbItems);
$paginator->_nbItemsPerPage ($this->nbItemsPerPage);
$paginator->_currentPage ($this->currentPage);
-
+
return $paginator;
}
}
@@ -361,7 +395,7 @@ class EntryDAO extends Model_pdo {
class HelperEntry {
public static function daoToEntry ($listDAO, $mode = 'all', $favorite = false) {
$list = array ();
-
+
if (!is_array ($listDAO)) {
$listDAO = array ($listDAO);
}
diff --git a/app/models/Feed.php b/app/models/Feed.php
index db051c948..046e5af92 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -9,11 +9,11 @@ class Feed extends Model {
private $website = '';
private $description = '';
private $lastUpdate = 0;
-
+
public function __construct ($url) {
$this->_url ($url);
}
-
+
public function id () {
if(is_null($this->id)) {
return small_hash ($this->url . Configuration::selApplication ());
@@ -58,7 +58,7 @@ class Feed extends Model {
if (!is_null ($value) && !preg_match ('#^https?://#', $value)) {
$value = 'http://' . $value;
}
-
+
if (!is_null ($value) && filter_var ($value, FILTER_VALIDATE_URL)) {
$this->url = $value;
} else {
@@ -89,7 +89,7 @@ class Feed extends Model {
public function _lastUpdate ($value) {
$this->lastUpdate = $value;
}
-
+
public function load () {
if (!is_null ($this->url)) {
if (CACHE_PATH === false) {
@@ -113,13 +113,13 @@ class Feed extends Model {
}
private function loadEntries ($feed) {
$entries = array ();
-
+
foreach ($feed->get_items () as $item) {
$title = $item->get_title ();
$author = $item->get_author ();
$link = $item->get_permalink ();
$date = strtotime ($item->get_date ());
-
+
// Gestion du contenu
// On cherche à récupérer les articles en entier... même si le flux ne le propose pas
$path = get_path ($this->website ());
@@ -132,7 +132,7 @@ class Feed extends Model {
} else {
$content = $item->get_content ();
}
-
+
$entry = new Entry (
$this->id (),
$item->get_id (),
@@ -142,10 +142,10 @@ class Feed extends Model {
!is_null ($link) ? $link : '',
$date ? $date : time ()
);
-
+
$entries[$entry->id ()] = $entry;
}
-
+
$this->entries = $entries;
}
}
@@ -171,14 +171,14 @@ class FeedDAO extends Model_pdo {
return false;
}
}
-
+
public function updateFeed ($id, $valuesTmp) {
$set = '';
foreach ($valuesTmp as $key => $v) {
$set .= $key . '=?, ';
}
$set = substr ($set, 0, -2);
-
+
$sql = 'UPDATE feed SET ' . $set . ' WHERE id=?';
$stm = $this->bd->prepare ($sql);
@@ -193,7 +193,7 @@ class FeedDAO extends Model_pdo {
return false;
}
}
-
+
public function updateLastUpdate ($id) {
$sql = 'UPDATE feed SET lastUpdate=? WHERE id=?';
$stm = $this->bd->prepare ($sql);
@@ -209,7 +209,7 @@ class FeedDAO extends Model_pdo {
return false;
}
}
-
+
public function deleteFeed ($id) {
$sql = 'DELETE FROM feed WHERE id=?';
$stm = $this->bd->prepare ($sql);
@@ -222,24 +222,24 @@ class FeedDAO extends Model_pdo {
return false;
}
}
-
+
public function searchById ($id) {
$sql = 'SELECT * FROM feed WHERE id=?';
$stm = $this->bd->prepare ($sql);
-
+
$values = array ($id);
-
+
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$feed = HelperFeed::daoToFeed ($res);
-
- if (isset ($feed[0])) {
- return $feed[0];
+
+ if (isset ($feed[$id])) {
+ return $feed[$id];
} else {
return false;
}
}
-
+
public function listFeeds () {
$sql = 'SELECT * FROM feed ORDER BY name';
$stm = $this->bd->prepare ($sql);
@@ -247,7 +247,7 @@ class FeedDAO extends Model_pdo {
return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function listFeedsOrderUpdate () {
$sql = 'SELECT * FROM feed ORDER BY lastUpdate';
$stm = $this->bd->prepare ($sql);
@@ -255,18 +255,18 @@ class FeedDAO extends Model_pdo {
return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function listByCategory ($cat) {
$sql = 'SELECT * FROM feed WHERE category=? ORDER BY name';
$stm = $this->bd->prepare ($sql);
-
+
$values = array ($cat);
-
+
$stm->execute ($values);
return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
}
-
+
public function count () {
$sql = 'SELECT COUNT(*) AS count FROM feed';
$stm = $this->bd->prepare ($sql);
@@ -275,7 +275,7 @@ class FeedDAO extends Model_pdo {
return $res[0]['count'];
}
-
+
public function countEntries ($id) {
$sql = 'SELECT COUNT(*) AS count FROM entry WHERE id_feed=?';
$stm = $this->bd->prepare ($sql);
@@ -296,6 +296,10 @@ class HelperFeed {
}
foreach ($listDAO as $key => $dao) {
+ if (isset ($dao['id'])) {
+ $key = $dao['id'];
+ }
+
$list[$key] = new Feed ($dao['url']);
$list[$key]->_category ($dao['category']);
$list[$key]->_name ($dao['name']);