new: [internal] Further work on the filtering

pull/3551/head
iglocska 2018-08-09 07:46:31 +02:00
parent 28e37cd781
commit 8d699d35a9
1 changed files with 50 additions and 35 deletions

View File

@ -2033,7 +2033,7 @@ class Attribute extends AppModel
return $rules; return $rules;
} }
public function set_filter_tags($params, $conditions, $scope = 'all') { public function set_filter_tags(&$params, $conditions, $scope = 'Event') {
if (empty($params['tags'])) { if (empty($params['tags'])) {
return $conditions; return $conditions;
} }
@ -2042,26 +2042,33 @@ class Attribute extends AppModel
$tagArray = $tag->fetchTagIds($args[0], $args[1]); $tagArray = $tag->fetchTagIds($args[0], $args[1]);
$temp = array(); $temp = array();
if (!empty($tagArray[0])) { if (!empty($tagArray[0])) {
if ($scope == 'all' || $scope == 'Event') {
$options = array(
'conditions' => array(
'tag_id' => $tagArray[0]
),
'fields' => array(
'event_id'
)
);
$temp = array_merge($temp, $this->subQueryGenerator($tag->EventTag, $options, 'Attribute.event_id'));
}
$options = array( $options = array(
'conditions' => array( 'conditions' => array(
'tag_id' => $tagArray[0] 'tag_id' => $tagArray[0]
), ),
'fields' => array( 'fields' => array(
'attribute_id' 'event_id'
) )
); );
$temp = array_merge($temp, $this->subQueryGenerator($tag->AttributeTag, $options, 'Attribute.id')); $lookup_field = ($scope === 'Event') ? 'Event.id' : 'Attribute.event_id';
$temp = array_merge(
$temp,
$this->subQueryGenerator($tag->EventTag, $options, $lookup_field)
);
$options = array(
'conditions' => array(
'tag_id' => $tagArray[0]
),
'fields' => array(
$scope === 'Event' ? 'Event.id' : 'attribute_id'
)
);
$lookup_field = $scope === 'Event' ? 'Event.id' : 'Attribute.id';
$temp = array_merge(
$temp,
$this->subQueryGenerator($tag->AttributeTag, $options, $lookup_field)
);
$conditions['AND'][] = array('OR' => $temp); $conditions['AND'][] = array('OR' => $temp);
} }
$temp = array(); $temp = array();
@ -2075,7 +2082,8 @@ class Attribute extends AppModel
'event_id' 'event_id'
) )
); );
$conditions['AND'][] = array_merge($temp, $this->subQueryGenerator($tag->EventTag, $options, 'Attribute.event_id', 1)); $lookup_field = ($scope === 'Event') ? 'Event.id' : 'Attribute.event_id';
$conditions['AND'][] = array_merge($temp, $this->subQueryGenerator($tag->EventTag, $options, $lookup_field, 1));
} }
if ($scope == 'all' || $scope == 'Attribute') { if ($scope == 'all' || $scope == 'Attribute') {
$options = array( $options = array(
@ -2083,12 +2091,18 @@ class Attribute extends AppModel
'tag_id' => $tagArray[1] 'tag_id' => $tagArray[1]
), ),
'fields' => array( 'fields' => array(
'attribute_id' $scope === 'Event' ? 'event.id' : 'attribute_id'
) )
); );
$conditions['AND'][] = array_merge($temp, $this->subQueryGenerator($tag->AttributeTag, $options, 'Attribute.id', 1)); $lookup_field = $scope === 'Event' ? 'Event.id' : 'Attribute.id';
$conditions['AND'][] = array_merge($temp, $this->subQueryGenerator($tag->AttributeTag, $options, $lookup_field, 1));
} }
} }
if (!empty($tagArray[1])) {
$params['tags'] = array('NOT' => $tagArray[1]);
} else {
unset($params['tags']);
}
return $conditions; return $conditions;
} }
@ -2394,25 +2408,26 @@ class Attribute extends AppModel
// array 1 will have all of the non negated terms and array 2 all the negated terms // array 1 will have all of the non negated terms and array 2 all the negated terms
public function dissectArgs($args) public function dissectArgs($args)
{ {
if (!$args) { if (!is_array($args)) {
return array(null, null); $args = explode('&&', $args);
} }
if (is_array($args)) { $result = array(0 => array(), 1 => array());
$argArray = $args; if (isset($args['OR']) || isset($args['NOT']) || isset($args['AND'])) {
if (!empty($args['OR'])) {
$result[0] = $args['OR'];
}
if (!empty($args['NOT'])) {
$result[1] = $args['NOT'];
}
} else { } else {
$argArray = explode('&&', $args); foreach ($args as $arg) {
} if (substr($arg, 0, 1) == '!') {
$accept = $reject = $result = array(); $result[1][] = substr($arg, 1);
$reject = array(); } else {
foreach ($argArray as $arg) { $result[0][] = $arg;
if (substr($arg, 0, 1) == '!') { }
$reject[] = substr($arg, 1);
} else {
$accept[] = $arg;
} }
} }
$result[0] = $accept;
$result[1] = $reject;
return $result; return $result;
} }
@ -3089,11 +3104,11 @@ class Attribute extends AppModel
if (is_array($timestamp)) { if (is_array($timestamp)) {
$timestamp[0] = $this->Event->resolveTimeDelta($timestamp[0]); $timestamp[0] = $this->Event->resolveTimeDelta($timestamp[0]);
$timestamp[1] = $this->Event->resolveTimeDelta($timestamp[1]); $timestamp[1] = $this->Event->resolveTimeDelta($timestamp[1]);
$conditions['AND'][] = array($scope . ' >=' => $timestamp[0]); $conditions['AND'][] = array($scope . ' >=' => intval($timestamp[0]));
$conditions['AND'][] = array($scope . ' <=' => $timestamp[1]); $conditions['AND'][] = array($scope . ' <=' => intval($timestamp[1]));
} else { } else {
$timestamp = $this->Event->resolveTimeDelta($timestamp); $timestamp = $this->Event->resolveTimeDelta($timestamp);
$conditions['AND'][] = array($scope . ' >=' => $timestamp); $conditions['AND'][] = array($scope . ' >=' => intval($timestamp));
} }
return $conditions; return $conditions;
} }