summaryrefslogtreecommitdiff
path: root/app/controllers/indexController.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-05-05 13:20:13 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-05-05 13:20:13 +0200
commit2e7afb7d340eb367d65ac042ae24a10fa021c073 (patch)
tree27208483aac8262cdc42ee492a0f222991a0b4fa /app/controllers/indexController.php
parentae7c9787cd8afd4313d356c6525e40d4ce79f99b (diff)
parentd4e6176a1ae210c011b14839023f91b4014f2881 (diff)
Merge branch 'releases'0.3.0
Diffstat (limited to 'app/controllers/indexController.php')
-rwxr-xr-xapp/controllers/indexController.php279
1 files changed, 110 insertions, 169 deletions
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php
index 8fa911631..f4f0b98b3 100755
--- a/app/controllers/indexController.php
+++ b/app/controllers/indexController.php
@@ -6,117 +6,136 @@ class indexController extends ActionController {
private $mode = 'all';
public function indexAction () {
- View::appendScript (Url::display ('/scripts/shortcut.js'));
- View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
- View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'actualize')));
+ if (Request::param ('output') == 'rss') {
+ $this->view->_useLayout (false);
+ } else {
+ View::appendScript (Url::display ('/scripts/shortcut.js'));
+ View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
+ View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'actualize')));
+ }
$entryDAO = new EntryDAO ();
$feedDAO = new FeedDAO ();
$catDAO = new CategoryDAO ();
- $error = false;
-
- // pour optimiser
- $page = Request::param ('page', 1);
- $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)
- $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ère les flux par catégorie, favoris ou tous
- 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 ($this->get['type'] == 'public') {
- $entries = $entryDAO->listPublic ($this->mode, $search, $order);
- View::prependTitle ('Public - ');
- } elseif ($this->get != false) {
- if ($this->get['type'] == 'c') {
- $cat = $catDAO->searchById ($this->get['filter']);
-
- if ($cat) {
- $entries = $entryDAO->listByCategory ($this->get['filter'], $this->mode, $search, $order);
- View::prependTitle ($cat->name () . ' - ');
- } else {
- $error = true;
- }
- } elseif ($this->get['type'] == 'f') {
- $feed = $feedDAO->searchById ($this->get['filter']);
-
- if ($feed) {
- $entries = $entryDAO->listByFeed ($this->get['filter'], $this->mode, $search, $order);
- $this->view->get_c = $feed->category ();
- View::prependTitle ($feed->name () . ' - ');
- } else {
- $error = true;
+ $this->view->cat_aside = $catDAO->listCategories ();
+ $this->view->nb_favorites = $entryDAO->countFavorites ();
+ $this->view->nb_total = $entryDAO->count ();
+
+ $this->view->get_c = '';
+ $this->view->get_f = '';
+
+ $type = $this->getType ();
+ $error = $this->checkAndProcessType ($type);
+ if (!$error) {
+ // On récupère les différents éléments de filtrage
+ $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ());
+ $filter = Request::param ('search', '');
+ $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ());
+ $nb = Request::param ('nb', $this->view->conf->postsPerPage ());
+ $first = Request::param ('next', '');
+
+ try {
+ // EntriesGetter permet de déporter la complexité du filtrage
+ $getter = new EntriesGetter ($type, $state, $filter, $order, $nb, $first);
+ $getter->execute ();
+ $entries = $getter->getPaginator ();
+
+ // Si on a récupéré aucun article "non lus"
+ // on essaye de récupérer tous les articles
+ if ($state == 'not_read' && $entries->isEmpty ()) {
+ $this->view->state = 'all';
+ $getter->_state ('all');
+ $getter->execute ();
+ $entries = $getter->getPaginator ();
}
- } else {
- $error = true;
+
+ $this->view->entryPaginator = $entries;
+ } catch(EntriesGetterException $e) {
+ Log::record ($e->getMessage (), Log::NOTICE);
+ Error::error (
+ 404,
+ array ('error' => array (Translate::t ('page_not_found')))
+ );
}
} else {
- $error = true;
- }
-
- if ($error) {
Error::error (
404,
- array ('error' => array ('La page que vous cherchez n\'existe pas'))
+ array ('error' => array (Translate::t ('page_not_found')))
);
- } 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 ();
-
- if (Request::param ('output', '') == 'rss') {
- $this->view->_useLayout (false);
- }
}
}
- public function aboutAction () {
- View::prependTitle ('À propos - ');
- }
-
- public function changeModeAction () {
- $mode = Request::param ('mode');
+ /*
+ * Détermine le type d'article à récupérer :
+ * "tous", "favoris", "public", "catégorie" ou "flux"
+ */
+ private function getType () {
+ $get = Request::param ('get', 'all');
+ $typeGet = $get[0];
+ $id = substr ($get, 2);
- if ($mode == 'not_read') {
- Session::_param ('mode', 'not_read');
- } else {
- Session::_param ('mode', 'all');
+ $type = null;
+ if ($get == 'all' || $get == 'favoris' || $get == 'public') {
+ $type = array (
+ 'type' => $get,
+ 'id' => $get
+ );
+ } elseif ($typeGet == 'f' || $typeGet == 'c') {
+ $type = array (
+ 'type' => $typeGet,
+ 'id' => $id
+ );
}
- Request::forward (array (), true);
+ return $type;
}
- public function changeOrderAction () {
- $order = Request::param ('order');
-
- if ($order == 'low_to_high') {
- Session::_param ('order', 'low_to_high');
+ /*
+ * Vérifie que la catégorie / flux sélectionné existe
+ * + Initialise correctement les variables de vue get_c et get_f
+ * + Initialise le titre
+ */
+ private function checkAndProcessType ($type) {
+ if ($type['type'] == 'all') {
+ View::prependTitle (Translate::t ('your_rss_feeds') . ' - ');
+ $this->view->get_c = $type['type'];
+ return false;
+ } elseif ($type['type'] == 'favoris') {
+ View::prependTitle (Translate::t ('your_favorites') . ' - ');
+ $this->view->get_c = $type['type'];
+ return false;
+ } elseif ($type['type'] == 'public') {
+ View::prependTitle (Translate::t ('public') . ' - ');
+ $this->view->get_c = $type['type'];
+ return false;
+ } elseif ($type['type'] == 'c') {
+ $catDAO = new CategoryDAO ();
+ $cat = $catDAO->searchById ($type['id']);
+ if ($cat) {
+ View::prependTitle ($cat->name () . ' - ');
+ $this->view->get_c = $type['id'];
+ return false;
+ } else {
+ return true;
+ }
+ } elseif ($type['type'] == 'f') {
+ $feedDAO = new FeedDAO ();
+ $feed = $feedDAO->searchById ($type['id']);
+ if ($feed) {
+ View::prependTitle ($feed->name () . ' - ');
+ $this->view->get_f = $type['id'];
+ $this->view->get_c = $feed->category ();
+ return false;
+ } else {
+ return true;
+ }
} else {
- Session::_param ('order', 'high_to_low');
+ return true;
}
+ }
- Request::forward (array (), true);
+ public function aboutAction () {
+ View::prependTitle (Translate::t ('about') . ' - ');
}
public function loginAction () {
@@ -143,7 +162,7 @@ class indexController extends ActionController {
} else {
$res = array ();
$res['status'] = 'failure';
- $res['reason'] = 'L\'identifiant est invalide';
+ $res['reason'] = Translate::t ('invalid_login');
}
$this->view->res = json_encode ($res);
@@ -153,82 +172,4 @@ 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 == 'public') {
- $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;
- }
}