fix: [event index] search via attribute key allows for empty input now

pull/6596/head
iglocska 2020-11-16 16:17:47 +01:00
parent 5a29fcc370
commit 459144011e
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 41 additions and 39 deletions

View File

@ -109,53 +109,55 @@ class EventsController extends AppController
*/ */
private function __filterOnAttributeValue($value) private function __filterOnAttributeValue($value)
{ {
if (!is_array($value)) {
$pieces = explode('|', strtolower($value));
} else {
$pieces = $value;
}
// dissect the value // dissect the value
$include = array(); $include = array();
$exclude = array(); $exclude = array();
$includeIDs = [];
foreach ($pieces as $piece) { $excludeIDs = [];
if ($piece[0] === '!') { if (!empty($value)) {
$exclude[] = '%' . substr($piece, 1) . '%'; if (!is_array($value)) {
$pieces = explode('|', strtolower($value));
} else { } else {
$include[] = "%$piece%"; $pieces = $value;
}
}
$includeIDs = array();
if (!empty($include)) {
$includeConditions = [];
foreach ($include as $i) {
$includeConditions['OR'][] = array('lower(Attribute.value1) LIKE' => $i);
$includeConditions['OR'][] = array('lower(Attribute.value2) LIKE' => $i);
} }
$includeIDs = array_values($this->Event->Attribute->fetchAttributes($this->Auth->user(), array( foreach ($pieces as $piece) {
'conditions' => $includeConditions, if ($piece[0] === '!') {
'flatten' => true, $exclude[] = '%' . substr($piece, 1) . '%';
'event_ids' => true, } else {
'list' => true, $include[] = "%$piece%";
))); }
}
$excludeIDs = array();
if (!empty($exclude)) {
$excludeConditions = [];
foreach ($exclude as $e) {
$excludeConditions['OR'][] = array('lower(Attribute.value1) LIKE' => $e);
$excludeConditions['OR'][] = array('lower(Attribute.value2) LIKE' => $e);
} }
$excludeIDs = array_values($this->Event->Attribute->fetchAttributes($this->Auth->user(), array( if (!empty($include)) {
'conditions' => $excludeConditions, $includeConditions = [];
'flatten' => true, foreach ($include as $i) {
'event_ids' => true, $includeConditions['OR'][] = array('lower(Attribute.value1) LIKE' => $i);
'list' => true, $includeConditions['OR'][] = array('lower(Attribute.value2) LIKE' => $i);
))); }
$includeIDs = array_values($this->Event->Attribute->fetchAttributes($this->Auth->user(), array(
'conditions' => $includeConditions,
'flatten' => true,
'event_ids' => true,
'list' => true,
)));
}
if (!empty($exclude)) {
$excludeConditions = [];
foreach ($exclude as $e) {
$excludeConditions['OR'][] = array('lower(Attribute.value1) LIKE' => $e);
$excludeConditions['OR'][] = array('lower(Attribute.value2) LIKE' => $e);
}
$excludeIDs = array_values($this->Event->Attribute->fetchAttributes($this->Auth->user(), array(
'conditions' => $excludeConditions,
'flatten' => true,
'event_ids' => true,
'list' => true,
)));
}
} }
// return -1 as the only value in includedIDs if both arrays are empty. This will mean that no events will be shown if there was no hit // return -1 as the only value in includedIDs if both arrays are empty. This will mean that no events will be shown if there was no hit
if (empty($includeIDs) && empty($excludeIDs)) { if (empty($includeIDs) && empty($excludeIDs)) {