summaryrefslogtreecommitdiff
path: root/app/controllers/indexController.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-30 17:21:26 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-30 17:21:26 +0100
commit37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 (patch)
tree0edf7fc2c7505c8b70fd0722fb7abfbf058fd814 /app/controllers/indexController.php
parente98b7ab13ec414d1c5c3c3d1d6a7c9995ebf4fea (diff)
Recherche côté SQL avec LIKE
Premier essai de recherche côté base de données (à améliorer) https://github.com/marienfressinaud/FreshRSS/issues/204 Pour l'instant fait avec du LIKE et pas d'indexation texte complet. * Suppression de EntriesGetter car le code est devenu plus simple grâce au filtrage côté SQL * Uniformisation de get_c à une lettre ('all' devient 'a','favoris' devient 's' - pour "starred") pour simplifier le code * low_to_high par DESC, high_to_low par ASC * Réduction du nombre de créations de *DAO dans indexController * Refactorisation de checkAndProcessType() Pas encore trop testé...
Diffstat (limited to 'app/controllers/indexController.php')
-rwxr-xr-xapp/controllers/indexController.php254
1 files changed, 119 insertions, 135 deletions
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php
index 8e6abd682..cf0e5024a 100755
--- a/app/controllers/indexController.php
+++ b/app/controllers/indexController.php
@@ -3,19 +3,29 @@
class indexController extends ActionController {
private $get = false;
private $nb_not_read_cat = 0;
+ private $entryDAO;
+ private $feedDAO;
+ private $catDAO;
+
+ function __construct($router) {
+ parent::__construct($router);
+ $this->entryDAO = new EntryDAO ();
+ $this->feedDAO = new FeedDAO ();
+ $this->catDAO = new CategoryDAO ();
+ }
public function indexAction () {
$output = Request::param ('output');
$token = $this->view->conf->token();
$token_param = Request::param ('token', '');
- $token_is_ok = ($token != '' && $token == $token_param);
+ $token_is_ok = ($token != '' && $token === $token_param);
// check if user is log in
if(login_is_conf ($this->view->conf) &&
!is_logged() &&
- $this->view->conf->anonAccess() == 'no' &&
- !($output == 'rss' && $token_is_ok)) {
+ $this->view->conf->anonAccess() === 'no' &&
+ !($output === 'rss' && $token_is_ok)) {
return;
}
@@ -26,7 +36,7 @@ class indexController extends ActionController {
$params['search'] = urlencode ($params['search']);
}
if (login_is_conf($this->view->conf) &&
- $this->view->conf->anonAccess() == 'no' &&
+ $this->view->conf->anonAccess() === 'no' &&
$token != '') {
$params['token'] = $token;
}
@@ -38,32 +48,25 @@ class indexController extends ActionController {
$this->view->rss_title = View::title();
- if ($output == 'rss') {
+ if ($output === 'rss') {
// no layout for RSS output
$this->view->_useLayout (false);
header('Content-Type: application/rss+xml; charset=utf-8');
} else {
View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
- if ($output == 'global') {
+ if ($output === 'global') {
View::appendScript (Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js')));
}
}
- $entryDAO = new EntryDAO ();
- $feedDAO = new FeedDAO ();
- $catDAO = new CategoryDAO ();
-
- $this->view->cat_aside = $catDAO->listCategories ();
- $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites ();
+ $this->view->cat_aside = $this->catDAO->listCategories ();
+ $this->view->nb_favorites = $this->entryDAO->countUnreadReadFavorites ();
$this->view->currentName = '';
$this->view->get_c = '';
$this->view->get_f = '';
- $type = $this->getType ();
- $error = $this->checkAndProcessType ($type);
-
// mise à jour des titres
$this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1);
if ($this->view->nb_not_read > 0) {
@@ -77,63 +80,73 @@ class indexController extends ActionController {
($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '')
);
- 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', '');
-
- if ($state === 'not_read') { //Any unread article in this category at all?
- switch ($type['type']) {
- case 'all':
- $hasUnread = $this->view->nb_not_read > 0;
- break;
- case 'favoris':
- $hasUnread = $this->view->nb_favorites['unread'] > 0;
- break;
- case 'c':
- $hasUnread = (!isset($this->view->cat_aside[$type['id']])) || ($this->view->cat_aside[$type['id']]->nbNotRead() > 0);
- break;
- case 'f':
- $myFeed = HelperCategory::findFeed($this->view->cat_aside, $type['id']);
- $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0);
- break;
- default:
- $hasUnread = true;
- break;
- }
- if (!$hasUnread) {
- $this->view->state = $state = 'all';
- }
+ $get = Request::param ('get', 'a');
+ $getType = $get[0];
+ $getId = substr ($get, 2);
+ if (!$this->checkAndProcessType ($getType, $getId)) {
+ Minz_Log::record ('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG);
+ Error::error (
+ 404,
+ array ('error' => array (Translate::t ('page_not_found')))
+ );
+ return;
+ }
+
+ // 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', '');
+ if (!empty($filter)) {
+ $state = 'all'; //Search always in read and unread articles
+ }
+ $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ());
+ $nb = Request::param ('nb', $this->view->conf->postsPerPage ());
+ $first = Request::param ('next', '');
+
+ if ($state === 'not_read') { //Any unread article in this category at all?
+ switch ($getType) {
+ case 'a':
+ $hasUnread = $this->view->nb_not_read > 0;
+ break;
+ case 's':
+ $hasUnread = $this->view->nb_favorites['unread'] > 0;
+ break;
+ case 'c':
+ $hasUnread = (!isset($this->view->cat_aside[$getId])) || ($this->view->cat_aside[$getId]->nbNotRead() > 0);
+ break;
+ case 'f':
+ $myFeed = HelperCategory::findFeed($this->view->cat_aside, $getId);
+ $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0);
+ break;
+ default:
+ $hasUnread = true;
+ break;
}
+ if (!$hasUnread) {
+ $this->view->state = $state = 'all';
+ }
+ }
- 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 ()) { //TODO: Remove in v0.8
- Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
- $this->view->state = 'all';
- $getter->_state ('all');
- $getter->execute ();
- $entries = $getter->getPaginator ();
- }
+ try {
+ $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter);
+
+ // Si on a récupéré aucun article "non lus"
+ // on essaye de récupérer tous les articles
+ if ($state === 'not_read' && empty($entries)) { //TODO: Remove in v0.8
+ Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
+ $this->view->state = 'all';
+ $entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter);
+ }
- $this->view->entryPaginator = $entries;
- } catch (EntriesGetterException $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);
- Error::error (
- 404,
- array ('error' => array (Translate::t ('page_not_found')))
- );
+ if (count($entries) <= $nb) {
+ $next = '';
+ } else { //We have more elements for pagination
+ $lastEntry = array_pop($entries);
+ $next = $lastEntry->id();
}
- } else {
+
+ $this->view->entryPaginator = new RSSPaginator ($entries, $next);
+ } catch (EntriesGetterException $e) {
+ Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);
Error::error (
404,
array ('error' => array (Translate::t ('page_not_found')))
@@ -142,78 +155,49 @@ class indexController extends ActionController {
}
/*
- * 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);
-
- $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
- );
- }
-
- return $type;
- }
- /*
* Vérifie que la catégorie / flux sélectionné existe
* + Initialise correctement les variables de vue get_c et get_f
* + Met à jour la variable $this->nb_not_read_cat
*/
- private function checkAndProcessType ($type) {
- if ($type['type'] == 'all') {
- $this->view->currentName = Translate::t ('your_rss_feeds');
- $this->view->get_c = $type['type'];
- return false;
- } elseif ($type['type'] == 'favoris') {
- $this->view->currentName = Translate::t ('your_favorites');
- $this->view->get_c = $type['type'];
- return false;
- } elseif ($type['type'] == 'public') {
- $this->view->currentName = Translate::t ('public');
- $this->view->get_c = $type['type'];
- return false;
- } elseif ($type['type'] == 'c') {
- $cat = isset($this->view->cat_aside[$type['id']]) ? $this->view->cat_aside[$type['id']] : null;
- if ($cat === null) {
- $catDAO = new CategoryDAO ();
- $cat = $catDAO->searchById ($type['id']);
- }
- if ($cat) {
- $this->view->currentName = $cat->name ();
- $this->nb_not_read_cat = $cat->nbNotRead ();
- $this->view->get_c = $type['id'];
- return false;
- } else {
+ private function checkAndProcessType ($getType, $getId) {
+ switch ($getType) {
+ case 'a':
+ $this->view->currentName = Translate::t ('your_rss_feeds');
+ $this->view->get_c = $getType;
return true;
- }
- } elseif ($type['type'] == 'f') {
- $feed = HelperCategory::findFeed($this->view->cat_aside, $type['id']);
- if (empty($feed)) {
- $feedDAO = new FeedDAO ();
- $feed = $feedDAO->searchById ($type['id']);
- }
- if ($feed) {
- $this->view->currentName = $feed->name ();
- $this->nb_not_read_cat = $feed->nbNotRead ();
- $this->view->get_f = $type['id'];
- $this->view->get_c = $feed->category ();
- return false;
- } else {
+ case 's':
+ $this->view->currentName = Translate::t ('your_favorites');
+ $this->view->get_c = $getType;
return true;
- }
- } else {
- return true;
+ case 'c':
+ $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null;
+ if ($cat === null) {
+ $cat = $this->catDAO->searchById ($getId);
+ }
+ if ($cat) {
+ $this->view->currentName = $cat->name ();
+ $this->nb_not_read_cat = $cat->nbNotRead ();
+ $this->view->get_c = $getId;
+ return true;
+ } else {
+ return false;
+ }
+ case 'f':
+ $feed = HelperCategory::findFeed($this->view->cat_aside, $getId);
+ if (empty($feed)) {
+ $feed = $this->feedDAO->searchById ($getId);
+ }
+ if ($feed) {
+ $this->view->currentName = $feed->name ();
+ $this->nb_not_read_cat = $feed->nbNotRead ();
+ $this->view->get_f = $getId;
+ $this->view->get_c = $feed->category ();
+ return true;
+ } else {
+ return false;
+ }
+ default:
+ return false;
}
}
@@ -270,7 +254,7 @@ class indexController extends ActionController {
curl_close ($ch);
$res = json_decode ($result, true);
- if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) {
+ if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mailLogin ()) {
Session::_param ('mail', $res['email']);
invalidateHttpCache();
} else {