From 9daa4c14636ca6b70031344f812ac99947b3a2b0 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 16 Mar 2013 20:29:24 +0100 Subject: Ajout champs de recherche + désactivation des raccourcis quand un input a le focus -> fix bugs #18 et #29 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/indexController.php | 10 ++++---- app/layout/header.phtml | 2 +- app/models/Entry.php | 47 ++++++++++++++++++++++++++++--------- app/views/javascript/main.phtml | 20 ++++++++++++++++ 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 18d9d43c3..79d430f99 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -30,11 +30,13 @@ class indexController extends ActionController { $this->view->get_f = false; $order = $this->view->conf->sortOrder (); + $search = Request::param ('search'); + $error = false; // Récupère les flux par catégorie, favoris ou tous if ($get == 'favoris') { - $entries = $entryDAO->listFavorites ($mode, $order); + $entries = $entryDAO->listFavorites ($mode, $search, $order); $this->view->get_c = $get; View::prependTitle ('Vos favoris - '); } elseif ($get != false) { @@ -42,7 +44,7 @@ class indexController extends ActionController { $get = substr ($get, 2); if ($typeGet == 'c') { - $entries = $entryDAO->listByCategory ($get, $mode, $order); + $entries = $entryDAO->listByCategory ($get, $mode, $search, $order); $cat = $catDAO->searchById ($get); if ($cat) { @@ -52,7 +54,7 @@ class indexController extends ActionController { $error = true; } } elseif ($typeGet == 'f') { - $entries = $entryDAO->listByFeed ($get, $mode, $order); + $entries = $entryDAO->listByFeed ($get, $mode, $search, $order); $feed = $feedDAO->searchById ($get); if ($feed) { @@ -74,7 +76,7 @@ class indexController extends ActionController { // 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, $order); + $entries = $entryDAO->listEntries ($mode, $search, $order); } try { diff --git a/app/layout/header.phtml b/app/layout/header.phtml index 04dbd91ff..351984aa7 100644 --- a/app/layout/header.phtml +++ b/app/layout/header.phtml @@ -17,7 +17,7 @@
- +
diff --git a/app/models/Entry.php b/app/models/Entry.php index 8a1ee1449..b1d7b8880 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -229,12 +229,22 @@ class EntryDAO extends Model_pdo { } } - public function listEntries ($mode, $order = 'high_to_low') { + public function listEntries ($mode, $search = false, $order = 'high_to_low') { $where = ''; if ($mode == 'not_read') { $where = ' WHERE is_read=0'; } + $values = array(); + if ($search) { + $values[] = '%'.$search.'%'; + if ($mode == 'not_read') { + $where = ' AND title LIKE ?'; + } else { + $where = ' WHERE title LIKE ?'; + } + } + if ($order == 'low_to_high') { $order = ' DESC'; } else { @@ -243,7 +253,7 @@ class EntryDAO extends Model_pdo { $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; $stm = $this->bd->prepare ($sql); - $stm->execute (); + $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); $this->nbItems = $res[0]['count']; @@ -254,17 +264,23 @@ class EntryDAO extends Model_pdo { . ' ORDER BY date' . $order . ' LIMIT ' . $deb . ', ' . $fin; $stm = $this->bd->prepare ($sql); - $stm->execute (); + $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listFavorites ($mode, $order = 'high_to_low') { + public function listFavorites ($mode, $search = false, $order = 'high_to_low') { $where = ' WHERE is_favorite=1'; if ($mode == 'not_read') { $where .= ' AND is_read=0'; } + $values = array(); + if ($search) { + $values[] = '%'.$search.'%'; + $where = ' AND title LIKE ?'; + } + if ($order == 'low_to_high') { $order = ' DESC'; } else { @@ -273,7 +289,7 @@ class EntryDAO extends Model_pdo { $sql = 'SELECT COUNT(*) AS count FROM entry' . $where; $stm = $this->bd->prepare ($sql); - $stm->execute (); + $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); $this->nbItems = $res[0]['count']; @@ -290,17 +306,23 @@ class EntryDAO extends Model_pdo { } $stm = $this->bd->prepare ($sql); - $stm->execute (); + $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listByCategory ($cat, $mode, $order = 'high_to_low') { + public function listByCategory ($cat, $mode, $search = false, $order = 'high_to_low') { $where = ' WHERE category=?'; if ($mode == 'not_read') { $where .= ' AND is_read=0'; } + $values = array ($cat); + if ($search) { + $values[] = '%'.$search.'%'; + $where = ' AND title LIKE ?'; + } + if ($order == 'low_to_high') { $order = ' DESC'; } else { @@ -309,7 +331,6 @@ class EntryDAO extends Model_pdo { $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']; @@ -322,19 +343,23 @@ class EntryDAO extends Model_pdo { $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') { + public function listByFeed ($feed, $mode, $search = false, $order = 'high_to_low') { $where = ' WHERE id_feed=?'; if ($mode == 'not_read') { $where .= ' AND is_read=0'; } + $values = array(); + if ($search) { + $values[] = '%'.$search.'%'; + $where = ' AND title LIKE ?'; + } + if ($order == 'low_to_high') { $order = ' DESC'; } else { diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index d503cac0f..a4e3229bf 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -153,16 +153,22 @@ $(document).ready (function () { // on marque comme lu ou non lu active = $(".flux.active"); mark_read (active); + }, { + 'disable_in_input':true }); shortcut.add("shift+", function () { // on marque tout comme lu url = $("#top a.read_all").attr ("href"); redirect (url, false); + }, { + 'disable_in_input':true }); shortcut.add("", function () { // on marque comme favori ou non favori active = $(".flux.active"); mark_favorite (active); + }, { + 'disable_in_input':true }); // Touches de navigation @@ -176,6 +182,8 @@ $(document).ready (function () { } else if (new_active[0] === undefined) { slide (last_active, old_active); } + }, { + 'disable_in_input':true }); shortcut.add("shift+", function () { old_active = $(".flux.active"); @@ -184,6 +192,8 @@ $(document).ready (function () { if (first.hasClass("flux")) { slide (first, old_active); } + }, { + 'disable_in_input':true }); shortcut.add("", function () { old_active = $(".flux.active"); @@ -195,6 +205,8 @@ $(document).ready (function () { } else if (new_active[0] === undefined) { slide (first_active, old_active); } + }, { + 'disable_in_input':true }); shortcut.add("shift+", function () { old_active = $(".flux.active"); @@ -203,18 +215,26 @@ $(document).ready (function () { if (last.hasClass("flux")) { slide (last, old_active); } + }, { + 'disable_in_input':true }); shortcut.add("", function () { url = $(".pager-next a").attr ("href"); redirect (url, false); + }, { + 'disable_in_input':true }); shortcut.add("", function () { url = $(".pager-previous a").attr ("href"); redirect (url, false); + }, { + 'disable_in_input':true }); shortcut.add("", function () { url = $(".flux.active .link a").attr ("href"); redirect (url, true); + }, { + 'disable_in_input':true }); }); -- cgit v1.2.3