mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Refactored the filterResults again. Now this method not call the callback afterFind when model is Model.
This commit is contained in:
parent
34b4ff9204
commit
63d700a9d6
1 changed files with 26 additions and 19 deletions
|
@ -1128,29 +1128,36 @@ class DboSource extends DataSource {
|
||||||
* @return array Array of results that have been filtered through $model->afterFind
|
* @return array Array of results that have been filtered through $model->afterFind
|
||||||
*/
|
*/
|
||||||
protected function _filterResults(&$results, Model $model, $filtered = array()) {
|
protected function _filterResults(&$results, Model $model, $filtered = array()) {
|
||||||
|
static $haveCallback = array();
|
||||||
|
|
||||||
|
$current = current($results);
|
||||||
|
if (!is_array($current)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$keys = array_diff(array_keys($current), $filtered, array($model->alias));
|
||||||
$filtering = array();
|
$filtering = array();
|
||||||
$_filtered = array_flip($filtered);
|
foreach ($keys as $className) {
|
||||||
|
if (!isset($model->{$className}) || !is_object($model->{$className})) {
|
||||||
foreach ($results as &$result) {
|
continue;
|
||||||
if (is_array($result)) {
|
}
|
||||||
if (!isset($keys)) {
|
$linkedModel = $model->{$className};
|
||||||
$keys = array_keys($result);
|
$linkedClass = get_class($linkedModel);
|
||||||
}
|
if (!isset($haveCallback[$linkedClass])) {
|
||||||
foreach ($keys as $className) {
|
$ref = new ReflectionClass($linkedModel);
|
||||||
if ($model->alias !== $className && !isset($_filtered[$className])) {
|
$haveCallback[$linkedClass] = $ref->getMethod('afterFind')->class !== 'Model';
|
||||||
$filtering[] = $className;
|
}
|
||||||
|
if ($haveCallback[$linkedClass] !== true) {
|
||||||
if (isset($model->{$className}) && is_object($model->{$className})) {
|
continue;
|
||||||
$data = $model->{$className}->afterFind(array(array($className => $result[$className])), false);
|
}
|
||||||
}
|
$filtering[] = $className;
|
||||||
if (isset($data[0][$className])) {
|
foreach ($results as &$result) {
|
||||||
$result[$className] = $data[0][$className];
|
$data = $linkedModel->afterFind(array(array($className => $result[$className])), false);
|
||||||
}
|
if (isset($data[0][$className])) {
|
||||||
}
|
$result[$className] = $data[0][$className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_unique($filtering);
|
return $filtering;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue