From bca4f0dec954c44694e794d0eed576bdeaed0f23 Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 14 Apr 2017 17:10:47 +0200 Subject: [PATCH] new: Disable taxonomy tags --- app/Controller/TaxonomiesController.php | 20 +++++++++++++++- app/Model/Tag.php | 14 +++++++++-- app/Model/Taxonomy.php | 31 ++++++++++++++++++++++--- app/View/Taxonomies/view.ctp | 24 ++++++++++++++++--- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/app/Controller/TaxonomiesController.php b/app/Controller/TaxonomiesController.php index f82f2936b..b0c1cc5e5 100644 --- a/app/Controller/TaxonomiesController.php +++ b/app/Controller/TaxonomiesController.php @@ -28,7 +28,7 @@ class TaxonomiesController extends AppController { $total += empty($predicate['TaxonomyEntry']) ? 1 : count($predicate['TaxonomyEntry']); } $taxonomies[$key]['total_count'] = $total; - $taxonomies[$key]['current_count'] = $this->Tag->find('count', array('conditions' => array('lower(Tag.name) LIKE ' => strtolower($taxonomy['Taxonomy']['namespace']) . ':%'))); + $taxonomies[$key]['current_count'] = $this->Tag->find('count', array('conditions' => array('lower(Tag.name) LIKE ' => strtolower($taxonomy['Taxonomy']['namespace']) . ':%', 'hide_tag' => 0))); unset($taxonomies[$key]['TaxonomyPredicate']); } $this->set('taxonomies', $taxonomies); @@ -198,6 +198,24 @@ class TaxonomiesController extends AppController { $this->redirect($this->referer()); } + public function disableTag($taxonomy_id = false) { + if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) throw new NotFoundException('You don\'t have permission to do that.'); + if ($taxonomy_id) { + $result = $this->Taxonomy->disableTags($taxonomy_id); + } else { + if (isset($this->request->data['Taxonomy'])) { + $this->request->data['Tag'] = $this->request->data['Taxonomy']; + unset($this->request->data['Taxonomy']); + } + if (isset($this->request->data['Tag']['request'])) $this->request->data['Tag'] = $this->request->data['Tag']['request']; + if (!isset($this->request->data['Tag']['nameList'])) $this->request->data['Tag']['nameList'] = array($this->request->data['Tag']['name']); + else $this->request->data['Tag']['nameList'] = json_decode($this->request->data['Tag']['nameList'], true); + $result = $this->Taxonomy->disableTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']); + } + $this->Session->setFlash($result ? 'The tag(s) has been hidden.' : 'The tag(s) could not be hidden. Please, try again.'); + $this->redirect($this->referer()); + } + public function taxonomyMassConfirmation($id) { if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) throw new NotFoundException('You don\'t have permission to do that.'); $this->set('id', $id); diff --git a/app/Model/Tag.php b/app/Model/Tag.php index c1feffd50..027a4e225 100644 --- a/app/Model/Tag.php +++ b/app/Model/Tag.php @@ -191,15 +191,25 @@ class Tag extends AppModel { return ($this->save($data)); } - public function quickEdit($tag, $name, $colour) { - if ($tag['Tag']['colour'] !== $colour || $tag['Tag']['name'] !== $name) { + public function quickEdit($tag, $name, $colour, $hide = false) { + if ($tag['Tag']['colour'] !== $colour || $tag['Tag']['name'] !== $name || $hide !== false) { $tag['Tag']['name'] = $name; $tag['Tag']['colour'] = $colour; + if ($hide !== false) { + $tag['Tag']['hide_tag'] = $hide; + } return ($this->save($tag['Tag'])); } return true; } + public function disableTags($tags) { + foreach ($tags as $k => $v) { + $tags[$k]['Tag']['hide_tag'] = 1; + } + return ($this->saveAll($tags)); + } + public function getTagsForNamespace($namespace) { $contain = array('EventTag'); $contain[] = 'AttributeTag'; diff --git a/app/Model/Taxonomy.php b/app/Model/Taxonomy.php index d93709d9f..56e298372 100644 --- a/app/Model/Taxonomy.php +++ b/app/Model/Taxonomy.php @@ -233,7 +233,6 @@ class Taxonomy extends AppModel { $this->Tag = ClassRegistry::init('Tag'); App::uses('ColourPaletteTool', 'Tools'); $paletteTool = new ColourPaletteTool(); - App::uses('ColourPaletteTool', 'Tools'); $taxonomy = $this->__getTaxonomy($id, array('full' => true)); $tags = $this->Tag->getTagsForNamespace($taxonomy['Taxonomy']['namespace']); $colours = $paletteTool->generatePaletteFromString($taxonomy['Taxonomy']['namespace'], count($taxonomy['entries'])); @@ -246,7 +245,7 @@ class Taxonomy extends AppModel { foreach ($tagList as $tagName) { if ($tagName === $entry['tag']) { if (isset($tags[strtoupper($entry['tag'])])) { - $this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $tagName, $colour); + $this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $tagName, $colour, 0); } else { $this->Tag->quickAdd($tagName, $colour); } @@ -254,7 +253,7 @@ class Taxonomy extends AppModel { } } else { if (isset($tags[strtoupper($entry['tag'])])) { - $this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $entry['tag'], $colour); + $this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $entry['tag'], $colour, 0); } else { $this->Tag->quickAdd($entry['tag'], $colour); } @@ -263,6 +262,32 @@ class Taxonomy extends AppModel { return true; } + public function disableTags($id, $tagList = false) { + if ($tagList && !is_array($tagList)) $tagList = array($tagList); + $this->Tag = ClassRegistry::init('Tag'); + $tags = array(); + if ($tagList) { + $tags = $tagList; + } else { + $taxonomy = $this->__getTaxonomy($id, array('full' => true)); + foreach ($taxonomy['entries'] as $entry) { + $tags[] = $entry['tag']; + } + } + if (empty($tags)) { + return true; + } + $tags = $this->Tag->find('all', array( + 'conditions' => array('Tag.name' => $tags, 'Tag.hide_tag' => 0), + 'recursive' => -1 + )); + if (empty($tags)) { + return true; + } + $this->Tag->disableTags($tags); + return true; + } + public function listTaxonomies($options = array('full' => false, 'enabled' => false)) { $recursive = -1; if (isset($options['full']) && $options['full']) $recursive = 2; diff --git a/app/View/Taxonomies/view.ctp b/app/View/Taxonomies/view.ctp index facfc7ab1..767fce867 100644 --- a/app/View/Taxonomies/view.ctp +++ b/app/View/Taxonomies/view.ctp @@ -111,11 +111,17 @@ + Hidden + @@ -125,9 +131,21 @@ echo $this->Form->create('Tag', array('id' => 'quick_' . h($k), 'url' => '/taxonomies/addTag/', 'style' => 'margin:0px;')); echo $this->Form->input('name', array('type' => 'hidden', 'value' => $item['tag'])); echo $this->Form->input('taxonomy_id', array('type' => 'hidden', 'value' => $taxonomy['id'])); + echo $this->Form->end(); + if ($item['existing_tag'] && !$item['existing_tag']['Tag']['hide_tag']): + echo $this->Form->create('Tag', array('id' => 'quick_disable_' . h($k), 'url' => '/taxonomies/disableTag/', 'style' => 'margin:0px;')); + echo $this->Form->input('name', array('type' => 'hidden', 'value' => $item['tag'])); + echo $this->Form->input('taxonomy_id', array('type' => 'hidden', 'value' => $taxonomy['id'])); + echo $this->Form->end(); ?> - + + + + Form->end(); } else { echo 'N/A';