aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rwxr-xr-xinc/poche/Poche.class.php77
1 files changed, 45 insertions, 32 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 5aa6ea07..429c13b8 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -511,42 +511,55 @@ class Poche
511 Tools::redirect(); 511 Tools::redirect();
512 break; 512 break;
513 case 'add_tag' : 513 case 'add_tag' :
514 $tags = explode(',', $_POST['value']); 514 if (isset($_GET['search'])) {
515 $entry_id = $_POST['entry_id']; 515 //when we want to apply a tag to a search
516 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); 516 $search = true;
517 if (!$entry) { 517 $tags = array($_GET['search']);
518 $this->messages->add('e', _('Article not found!')); 518 $allentry_ids = $this->store->search($tags[0], $this->user->getId());
519 Tools::logm('error : article not found'); 519 $entry_ids = array();
520 Tools::redirect(); 520 foreach ($allentry_ids as $eachentry) {
521 } 521 $entry_ids[] = $eachentry[0];
522 //get all already set tags to preven duplicates 522 }
523 $already_set_tags = array(); 523 } else { //add a tag to a single article
524 $entry_tags = $this->store->retrieveTagsByEntry($entry_id); 524 $tags = explode(',', $_POST['value']);
525 foreach ($entry_tags as $tag) { 525 $entry_ids = array($_POST['entry_id']);
526 $already_set_tags[] = $tag['value'];
527 } 526 }
528 foreach($tags as $key => $tag_value) { 527 foreach($entry_ids as $entry_id) {
529 $value = trim($tag_value); 528 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId());
530 if ($value && !in_array($value, $already_set_tags)) { 529 if (!$entry) {
531 $tag = $this->store->retrieveTagByValue($value); 530 $this->messages->add('e', _('Article not found!'));
532 531 Tools::logm('error : article not found');
533 if (is_null($tag)) { 532 Tools::redirect();
534 # we create the tag 533 }
535 $tag = $this->store->createTag($value); 534 //get all already set tags to preven duplicates
536 $sequence = ''; 535 $already_set_tags = array();
537 if (STORAGE == 'postgres') { 536 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
538 $sequence = 'tags_id_seq'; 537 foreach ($entry_tags as $tag) {
538 $already_set_tags[] = $tag['value'];
539 }
540 foreach($tags as $key => $tag_value) {
541 $value = trim($tag_value);
542 if ($value && !in_array($value, $already_set_tags)) {
543 $tag = $this->store->retrieveTagByValue($value);
544 if (is_null($tag)) {
545 # we create the tag
546 $tag = $this->store->createTag($value);
547 $sequence = '';
548 if (STORAGE == 'postgres') {
549 $sequence = 'tags_id_seq';
550 }
551 $tag_id = $this->store->getLastId($sequence);
539 } 552 }
540 $tag_id = $this->store->getLastId($sequence); 553 else {
541 } 554 $tag_id = $tag['id'];
542 else { 555 }
543 $tag_id = $tag['id']; 556
544 } 557 # we assign the tag to the article
545 558 $this->store->setTagToEntry($tag_id, $entry_id);
546 # we assign the tag to the article 559 }
547 $this->store->setTagToEntry($tag_id, $entry_id);
548 } 560 }
549 } 561 }
562 $this->messages->add('s', _('the tag has been applied successfully'));
550 Tools::redirect(); 563 Tools::redirect();
551 break; 564 break;
552 case 'remove_tag' : 565 case 'remove_tag' :