From decc23aaf230f320613f5f09e0c70c7eb758ca70 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:25:03 +0200 Subject: Added save search as tag functionality --- inc/poche/Poche.class.php | 77 +++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 32 deletions(-) (limited to 'inc') 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 Tools::redirect(); break; case 'add_tag' : - $tags = explode(',', $_POST['value']); - $entry_id = $_POST['entry_id']; - $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); - if (!$entry) { - $this->messages->add('e', _('Article not found!')); - Tools::logm('error : article not found'); - Tools::redirect(); - } - //get all already set tags to preven duplicates - $already_set_tags = array(); - $entry_tags = $this->store->retrieveTagsByEntry($entry_id); - foreach ($entry_tags as $tag) { - $already_set_tags[] = $tag['value']; + if (isset($_GET['search'])) { + //when we want to apply a tag to a search + $search = true; + $tags = array($_GET['search']); + $allentry_ids = $this->store->search($tags[0], $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; + } + } else { //add a tag to a single article + $tags = explode(',', $_POST['value']); + $entry_ids = array($_POST['entry_id']); } - foreach($tags as $key => $tag_value) { - $value = trim($tag_value); - if ($value && !in_array($value, $already_set_tags)) { - $tag = $this->store->retrieveTagByValue($value); - - if (is_null($tag)) { - # we create the tag - $tag = $this->store->createTag($value); - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'tags_id_seq'; + foreach($entry_ids as $entry_id) { + $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); + if (!$entry) { + $this->messages->add('e', _('Article not found!')); + Tools::logm('error : article not found'); + Tools::redirect(); + } + //get all already set tags to preven duplicates + $already_set_tags = array(); + $entry_tags = $this->store->retrieveTagsByEntry($entry_id); + foreach ($entry_tags as $tag) { + $already_set_tags[] = $tag['value']; + } + foreach($tags as $key => $tag_value) { + $value = trim($tag_value); + if ($value && !in_array($value, $already_set_tags)) { + $tag = $this->store->retrieveTagByValue($value); + if (is_null($tag)) { + # we create the tag + $tag = $this->store->createTag($value); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'tags_id_seq'; + } + $tag_id = $this->store->getLastId($sequence); } - $tag_id = $this->store->getLastId($sequence); - } - else { - $tag_id = $tag['id']; - } - - # we assign the tag to the article - $this->store->setTagToEntry($tag_id, $entry_id); + else { + $tag_id = $tag['id']; + } + + # we assign the tag to the article + $this->store->setTagToEntry($tag_id, $entry_id); + } } } + $this->messages->add('s', _('the tag has been applied successfully')); Tools::redirect(); break; case 'remove_tag' : -- cgit v1.2.3 From 78bddb22bee94c86af04061cb630c97625b17898 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:31:21 +0200 Subject: Remove unnecessary line --- inc/poche/Poche.class.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 429c13b8..61bc8e13 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -513,7 +513,6 @@ class Poche case 'add_tag' : if (isset($_GET['search'])) { //when we want to apply a tag to a search - $search = true; $tags = array($_GET['search']); $allentry_ids = $this->store->search($tags[0], $this->user->getId()); $entry_ids = array(); -- cgit v1.2.3 From 9c743ab965b978aa72a6272172b33f562d1f1f96 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 12:14:20 +0200 Subject: Clean old unused tags when deleting a tag --- inc/poche/Database.class.php | 18 ++++++++++++++++++ inc/poche/Poche.class.php | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 141d7987..02e8be8b 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -511,6 +511,24 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); return $query; } + + public function cleanUnusedTags() { + $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; + $query = $this->executeQuery($sql_action,array()); + $tagstokeep = $query->fetchAll(); + $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; + $query = $this->executeQuery($sql_action,array()); + $alltags = $query->fetchAll(); + foreach ($alltags as $tag) { + if ($tag && !in_array($tag,$tagstokeep)) { + //delete tag + $sql_action = "DELETE FROM tags WHERE id=?"; + $params_action = array($tag[0]); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + } + } public function retrieveTagByValue($value) { $tag = NULL; diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 61bc8e13..dc7b76d0 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -558,7 +558,7 @@ class Poche } } } - $this->messages->add('s', _('the tag has been applied successfully')); + $this->messages->add('s', _('The tag has been applied successfully')); Tools::redirect(); break; case 'remove_tag' : @@ -570,6 +570,10 @@ class Poche Tools::redirect(); } $this->store->removeTagForEntry($id, $tag_id); + Tools::logm('tag entry deleted'); + $this->store->cleanUnusedTags(); + Tools::logm('old tags cleaned'); + $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; default: @@ -1131,6 +1135,13 @@ class Poche $this->messages->add('s', _('Cache deleted.')); Tools::redirect(); } + + public function cleanTags() { + $this->store->cleanUnusedTags(); + $this->messages->add('s', _('The unused tags have been cleaned.')); + Tools::logm('clean tags'); + Tools::redirect(); + } /** * return new purifier object with actual config -- cgit v1.2.3 From 4910af33ff79cdce6325a07bb0dc74fe4821e680 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 11 May 2014 16:14:47 +0200 Subject: Removed unnecessary function for cleaning tags --- inc/poche/Poche.class.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index dc7b76d0..8ea5e7a2 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1135,13 +1135,6 @@ class Poche $this->messages->add('s', _('Cache deleted.')); Tools::redirect(); } - - public function cleanTags() { - $this->store->cleanUnusedTags(); - $this->messages->add('s', _('The unused tags have been cleaned.')); - Tools::logm('clean tags'); - Tools::redirect(); - } /** * return new purifier object with actual config -- cgit v1.2.3 From 24696800e5caac6e37ebd2ac166578a9b18aba9d Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 18:51:02 +0200 Subject: Simplifed function which does tag cleanup --- inc/poche/Database.class.php | 17 +++++++++-------- inc/poche/Poche.class.php | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'inc') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 02e8be8b..9e901974 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -512,22 +512,23 @@ class Database { return $query; } - public function cleanUnusedTags() { - $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + public function cleanUnusedTag($tag_id) { + $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $tagstokeep = $query->fetchAll(); - $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $alltags = $query->fetchAll(); + foreach ($alltags as $tag) { if ($tag && !in_array($tag,$tagstokeep)) { - //delete tag $sql_action = "DELETE FROM tags WHERE id=?"; $params_action = array($tag[0]); - $query = $this->executeQuery($sql_action, $params_action); - return $query; + $this->executeQuery($sql_action, $params_action); + return true; } } + } public function retrieveTagByValue($value) { diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8ea5e7a2..515d4cac 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -559,6 +559,7 @@ class Poche } } $this->messages->add('s', _('The tag has been applied successfully')); + Tools::logm('The tag has been applied successfully'); Tools::redirect(); break; case 'remove_tag' : @@ -571,8 +572,9 @@ class Poche } $this->store->removeTagForEntry($id, $tag_id); Tools::logm('tag entry deleted'); - $this->store->cleanUnusedTags(); - Tools::logm('old tags cleaned'); + if ($this->store->cleanUnusedTag($tag_id)) { + Tools::logm('tag deleted'); + } $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; -- cgit v1.2.3