aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Database.class.php31
-rw-r--r--inc/poche/Poche.class.php31
2 files changed, 62 insertions, 0 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index a89bce41..d95b9b81 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -289,4 +289,35 @@ class Database {
289 289
290 return $tags; 290 return $tags;
291 } 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 }
292} 323}
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 68f56d62..d415dd03 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -397,6 +397,36 @@ class Poche
397 Tools::redirect(); 397 Tools::redirect();
398 } 398 }
399 break; 399 break;
400 case 'add_tag' :
401 $tags = explode(',', $_POST['value']);
402 $entry_id = $_POST['entry_id'];
403 foreach($tags as $key => $tag_value) {
404 $value = trim($tag_value);
405 $tag = $this->store->retrieveTagByValue($value);
406
407 if (is_null($tag)) {
408 # we create the tag
409 $tag = $this->store->createTag($value);
410 $sequence = '';
411 if (STORAGE == 'postgres') {
412 $sequence = 'tags_id_seq';
413 }
414 $tag_id = $this->store->getLastId($sequence);
415 }
416 else {
417 $tag_id = $tag['id'];
418 }
419
420 # we assign the tag to the article
421 $this->store->setTagToEntry($tag_id, $entry_id);
422 }
423 Tools::redirect();
424 break;
425 case 'remove_tag' :
426 $tag_id = $_GET['tag_id'];
427 $this->store->removeTagForEntry($id, $tag_id);
428 Tools::redirect();
429 break;
400 default: 430 default:
401 break; 431 break;
402 } 432 }
@@ -434,6 +464,7 @@ class Poche
434 # tags 464 # tags
435 $tags = $this->store->retrieveTagsByEntry($id); 465 $tags = $this->store->retrieveTagsByEntry($id);
436 $tpl_vars = array( 466 $tpl_vars = array(
467 'entry_id' => $id,
437 'tags' => $tags, 468 'tags' => $tags,
438 ); 469 );
439 break; 470 break;