chg: [tag:exclusive] Added support of local while checking for

exclusivity
pull/5378/head
mokaddem 2019-11-04 14:55:43 +01:00
parent 1aaa590e30
commit 0222b8c090
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 89 additions and 16 deletions

View File

@ -1160,7 +1160,13 @@ class EventsController extends AppController
unset($event['Object'][$k]['Attribute'][$k2]['AttributeTag'][$k3]); 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; $event['Object'][$k]['Attribute'][$k2]['tagConflicts'] = $tagConflicts;
} }
} }
@ -1171,7 +1177,13 @@ class EventsController extends AppController
unset($event['Attribute'][$k]['AttributeTag'][$k2]); 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; $event['Attribute'][$k]['tagConflicts'] = $tagConflicts;
} }
if (empty($this->passedArgs['sort'])) { if (empty($this->passedArgs['sort'])) {
@ -1372,8 +1384,11 @@ class EventsController extends AppController
} }
} }
$tagConflicts = $this->Taxonomy->checkIfTagInconsistencies(Hash::extract($event['EventTag'], '{n}.Tag.name')); $tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($event['EventTag']);
foreach ($tagConflicts as $tagConflict) { foreach ($tagConflicts['global'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
}
foreach ($tagConflicts['local'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
} }
$this->set('tagConflicts', $tagConflicts); $this->set('tagConflicts', $tagConflicts);
@ -1394,8 +1409,11 @@ class EventsController extends AppController
unset($event['Attribute'][$k]['AttributeTag'][$k2]); 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 as $tagConflict) { foreach ($tagConflicts['global'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
}
foreach ($tagConflicts['local'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
} }
$event['Attribute'][$k]['tagConflicts'] = $tagConflicts; $event['Attribute'][$k]['tagConflicts'] = $tagConflicts;
@ -1424,8 +1442,11 @@ class EventsController extends AppController
unset($event['Object'][$k]['Attribute'][$k2]['AttributeTag'][$k3]); 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 as $tagConflict) { foreach ($tagConflicts['global'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
}
foreach ($tagConflicts['local'] as $tagConflict) {
$warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy']; $warningTagConflict[$tagConflict['taxonomy']['Taxonomy']['namespace']] = $tagConflict['taxonomy'];
} }
$event['Object'][$k]['Attribute'][$k2]['tagConflicts'] = $tagConflicts; $event['Object'][$k]['Attribute'][$k2]['tagConflicts'] = $tagConflicts;
@ -3857,15 +3878,15 @@ class EventsController extends AppController
} }
$tagsOnEvent = $this->Event->EventTag->find('all', array( $tagsOnEvent = $this->Event->EventTag->find('all', array(
'conditions' => array( 'conditions' => array(
'Tag.id' => $tag_id, 'EventTag.event_id' => $id,
'EventTag.event_id' => $id 'EventTag.local' => $local
), ),
'contain' => 'Tag', 'contain' => 'Tag',
'fields' => array('Tag.name'), 'fields' => array('Tag.name'),
'recursive' => -1 'recursive' => -1
)); ));
$exclusive_test_passed = $this->Taxonomy->checkIfNewTagIsAllowedByTaxonomy($tag['Tag']['name'], $tagsOnEvent); $exclusive_test_passed = $this->Taxonomy->checkIfNewTagIsAllowedByTaxonomy($tag['Tag']['name'], Hash::extract($tagsOnEvent, '{n}.Tag.name'));
if (!empty($exclusive_test_passed)) { if (!$exclusive_test_passed) {
$fail = __('Tag is not allowed due to taxonomy exclusivity settings'); $fail = __('Tag is not allowed due to taxonomy exclusivity settings');
continue; continue;
} }

View File

@ -573,7 +573,26 @@ class Taxonomy extends AppModel
return true; 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(); $potentiallyConflictingTaxonomy = array();
$conflictingTaxonomy = array(); $conflictingTaxonomy = array();

View File

@ -163,9 +163,11 @@
$tagData $tagData
); );
$tagConflictData = ''; $tagConflictData = '';
if (!empty($tagConflicts)) { if (!empty($tagConflicts['global'])) {
$tagConflictData .= '<div><div class="alert alert-error tag-conflict-notice">'; $tagConflictData .= '<div><div class="alert alert-error tag-conflict-notice">';
foreach ($tagConflicts as $tagConflict) { $tagConflictData .= '<i class="fas fa-globe-americas icon"></i>';
$tagConflictData .= '<div class="text-container">';
foreach ($tagConflicts['global'] as $tagConflict) {
$tagConflictData .= sprintf( $tagConflictData .= sprintf(
'<strong>%s</strong></br>', '<strong>%s</strong></br>',
h($tagConflict['conflict']) h($tagConflict['conflict'])
@ -174,7 +176,22 @@
$tagConflictData .= sprintf('<span class="apply_css_arrow nowrap">%s</span></br>', h($tag)); $tagConflictData .= sprintf('<span class="apply_css_arrow nowrap">%s</span></br>', h($tag));
} }
} }
$tagConflictData .= '</div></span>'; $tagConflictData .= '</div></div></span>';
}
if (!empty($tagConflicts['local'])) {
$tagConflictData .= '<div><div class="alert alert-error tag-conflict-notice">';
$tagConflictData .= '<i class="fas fa-user icon"></i>';
$tagConflictData .= '<div class="text-container">';
foreach ($tagConflicts['local'] as $tagConflict) {
$tagConflictData .= sprintf(
'<strong>%s</strong></br>',
h($tagConflict['conflict'])
);
foreach ($tagConflict['tags'] as $tag) {
$tagConflictData .= sprintf('<span class="apply_css_arrow nowrap">%s</span></br>', h($tag));
}
}
$tagConflictData .= '</div></div></span>';
} }
echo $tagConflictData; echo $tagConflictData;
?> ?>

View File

@ -2397,6 +2397,12 @@ table tr:hover .down-expand-button {
.tag-conflict-notice { .tag-conflict-notice {
margin: 5px 0px; margin: 5px 0px;
padding-right: 14px;
position: relative;
}
.tag-conflict-notice div.text-container {
overflow: auto;
} }
.attributeTagContainer .tag-conflict-notice { .attributeTagContainer .tag-conflict-notice {
@ -2407,4 +2413,14 @@ table tr:hover .down-expand-button {
.tag-conflict-notice .apply_css_arrow { .tag-conflict-notice .apply_css_arrow {
display: inline-block; display: inline-block;
padding: 0px 6px; padding: 0px 6px;
}
.tag-conflict-notice i.icon {
position: absolute;
padding: 3px;
right: 0px;
top: 0px;
background-color: #3b3b3b;
color: white;
border-radius: 3px;
} }