From 4886ed6d3637df0b3e16e672d58d4ef8f17dc432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Dec 2013 14:22:29 +0100 Subject: [add] page which lists entries for a tag --- inc/poche/Database.class.php | 21 +++++++++++++++++++++ inc/poche/Poche.class.php | 8 ++++++++ inc/poche/Tools.class.php | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 8e9ee0b7..a89bce41 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -258,6 +258,27 @@ class Database { return $tags; } + public function retrieveTag($id) { + $tag = NULL; + $sql = "SELECT * FROM tags WHERE id=?"; + $params = array(intval($id)); + $query = $this->executeQuery($sql, $params); + $tag = $query->fetchAll(); + + return isset($tag[0]) ? $tag[0] : null; + } + + public function retrieveEntriesByTag($tag_id) { + $sql = + "SELECT * FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE tags_entries.tag_id = ?"; + $query = $this->executeQuery($sql, array($tag_id)); + $entries = $query->fetchAll(); + + return $entries; + } + public function retrieveTagsByEntry($entry_id) { $sql = "SELECT * FROM tags diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5d368842..fefbb02d 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -437,6 +437,14 @@ class Poche 'tags' => $tags, ); break; + case 'tag': + $entries = $this->store->retrieveEntriesByTag($id); + $tag = $this->store->retrieveTag($id); + $tpl_vars = array( + 'tag' => $tag, + 'entries' => $entries, + ); + break; case 'tags': $tags = $this->store->retrieveAllTags(); $tpl_vars = array( diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index b0ef55f5..6da53023 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -90,7 +90,7 @@ class Tools { $views = array( 'install', 'import', 'export', 'config', 'tags', - 'edit-tags', 'view', 'login', 'error' + 'edit-tags', 'view', 'login', 'error', 'tag' ); if (in_array($view, $views)) { -- cgit v1.2.3