aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-03-10 16:28:47 +0200
committerMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-03-10 16:28:47 +0200
commitfb26cc9375ce9ef8df748eb473eb6e58884421c6 (patch)
tree3b1ac9bf4b1eb95c4ca91c02b447350516b8ad84 /inc/poche/Poche.class.php
parent17b2afefad1947042cc9fbbb841c3a023d00d96d (diff)
downloadwallabag-fb26cc9375ce9ef8df748eb473eb6e58884421c6.tar.gz
wallabag-fb26cc9375ce9ef8df748eb473eb6e58884421c6.tar.zst
wallabag-fb26cc9375ce9ef8df748eb473eb6e58884421c6.zip
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(),