aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-10 18:14:43 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-10 18:14:43 +0100
commit1acd18510a8fc5b843bf793322ed79b249b195dc (patch)
tree8218a340193e2827e1c4b0a6117adf81344e7b43 /inc/poche/Poche.class.php
parentd47a05a9a5185e835d51341febc8257f5262ce03 (diff)
parentfb26cc9375ce9ef8df748eb473eb6e58884421c6 (diff)
downloadwallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.gz
wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.zst
wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.zip
Merge pull request #544 from mariroz/feature-tags-autocomplete
a lot of enhancements related to tags: tags list is now sorted, shows number of articles, autocomplete added according to #477, #542
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php52
1 files changed, 35 insertions, 17 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 0c8e798c..480f6d45 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -488,25 +488,33 @@ class Poche
488 Tools::logm('error : article not found'); 488 Tools::logm('error : article not found');
489 Tools::redirect(); 489 Tools::redirect();
490 } 490 }
491 //get all already set tags to preven duplicates
492 $already_set_tags = array();
493 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
494 foreach ($entry_tags as $tag) {
495 $already_set_tags[] = $tag['value'];
496 }
491 foreach($tags as $key => $tag_value) { 497 foreach($tags as $key => $tag_value) {
492 $value = trim($tag_value); 498 $value = trim($tag_value);
493 $tag = $this->store->retrieveTagByValue($value); 499 if ($value && !in_array($value, $already_set_tags)) {
494 500 $tag = $this->store->retrieveTagByValue($value);
495 if (is_null($tag)) { 501
496 # we create the tag 502 if (is_null($tag)) {
497 $tag = $this->store->createTag($value); 503 # we create the tag
498 $sequence = ''; 504 $tag = $this->store->createTag($value);
499 if (STORAGE == 'postgres') { 505 $sequence = '';
500 $sequence = 'tags_id_seq'; 506 if (STORAGE == 'postgres') {
501 } 507 $sequence = 'tags_id_seq';
502 $tag_id = $this->store->getLastId($sequence); 508 }
503 } 509 $tag_id = $this->store->getLastId($sequence);
504 else { 510 }
505 $tag_id = $tag['id']; 511 else {
512 $tag_id = $tag['id'];
513 }
514
515 # we assign the tag to the article
516 $this->store->setTagToEntry($tag_id, $entry_id);
506 } 517 }
507
508 # we assign the tag to the article
509 $this->store->setTagToEntry($tag_id, $entry_id);
510 } 518 }
511 if(!$import) { 519 if(!$import) {
512 Tools::redirect(); 520 Tools::redirect();
@@ -579,7 +587,17 @@ class Poche
579 break; 587 break;
580 case 'tags': 588 case 'tags':
581 $token = $this->user->getConfigValue('token'); 589 $token = $this->user->getConfigValue('token');
582 $tags = $this->store->retrieveAllTags($this->user->getId()); 590 //if term is set - search tags for this term
591 $term = Tools::checkVar('term');
592 $tags = $this->store->retrieveAllTags($this->user->getId(), $term);
593 if (Tools::isAjaxRequest()) {
594 $result = array();
595 foreach ($tags as $tag) {
596 $result[] = $tag['value'];
597 }
598 echo json_encode($result);
599 exit;
600 }
583 $tpl_vars = array( 601 $tpl_vars = array(
584 'token' => $token, 602 'token' => $token,
585 'user_id' => $this->user->getId(), 603 'user_id' => $this->user->getId(),