aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Database.class.php')
-rw-r--r--inc/poche/Database.class.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index c233eda1..d95b9b81 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -249,4 +249,75 @@ class Database {
249 public function getLastId($column = '') { 249 public function getLastId($column = '') {
250 return $this->getHandle()->lastInsertId($column); 250 return $this->getHandle()->lastInsertId($column);
251 } 251 }
252
253 public function retrieveAllTags() {
254 $sql = "SELECT * FROM tags";
255 $query = $this->executeQuery($sql, array());
256 $tags = $query->fetchAll();
257
258 return $tags;
259 }
260
261 public function retrieveTag($id) {
262 $tag = NULL;
263 $sql = "SELECT * FROM tags WHERE id=?";
264 $params = array(intval($id));
265 $query = $this->executeQuery($sql, $params);
266 $tag = $query->fetchAll();
267
268 return isset($tag[0]) ? $tag[0] : null;
269 }
270
271 public function retrieveEntriesByTag($tag_id) {
272 $sql =
273 "SELECT * FROM entries
274 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
275 WHERE tags_entries.tag_id = ?";
276 $query = $this->executeQuery($sql, array($tag_id));
277 $entries = $query->fetchAll();
278
279 return $entries;
280 }
281
282 public function retrieveTagsByEntry($entry_id) {
283 $sql =
284 "SELECT * FROM tags
285 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
286 WHERE tags_entries.entry_id = ?";
287 $query = $this->executeQuery($sql, array($entry_id));
288 $tags = $query->fetchAll();
289
290 return $tags;
291 }
292
293 public function removeTagForEntry($entry_id, $tag_id) {
294 $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
295 $params_action = array($tag_id, $entry_id);
296 $query = $this->executeQuery($sql_action, $params_action);
297 return $query;
298 }
299
300 public function retrieveTagByValue($value) {
301 $tag = NULL;
302 $sql = "SELECT * FROM tags WHERE value=?";
303 $params = array($value);
304 $query = $this->executeQuery($sql, $params);
305 $tag = $query->fetchAll();
306
307 return isset($tag[0]) ? $tag[0] : null;
308 }
309
310 public function createTag($value) {
311 $sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
312 $params_action = array($value);
313 $query = $this->executeQuery($sql_action, $params_action);
314 return $query;
315 }
316
317 public function setTagToEntry($tag_id, $entry_id) {
318 $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
319 $params_action = array($tag_id, $entry_id);
320 $query = $this->executeQuery($sql_action, $params_action);
321 return $query;
322 }
252} 323}