mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +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
|
||||
*/
|
||||
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();
|
||||
$_filtered = array_flip($filtered);
|
||||
|
||||
foreach ($results as &$result) {
|
||||
if (is_array($result)) {
|
||||
if (!isset($keys)) {
|
||||
$keys = array_keys($result);
|
||||
}
|
||||
foreach ($keys as $className) {
|
||||
if ($model->alias !== $className && !isset($_filtered[$className])) {
|
||||
$filtering[] = $className;
|
||||
|
||||
if (isset($model->{$className}) && is_object($model->{$className})) {
|
||||
$data = $model->{$className}->afterFind(array(array($className => $result[$className])), false);
|
||||
}
|
||||
if (isset($data[0][$className])) {
|
||||
$result[$className] = $data[0][$className];
|
||||
}
|
||||
}
|
||||
foreach ($keys as $className) {
|
||||
if (!isset($model->{$className}) || !is_object($model->{$className})) {
|
||||
continue;
|
||||
}
|
||||
$linkedModel = $model->{$className};
|
||||
$linkedClass = get_class($linkedModel);
|
||||
if (!isset($haveCallback[$linkedClass])) {
|
||||
$ref = new ReflectionClass($linkedModel);
|
||||
$haveCallback[$linkedClass] = $ref->getMethod('afterFind')->class !== 'Model';
|
||||
}
|
||||
if ($haveCallback[$linkedClass] !== true) {
|
||||
continue;
|
||||
}
|
||||
$filtering[] = $className;
|
||||
foreach ($results as &$result) {
|
||||
$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