mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1592 from kimegede/model-after-find-if-condition-remove
Reduce if condtion for finds
This commit is contained in:
commit
64cf40558f
1 changed files with 58 additions and 58 deletions
|
@ -2818,9 +2818,9 @@ class Model extends Object implements CakeEventListener {
|
|||
protected function _findAll($state, $query, $results = array()) {
|
||||
if ($state === 'before') {
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
return $results;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2836,12 +2836,12 @@ class Model extends Object implements CakeEventListener {
|
|||
if ($state === 'before') {
|
||||
$query['limit'] = 1;
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
if (empty($results[0])) {
|
||||
return array();
|
||||
}
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
if (empty($results[0])) {
|
||||
return array();
|
||||
}
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2877,17 +2877,17 @@ class Model extends Object implements CakeEventListener {
|
|||
));
|
||||
}
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
foreach (array(0, $this->alias) as $key) {
|
||||
if (isset($results[0][$key]['count'])) {
|
||||
if ($query['group']) {
|
||||
return count($results);
|
||||
}
|
||||
return intval($results[0][$key]['count']);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (array(0, $this->alias) as $key) {
|
||||
if (isset($results[0][$key]['count'])) {
|
||||
if ($query['group']) {
|
||||
return count($results);
|
||||
}
|
||||
return intval($results[0][$key]['count']);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2939,12 +2939,12 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
list($query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']) = $list;
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
if (empty($results)) {
|
||||
return array();
|
||||
}
|
||||
return Hash::combine($results, $query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']);
|
||||
}
|
||||
|
||||
if (empty($results)) {
|
||||
return array();
|
||||
}
|
||||
return Hash::combine($results, $query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2974,34 +2974,34 @@ class Model extends Object implements CakeEventListener {
|
|||
$query['field'] = $field;
|
||||
$query['value'] = $value;
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
extract($query);
|
||||
unset($query['conditions'][$field . ' <']);
|
||||
$return = array();
|
||||
if (isset($results[0])) {
|
||||
$prevVal = Hash::get($results[0], $field);
|
||||
$query['conditions'][$field . ' >='] = $prevVal;
|
||||
$query['conditions'][$field . ' !='] = $value;
|
||||
$query['limit'] = 2;
|
||||
} else {
|
||||
$return['prev'] = null;
|
||||
$query['conditions'][$field . ' >'] = $value;
|
||||
$query['limit'] = 1;
|
||||
}
|
||||
$query['order'] = $field . ' ASC';
|
||||
$neighbors = $this->find('all', $query);
|
||||
if (!array_key_exists('prev', $return)) {
|
||||
$return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
|
||||
}
|
||||
if (count($neighbors) === 2) {
|
||||
$return['next'] = $neighbors[1];
|
||||
} elseif (count($neighbors) === 1 && !$return['prev']) {
|
||||
$return['next'] = $neighbors[0];
|
||||
} else {
|
||||
$return['next'] = null;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
extract($query);
|
||||
unset($query['conditions'][$field . ' <']);
|
||||
$return = array();
|
||||
if (isset($results[0])) {
|
||||
$prevVal = Hash::get($results[0], $field);
|
||||
$query['conditions'][$field . ' >='] = $prevVal;
|
||||
$query['conditions'][$field . ' !='] = $value;
|
||||
$query['limit'] = 2;
|
||||
} else {
|
||||
$return['prev'] = null;
|
||||
$query['conditions'][$field . ' >'] = $value;
|
||||
$query['limit'] = 1;
|
||||
}
|
||||
$query['order'] = $field . ' ASC';
|
||||
$neighbors = $this->find('all', $query);
|
||||
if (!array_key_exists('prev', $return)) {
|
||||
$return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
|
||||
}
|
||||
if (count($neighbors) === 2) {
|
||||
$return['next'] = $neighbors[1];
|
||||
} elseif (count($neighbors) === 1 && !$return['prev']) {
|
||||
$return['next'] = $neighbors[0];
|
||||
} else {
|
||||
$return['next'] = null;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3016,16 +3016,16 @@ class Model extends Object implements CakeEventListener {
|
|||
protected function _findThreaded($state, $query, $results = array()) {
|
||||
if ($state === 'before') {
|
||||
return $query;
|
||||
} elseif ($state === 'after') {
|
||||
$parent = 'parent_id';
|
||||
if (isset($query['parent'])) {
|
||||
$parent = $query['parent'];
|
||||
}
|
||||
return Hash::nest($results, array(
|
||||
'idPath' => '{n}.' . $this->alias . '.' . $this->primaryKey,
|
||||
'parentPath' => '{n}.' . $this->alias . '.' . $parent
|
||||
));
|
||||
}
|
||||
|
||||
$parent = 'parent_id';
|
||||
if (isset($query['parent'])) {
|
||||
$parent = $query['parent'];
|
||||
}
|
||||
return Hash::nest($results, array(
|
||||
'idPath' => '{n}.' . $this->alias . '.' . $this->primaryKey,
|
||||
'parentPath' => '{n}.' . $this->alias . '.' . $parent
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue