From 0222b8c0904f20a87e6cdd12eb82a1a781e59764 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Mon, 4 Nov 2019 14:55:43 +0100 Subject: [PATCH] chg: [tag:exclusive] Added support of local while checking for exclusivity --- app/Controller/EventsController.php | 45 +++++++++++++++++++++-------- app/Model/Taxonomy.php | 21 +++++++++++++- app/View/Elements/ajaxTags.ctp | 23 +++++++++++++-- app/webroot/css/main.css | 16 ++++++++++ 4 files changed, 89 insertions(+), 16 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index be5987a9e..a2b127dac 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -1160,7 +1160,13 @@ class EventsController extends AppController unset($event['Object'][$k]['Attribute'][$k2]['AttributeTag'][$k3]); } } - $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($attribute['AttributeTag'], '{n}.Tag.name')); + $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']); + foreach ($tagConflicts['global'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } + foreach ($tagConflicts['local'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } $event['Object'][$k]['Attribute'][$k2]['tagConflicts'] = $tagConflicts; } } @@ -1171,7 +1177,13 @@ class EventsController extends AppController unset($event['Attribute'][$k]['AttributeTag'][$k2]); } } - $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($attribute['AttributeTag'], '{n}.Tag.name')); + $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']); + foreach ($tagConflicts['global'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } + foreach ($tagConflicts['local'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } $event['Attribute'][$k]['tagConflicts'] = $tagConflicts; } if (empty($this->passedArgs['sort'])) { @@ -1372,8 +1384,11 @@ class EventsController extends AppController } } - $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($event['EventTag'], '{n}.Tag.name')); - foreach ($tagConflicts as $tagConflict) { + $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($event['EventTag']); + foreach ($tagConflicts['global'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } + foreach ($tagConflicts['local'] as $tagConflict) { $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; } $this->set('tagConflicts', $tagConflicts); @@ -1394,8 +1409,11 @@ class EventsController extends AppController unset($event['Attribute'][$k]['AttributeTag'][$k2]); } } - $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($attribute['AttributeTag'], '{n}.Tag.name')); - foreach ($tagConflicts as $tagConflict) { + $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']); + foreach ($tagConflicts['global'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } + foreach ($tagConflicts['local'] as $tagConflict) { $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; } $event['Attribute'][$k]['tagConflicts'] = $tagConflicts; @@ -1424,8 +1442,11 @@ class EventsController extends AppController unset($event['Object'][$k]['Attribute'][$k2]['AttributeTag'][$k3]); } } - $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($attribute['AttributeTag'], '{n}.Tag.name')); - foreach ($tagConflicts as $tagConflict) { + $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']); + foreach ($tagConflicts['global'] as $tagConflict) { + $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; + } + foreach ($tagConflicts['local'] as $tagConflict) { $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; } $event['Object'][$k]['Attribute'][$k2]['tagConflicts'] = $tagConflicts; @@ -3857,15 +3878,15 @@ class EventsController extends AppController } $tagsOnEvent = $this->Event->EventTag->find('all', array( 'conditions' => array( - 'Tag.id' => $tag_id, - 'EventTag.event_id' => $id + 'EventTag.event_id' => $id, + 'EventTag.local' => $local ), 'contain' => 'Tag', 'fields' => array('Tag.name'), 'recursive' => -1 )); - $exclusive_test_passed = $this->Taxonomy->checkIfNewTagIsAllowedByTaxonomy($tag['Tag']['name'], $tagsOnEvent); - if (!empty($exclusive_test_passed)) { + $exclusive_test_passed = $this->Taxonomy->checkIfNewTagIsAllowedByTaxonomy($tag['Tag']['name'], Hash::extract($tagsOnEvent, '{n}.Tag.name')); + if (!$exclusive_test_passed) { $fail = __('Tag is not allowed due to taxonomy exclusivity settings'); continue; } diff --git a/app/Model/Taxonomy.php b/app/Model/Taxonomy.php index 34e5a71f9..741324868 100644 --- a/app/Model/Taxonomy.php +++ b/app/Model/Taxonomy.php @@ -573,7 +573,26 @@ class Taxonomy extends AppModel return true; } - public function checkIfTagInconsistencies($tagNameList) + public function checkIfTagInconsistencies($tagList) + { + $eventTags = array(); + $localEventTags = array(); + foreach($tagList as $tag) { + if ($tag['local'] == 0) { + $eventTags[] = $tag['Tag']['name']; + } else { + $localEventTags[] = $tag['Tag']['name']; + } + } + $tagConflicts = $this->getTagConflicts($eventTags); + $localTagConflicts = $this->getTagConflicts($localEventTags); + return array( + 'global' => $tagConflicts, + 'local' => $localTagConflicts + ); + } + + public function getTagConflicts($tagNameList) { $potentiallyConflictingTaxonomy = array(); $conflictingTaxonomy = array(); diff --git a/app/View/Elements/ajaxTags.ctp b/app/View/Elements/ajaxTags.ctp index bf00904fe..6a0c15255 100644 --- a/app/View/Elements/ajaxTags.ctp +++ b/app/View/Elements/ajaxTags.ctp @@ -163,9 +163,11 @@ $tagData ); $tagConflictData = ''; - if (!empty($tagConflicts)) { + if (!empty($tagConflicts['global'])) { $tagConflictData .= '
'; - foreach ($tagConflicts as $tagConflict) { + $tagConflictData .= ''; + $tagConflictData .= '
'; + foreach ($tagConflicts['global'] as $tagConflict) { $tagConflictData .= sprintf( '%s
', h($tagConflict['conflict']) @@ -174,7 +176,22 @@ $tagConflictData .= sprintf('%s
', h($tag)); } } - $tagConflictData .= '
'; + $tagConflictData .= '
'; + } + if (!empty($tagConflicts['local'])) { + $tagConflictData .= '
'; + $tagConflictData .= ''; + $tagConflictData .= '
'; + foreach ($tagConflicts['local'] as $tagConflict) { + $tagConflictData .= sprintf( + '%s
', + h($tagConflict['conflict']) + ); + foreach ($tagConflict['tags'] as $tag) { + $tagConflictData .= sprintf('%s
', h($tag)); + } + } + $tagConflictData .= '
'; } echo $tagConflictData; ?> diff --git a/app/webroot/css/main.css b/app/webroot/css/main.css index 524c20716..550d79ad6 100644 --- a/app/webroot/css/main.css +++ b/app/webroot/css/main.css @@ -2397,6 +2397,12 @@ table tr:hover .down-expand-button { .tag-conflict-notice { margin: 5px 0px; + padding-right: 14px; + position: relative; +} + +.tag-conflict-notice div.text-container { + overflow: auto; } .attributeTagContainer .tag-conflict-notice { @@ -2407,4 +2413,14 @@ table tr:hover .down-expand-button { .tag-conflict-notice .apply_css_arrow { display: inline-block; padding: 0px 6px; +} + +.tag-conflict-notice i.icon { + position: absolute; + padding: 3px; + right: 0px; + top: 0px; + background-color: #3b3b3b; + color: white; + border-radius: 3px; } \ No newline at end of file