From a2d92442b6b8faf742efaa6ba0ba5cbb8e5dbb87 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 10 Jun 2020 22:47:10 +0200 Subject: [PATCH] re-add populateIterable, apperently it is used :( --- DataStorage/Database/DataMapperAbstract.php | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 461763a32..78240b727 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1819,6 +1819,73 @@ class DataMapperAbstract implements DataMapperInterface * Create the delete functionality for arrays (deleteArray, deleteArrayModel). */ + /** + * Populate data. + * + * @param array $result Result set + * @param int $depth Relation depth + * + * @return array + * + * @since 1.0.0 + */ + public static function populateIterable(array $result, int $depth = 3) : array + { + $obj = []; + + foreach ($result as $element) { + if (isset($element[static::$primaryField . '_' . $depth]) && self::isInitialized(static::class, $element[static::$primaryField . '_' . $depth], $depth)) { + $obj[$element[static::$primaryField . '_' . $depth]] = self::$initObjects[static::class][$element[static::$primaryField . '_' . $depth]['obj']]; + + continue; + } + + $toFill = self::createBaseModel(); + + if (isset($element[static::$primaryField . '_' . $depth])) { + $obj[$element[static::$primaryField . '_' . $depth]] = self::populateAbstract($element, $toFill, $depth); + self::addInitialized(static::class, $element[static::$primaryField . '_' . $depth], $obj[$element[static::$primaryField . '_' . $depth]], $depth); + } else { + throw new \Exception(); + } + } + + return $obj; + } + + /** + * Populate data. + * + * @param array $result Result set + * @param int $depth Relation depth + * + * @return array + * + * @since 1.0.0 + */ + public static function populateIterableArray(array $result, int $depth = 3) : array + { + $obj = []; + + foreach ($result as $element) { + if (isset($element[static::$primaryField]) && self::isInitializedArray(static::class, $element[static::$primaryField], $depth)) { + $obj[$element[static::$primaryField]] = self::$initArrays[static::class][$element[static::$primaryField]]['obj']; + + continue; + } + + if (isset($element[static::$primaryField])) { + $obj[$element[static::$primaryField]] = self::populateAbstractArray($element, [], $depth); + self::addInitializedArray(static::class, $element[static::$primaryField], $obj[$element[static::$primaryField]], $depth); + } else { + throw new \Exception(); + } + } + + return $obj; + } + + /** * Populate data. *