aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/indexController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/indexController.php')
-rwxr-xr-xapp/controllers/indexController.php156
1 files changed, 106 insertions, 50 deletions
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 @@
<?php
class indexController extends ActionController {
+ private $get = false;
+ private $nb_not_read = 0;
+ private $mode = 'all';
+
public function indexAction () {
- View::appendScript (Url::display ('/scripts/smoothscroll.js'));
View::appendScript (Url::display ('/scripts/shortcut.js'));
View::appendScript (Url::display (array ('c' => '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;
+ }
}