new: Disable taxonomy tags

pull/2137/head
iglocska 2017-04-14 17:10:47 +02:00
parent 23ecf2738f
commit bca4f0dec9
4 changed files with 80 additions and 9 deletions

View File

@ -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);

View File

@ -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';

View File

@ -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;

View File

@ -111,11 +111,17 @@
<td class="short">
<?php
if ($item['existing_tag']):
$url = $baseurl . '/events/index/searchtag:' . h($item['existing_tag']['Tag']['id']);
if ($isAclTagger) $url = $baseurl . '/tags/edit/' . h($item['existing_tag']['Tag']['id']);
if ($item['existing_tag']['Tag']['hide_tag']):
?>
<span class="red bold">Hidden</span>
<?php
else:
$url = $baseurl . '/events/index/searchtag:' . h($item['existing_tag']['Tag']['id']);
if ($isAclTagger) $url = $baseurl . '/tags/edit/' . h($item['existing_tag']['Tag']['id']);
?>
<a href="<?php echo $url;?>" class="<?php echo $isAclTagger ? 'tagFirstHalf' : 'tag' ?>" style="background-color:<?php echo h($item['existing_tag']['Tag']['colour']);?>;color:<?php echo $this->TextColour->getTextColour($item['existing_tag']['Tag']['colour']);?>"><?php echo h($item['existing_tag']['Tag']['name']); ?></a>
<?php
endif;
endif;
?>
</td>
@ -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();
?>
<span class="<?php echo $item['existing_tag'] ? 'icon-refresh' : 'icon-plus'; ?> useCursorPointer" title="Refresh or enable" role="button" tabindex="0" aria-label="Refresh or enable" onClick="submitQuickTag('<?php echo 'quick_' . h($k); ?>');"></span>
<span class="icon-refresh useCursorPointer" title="Refresh" role="button" tabindex="0" aria-label="Refresh" onClick="submitQuickTag('<?php echo 'quick_' . h($k); ?>');"></span>
<span class="icon-minus useCursorPointer" title="Disable" role="button" tabindex="0" aria-label="Disable" onClick="submitQuickTag('<?php echo 'quick_disable_' . h($k); ?>');"></span>
<?php
else:
?>
<span class="icon-plus useCursorPointer" title="Enable" role="button" tabindex="0" aria-label="Refresh or enable" onClick="submitQuickTag('<?php echo 'quick_' . h($k); ?>');"></span>
<?php
endif;
echo $this->Form->end();
} else {
echo 'N/A';