Fix of tagged attributes search, displaying tag name instead of numeric Tag ID

Closes #3977
pull/4020/head
chkp-aliaksandrt 2019-01-16 14:58:27 +03:00
parent 9318d63156
commit 4ec95ee47d
No known key found for this signature in database
GPG Key ID: 4852847EE045873A
4 changed files with 20 additions and 4 deletions

View File

@ -1578,7 +1578,7 @@ class AttributesController extends AppController
$this->set('typeDefinitions', $this->Attribute->typeDefinitions);
$this->set('categoryDefinitions', $this->Attribute->categoryDefinitions);
$this->set('shortDist', $this->Attribute->shortDist);
if ($this->request->is('post') || !empty($this->params['named']['tags'])) {
if ($this->request->is('post') || !empty($this->request->params['named']['tags'])) {
if (isset($this->request->data['Attribute'])) {
$this->request->data = $this->request->data['Attribute'];
}
@ -1659,6 +1659,22 @@ class AttributesController extends AppController
} else {
return $this->RestResponse->viewData($attributes, $this->response->type());
}
if (isset($filters['tags']) && !empty($filters['tags'])) {
// if the tag is passed by ID - show its name in the view
$this->loadModel('Tag');
foreach ($filters['tags'] as $k => &$v) {
if (!is_numeric($v))
continue;
$tag = $this->Tag->find('first', [
'conditions' => ['Tag.id' => $v],
'fields' => ['name'],
'recursive' => -1
]);
if (!empty($tag)) {
$v = $tag['Tag']['name'];
}
}
}
$this->set('filters', $filters);
$this->set('attributes', $attributes);
$this->set('isSearch', 1);

View File

@ -20,7 +20,7 @@
<?php
else:
?>
<a href="<?php echo $baseurl;?>/attributes/search//tags:<?php echo h($tag['Tag']['id']); ?>" class="<?php echo $tagClass; ?>" style="display:inline-block; background-color:<?php echo h($tag['Tag']['colour']);?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']);?>"><?php echo h($tag['Tag']['name']); ?></a>
<a href="<?php echo $baseurl;?>/attributes/search/tags:<?php echo h($tag['Tag']['id']); ?>" class="<?php echo $tagClass; ?>" style="display:inline-block; background-color:<?php echo h($tag['Tag']['colour']);?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']);?>"><?php echo h($tag['Tag']['name']); ?></a>
<?php
endif;
if ($full):

View File

@ -111,7 +111,7 @@ foreach ($list as $k => $item): ?>
&nbsp;
</td>
<td class="shortish"><?php echo h($item['Tag']['count']); ?>&nbsp;</td>
<td class="shortish"><a href="<?php echo $baseurl . "/attributes/search/attributetag:" . $item['Tag']['id']; ?>"><?php echo h($item['Tag']['attribute_count']); ?></a> </td>
<td class="shortish"><a href="<?php echo $baseurl . "/attributes/search/tags:" . $item['Tag']['id']; ?>"><?php echo h($item['Tag']['attribute_count']); ?></a> </td>
<td class="shortish">
<?php echo $this->element('sparkline', array('id' => $item['Tag']['id'], 'csv' => isset($csv[$k]) ? $csv[$k] : $emptyDate)); ?>
</td>

View File

@ -103,7 +103,7 @@
<?php
if ($item['existing_tag']):
?>
<a href='<?php echo $baseurl."/attributes/search/attributetag:". h($item['existing_tag']['Tag']['id']);?>'><?php echo count($item['existing_tag']['AttributeTag']);?></a>
<a href='<?php echo $baseurl."/attributes/search/tags:". h($item['existing_tag']['Tag']['id']);?>'><?php echo count($item['existing_tag']['AttributeTag']);?></a>
<?php
else:
echo __('N/A');