From d2f0451eb3764402cbdc09730fe172b74a96a1b0 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 17 Mar 2013 12:54:41 +0100 Subject: Fix bug #30 : lorsque articles non lus dans une catégorie, les autres catégories affichent désormais tous leurs articles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/indexController.php | 156 ++++++++++++++++++++++++------------ app/models/Entry.php | 27 +++++++ public/scripts/smoothscroll.js | 3 - 3 files changed, 133 insertions(+), 53 deletions(-) delete mode 100644 public/scripts/smoothscroll.js diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 04c74028c..c83f7f1d2 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -1,8 +1,11 @@ 'javascript', 'a' => 'main'))); @@ -17,53 +20,39 @@ class indexController extends ActionController { $entryDAO->_nbItemsPerPage ($this->view->conf->postsPerPage ()); $entryDAO->_currentPage ($page); + // récupération de la catégorie/flux à filtrer + $this->initFilter (); + // Compte le nombre d'articles non lus en prenant en compte le filtre + $this->countNotRead (); // mode de vue (tout ou seulement non lus) - $default_view = $this->view->conf->defaultView (); - $mode = Session::param ('mode'); - if ($mode == false) { - if ($default_view == 'not_read' && $this->view->nb_not_read < 1) { - $mode = 'all'; - } else { - $mode = $default_view; - } - } - + $this->initCurrentMode (); // ordre de listage des flux $order = Session::param ('order', $this->view->conf->sortOrder ()); - // recherche sur les titres (pour le moment) $search = Request::param ('search'); - // récupération de la catégorie/flux à filtrer - $get = Request::param ('get'); - $this->view->get_c = false; - $this->view->get_f = false; - // Récupère les flux par catégorie, favoris ou tous - if ($get == 'favoris') { - $entries = $entryDAO->listFavorites ($mode, $search, $order); - $this->view->get_c = $get; + if ($this->get['type'] == 'all') { + $entries = $entryDAO->listEntries ($this->mode, $search, $order); + View::prependTitle ('Vos flux RSS - '); + } elseif ($this->get['type'] == 'favoris') { + $entries = $entryDAO->listFavorites ($this->mode, $search, $order); View::prependTitle ('Vos favoris - '); - } elseif ($get != false) { - $typeGet = $get[0]; - $get = substr ($get, 2); - - if ($typeGet == 'c') { - $entries = $entryDAO->listByCategory ($get, $mode, $search, $order); - $cat = $catDAO->searchById ($get); + } elseif ($this->get != false) { + if ($this->get['type'] == 'c') { + $cat = $catDAO->searchById ($this->get['filter']); if ($cat) { - $this->view->get_c = $get; + $entries = $entryDAO->listByCategory ($this->get['filter'], $this->mode, $search, $order); View::prependTitle ($cat->name () . ' - '); } else { $error = true; } - } elseif ($typeGet == 'f') { - $entries = $entryDAO->listByFeed ($get, $mode, $search, $order); - $feed = $feedDAO->searchById ($get); + } elseif ($this->get['type'] == 'f') { + $feed = $feedDAO->searchById ($this->get['filter']); if ($feed) { - $this->view->get_f = $get; + $entries = $entryDAO->listByFeed ($this->get['filter'], $this->mode, $search, $order); $this->view->get_c = $feed->category (); View::prependTitle ($feed->name () . ' - '); } else { @@ -73,31 +62,27 @@ class indexController extends ActionController { $error = true; } } else { - View::prependTitle ('Vos flux RSS - '); - } - - $this->view->mode = $mode; - $this->view->order = $order; - - // Cas où on ne choisie ni catégorie ni les favoris - // ou si la catégorie ne correspond à aucune - if (!isset ($entries)) { - $entries = $entryDAO->listEntries ($mode, $search, $order); + $error = true; } - try { - $this->view->entryPaginator = $entryDAO->getPaginator ($entries); - } catch (CurrentPagePaginationException $e) { } - - $this->view->cat_aside = $catDAO->listCategories (); - $this->view->nb_favorites = $entryDAO->countFavorites (); - $this->view->nb_total = $entryDAO->count (); - if ($error) { Error::error ( 404, array ('error' => array ('La page que vous cherchez n\'existe pas')) ); + } else { + $this->view->mode = $this->mode; + $this->view->order = $order; + + try { + $this->view->entryPaginator = $entryDAO->getPaginator ($entries); + } catch (CurrentPagePaginationException $e) { + + } + + $this->view->cat_aside = $catDAO->listCategories (); + $this->view->nb_favorites = $entryDAO->countFavorites (); + $this->view->nb_total = $entryDAO->count (); } } @@ -162,4 +147,75 @@ class indexController extends ActionController { $this->view->_useLayout (false); Session::_param ('mail'); } + + private function initFilter () { + $get = Request::param ('get'); + $this->view->get_c = false; + $this->view->get_f = false; + + $typeGet = $get[0]; + $filter = substr ($get, 2); + + if ($get == 'favoris') { + $this->view->get_c = $get; + + $this->get = array ( + 'type' => $get, + 'filter' => $get + ); + } elseif ($get == false) { + $this->get = array ( + 'type' => 'all', + 'filter' => 'all' + ); + } else { + if ($typeGet == 'f') { + $this->view->get_f = $filter; + + $this->get = array ( + 'type' => $typeGet, + 'filter' => $filter + ); + } elseif ($typeGet == 'c') { + $this->view->get_c = $filter; + + $this->get = array ( + 'type' => $typeGet, + 'filter' => $filter + ); + } else { + $this->get = false; + } + } + } + + private function countNotRead () { + $entryDAO = new EntryDAO (); + + if ($this->get != false) { + if ($this->get['type'] == 'all') { + $this->nb_not_read = $this->view->nb_not_read; + } elseif ($this->get['type'] == 'favoris') { + $this->nb_not_read = $entryDAO->countNotReadFavorites (); + } elseif ($this->get['type'] == 'c') { + $this->nb_not_read = $entryDAO->countNotReadByCat ($this->get['filter']); + } elseif ($this->get['type'] == 'f') { + $this->nb_not_read = $entryDAO->countNotReadByFeed ($this->get['filter']); + } + } + } + + private function initCurrentMode () { + $default_view = $this->view->conf->defaultView (); + $mode = Session::param ('mode'); + if ($mode == false) { + if ($default_view == 'not_read' && $this->nb_not_read < 1) { + $mode = 'all'; + } else { + $mode = $default_view; + } + } + + $this->mode = $mode; + } } diff --git a/app/models/Entry.php b/app/models/Entry.php index 245fea2f6..71ace9b5e 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -443,6 +443,33 @@ class EntryDAO extends Model_pdo { return $res[0]['count']; } + public function countNotReadByFeed ($id) { + $sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read = 0 AND id_feed = ?'; + $stm = $this->bd->prepare ($sql); + $stm->execute (array ($id)); + $res = $stm->fetchAll (PDO::FETCH_ASSOC); + + return $res[0]['count']; + } + + public function countNotReadByCat ($id) { + $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE is_read=0 AND category = ?'; + $stm = $this->bd->prepare ($sql); + $stm->execute (array ($id)); + $res = $stm->fetchAll (PDO::FETCH_ASSOC); + + return $res[0]['count']; + } + + public function countNotReadFavorites () { + $sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0 AND is_favorite=1'; + $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); diff --git a/public/scripts/smoothscroll.js b/public/scripts/smoothscroll.js deleted file mode 100644 index 0f4db3e5e..000000000 --- a/public/scripts/smoothscroll.js +++ /dev/null @@ -1,3 +0,0 @@ -/*! Smooth Scroll - v1.4.6 - 2012-08-23 -* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */ -(function(a){function f(a){return a.replace(/(:|\.)/g,"\\$1")}var b="1.4.6",c={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficent:2},d=function(b){var c=[],d=!1,e=b.dir&&b.dir=="left"?"scrollLeft":"scrollTop";return this.each(function(){if(this==document||this==window)return;var b=a(this);b[e]()>0?c.push(this):(b[e](1),d=b[e]()>0,d&&c.push(this),b[e](0))}),c.length||this.each(function(a){this.nodeName==="BODY"&&(c=[this])}),b.el==="first"&&c.length>1&&(c=[c[0]]),c},e="ontouchend"in document;a.fn.extend({scrollable:function(a){var b=d.call(this,{dir:a});return this.pushStack(b)},firstScrollable:function(a){var b=d.call(this,{el:"first",dir:a});return this.pushStack(b)},smoothScroll:function(b){b=b||{};var c=a.extend({},a.fn.smoothScroll.defaults,b),d=a.smoothScroll.filterPath(location.pathname);return this.unbind("click.smoothscroll").bind("click.smoothscroll",function(b){var e=this,g=a(this),h=c.exclude,i=c.excludeWithin,j=0,k=0,l=!0,m={},n=location.hostname===e.hostname||!e.hostname,o=c.scrollTarget||(a.smoothScroll.filterPath(e.pathname)||d)===d,p=f(e.hash);if(!c.scrollTarget&&(!n||!o||!p))l=!1;else{while(l&&j