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/models/Entry.php | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'app/models/Entry.php') 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 { -- cgit v1.2.3