new: add param to get exact matches on attribute values

pull/9050/head
Luciano Righetti 2023-05-02 09:49:48 +02:00
parent 1f4e2af37a
commit bb9e406f85
2 changed files with 34 additions and 1 deletions

View File

@ -73,6 +73,9 @@ class AttributesController extends AppController
{
$user = $this->Auth->user();
$this->paginate['conditions']['AND'][] = $this->Attribute->buildConditions($user);
$this->__setIndexFilterConditions();
$attributes = $this->paginate();
if ($this->_isRest()) {
@ -3017,4 +3020,15 @@ class AttributesController extends AppController
$sg = $this->Attribute->Event->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'name', true, $sharingGroupId);
return !empty($sg);
}
private function __setIndexFilterConditions() {
// search by attribute value
if ($this->params['named']['searchvalue']) {
$v = $this->params['named']['searchvalue'];
$this->paginate['conditions']['AND']['OR'] = [
['Attribute.value1' => $v],
['Attribute.value2' => $v],
];
}
}
}

View File

@ -669,6 +669,25 @@ class EventsController extends AppController
[$eventReportQuery]
]
];
break;
case 'value':
if ($v == "") {
continue 2;
}
$conditions['OR'] = [
['Attribute.value1' => $v],
['Attribute.value2' => $v],
];
$eventIds = $this->Event->Attribute->fetchAttributes($this->Auth->user(), array(
'conditions' => $conditions,
'flatten' => true,
'event_ids' => true,
'list' => true,
));
$this->paginate['conditions']['AND'][] = array('Event.id' => $eventIds);
break;
default:
continue 2;
@ -682,7 +701,7 @@ class EventsController extends AppController
{
// list the events
$urlparams = "";
$overrideAbleParams = array('all', 'attribute', 'published', 'eventid', 'datefrom', 'dateuntil', 'org', 'eventinfo', 'tag', 'tags', 'distribution', 'sharinggroup', 'analysis', 'threatlevel', 'email', 'hasproposal', 'timestamp', 'publishtimestamp', 'publish_timestamp', 'minimal');
$overrideAbleParams = array('all', 'attribute', 'published', 'eventid', 'datefrom', 'dateuntil', 'org', 'eventinfo', 'tag', 'tags', 'distribution', 'sharinggroup', 'analysis', 'threatlevel', 'email', 'hasproposal', 'timestamp', 'publishtimestamp', 'publish_timestamp', 'minimal', 'value');
$paginationParams = array('limit', 'page', 'sort', 'direction', 'order');
$passedArgs = $this->passedArgs;
if (!empty($this->request->data)) {