Regard duplicate Id attributes that come as a list, transform into
single result.

@param array $list
@param string|null $parentKey
@return mixed
162681
public function doHydrateList(array $list, $parentKey = null)
    {
        $retVal = parent::doHydrateList($list, $parentKey);

        if('Id' === $parentKey)
        {
            if($retVal->count() > 0)
            {
                return $retVal->get(0);
            }
            return null;
        }
        return $retVal;
    }
611973
protected function prefixParentKeys($key, array $parent): string
    {
        return !empty($parent) ?
            $this->flattenKeys($parent).".$key" : $key;
    }
474387
public static function parentList() {
		if(!static::$arrParentsLoaded) {
			$parents = \Database::getInstance()->prepare("SELECT * FROM tl_member ORDER BY lastname, username")->execute();
			while ($parent = $parents->fetchAssoc()) {
				if($parent['groups'] && in_array(static::getGroupIdFor('parents'),unserialize($parent['groups'])))
					static::$arrParents[$parent['id']] = $parent['username'];
			}
			static::$arrParentsLoaded = true;
		}
		return static::$arrParents;
	}
827800
protected function listQueryParams(array $list)
    {
        $result = [];
        $params = $this->getRequest()->getQueryParams();
        
        foreach ($list as $key => $value) {
            if (is_int($key)) {
                $key = $value;
                $value = null;
            }
            
            $result[] = isset($params[$key]) ? $params[$key] : $value;
        }
        
        return $result;
    }
1363802
protected function getKeysFromResults(array $results, $key = null)
    {
        if (is_null($key)) {
            $key = $this->parentMap->getKeyName();
        }

        return array_unique(array_values(array_map(function ($value) use ($key) {
            return $value[$key];
        }, $results)));
    }
1181483
public function orderInterfaceChildren($parentKey, $childrenInterface)
    {
        $melisAppConfig = $this->getServiceLocator()->get('MelisCoreConfig');
        $orderInterface = $melisAppConfig->getOrderInterfaceConfig($parentKey);

        if (empty($orderInterface)) {
            // No order defined, items are displayed directly like found in interface config
            // meaning order is made uppon config merge
            return $childrenInterface;
        } else {
            $resultOrdered = [];

            // We first reorder depending on order defined
            foreach ($orderInterface as $orderKey) {
                if (is_array($orderKey)) {
                    $resultOrdered = $orderInterface;
                    break;
                }
                if (!empty($childrenInterface[$orderKey])) {
                    $resultOrdered[$orderKey] = $childrenInterface[$orderKey];
                    unset($childrenInterface[$orderKey]);
                }
            }

            // We add items at the end that are in the config but not present in the custom order
            foreach ($childrenInterface as $keyInterface => $childinterface) {
                $resultOrdered[$keyInterface] = $childinterface;
            }

            return $resultOrdered;
        }

    }
644070
public static function &getNestedArrayValue(array &$array, array $parents, &$keyExists = false)
    {
        $ref = &$array;
        foreach ($parents as $parent) {
            if (is_array($ref) && array_key_exists($parent, $ref)) {
                $ref = &$ref[$parent];
            } else {
                $keyExists = false;
                $null = null;
                return $null;
            }
        }
        $keyExists = true;

        return $ref;
    }
1309540
static  function toTree($list,$parent_field = 'parent_id',$id_field='id',$children_field='children') {
        $map = self::groupBy($list);
        $data=[];
        foreach ($list as $item) {
            $item->text=$item->name;
            if(is_object($item)){
                if(!$item->$parent_field){
                    $item->$children_field=$map[$item->$id_field];
                    $data[]=$item;
                }
            }
        }
        return $data;
    }
1159568
protected function getRule(string $name, string $key, array $parent_names = []): array
    {
        if (isset($this->rules[$key])) {
            return $this->rules[$key];
        }
        if ($this->total_rules === 1 || !$parent_names) {
            return $this->rules['*']; // Done here.
        }
        foreach (array_map('strtolower', $parent_names) as $_parent_key) {
            if (isset($this->rules[$_parent_key])) {
                return $this->rules[$_parent_key];
            }
        } // unset($_parent_key); // Housekeeping.

        return $this->rules['*'];
    }
1024871
private function normalizeParameters($parameters, $parentKey = '')
    {
        if (empty($parameters)) {
            return '';
        }

        $normalized = array();
        foreach ($parameters as $key => $value) {
            if (empty($value)) {
                continue;
            }

            if ($parentKey !== '') {
                // Multidimensional array; using foo=bar&foo=baz rather than foo[bar]=baz&foo[baz]=bar
                $key = $parentKey;
            }

            if (is_array($value)) {
                $normalized[] = $this->normalizeParameters($value, $key);
            } else {
                $normalized[] = $this->encode($key) . '=' . $this->encode($value);
            }
        }

        $normalized = array_filter($normalized);
        sort($normalized, SORT_STRING);

        return implode('&', $normalized);
    }
145051
public function hash(array $list)
    {
        $ids = '';
        foreach ($list as $item) {
            $ids .= ':'.$item['id'];
        }
        return md5($ids);
    }
1096075
private function ensureParentAndKey($parent, $key)
    {
        if (!$this->parent)
        {
            $this->parent = $parent;
        }
        if (!$this->key)
        {
            $this->key = $key;
        }
        if ($this->parent != $parent)
        {
            throw new \Exception('Internal Error. Relation retrieved from two different Objects.');
        }
        if ($this->key != $key)
        {
            throw new \Exception('Internal Error. Relation retrieved from two different keys.');
        }
    }
280137
public static function cleanCache($id, $parentOld)
    {
        unset(static::$_children[$parentOld]);
        unset(static::$_nodes[$id]);
        unset(static::$_i18n[$id]);

        $node = static::node($id);
        if (!empty($node)) {
            unset(static::$_children[$node->parent_id]); // after update node can get new parent
        }
    }
752641
public static function get($parent, $key)
    {
        is_eloquent_object($parent, true);
        // if you think those 2 issets can be simplified into just one
        // you've probably never dealt with \SplObjectStorage
        $cache = static::getCache();
        if (
            isset($cache[$parent])
            && isset($cache[$parent][$key])
        ) {
            return $cache[$parent][$key];
        }
    }
219365
public static function fromList(array $list)
    {
        if (count($list) !== count($list, COUNT_RECURSIVE)) {
            throw new NodeException('List is not a one-dimensional array.');
        }

        array_walk($list, function (&$item) {
            $item = array($item);
        });
        return new self($list);
    }
1312420
final protected function parseData(array $data, $parentId = 0)
    {
        $result = array();

        foreach ($data as $subArray) {
            $nested = array();

            if (isset($subArray[$this->childrenKey])) {
                // Recursive call
                $nested = $this->parseData($subArray[$this->childrenKey], $subArray[RelationBuilder::TREE_PARAM_ID]);
            }

            $result[] = array(
                RelationBuilder::TREE_PARAM_ID => $subArray[RelationBuilder::TREE_PARAM_ID], 
                RelationBuilder::TREE_PARAM_PARENT_ID => $parentId
            );

            $result = array_merge($result, $nested);
        }

        return $result;
    }
419062
public function getByRef(array $ref, array $parentEntity = [])
    {
        $document = $parentEntity;
        if (strpos($ref['rootDocumentEntityType'], 'parent') === false) {
            if (empty($document['_id']) || $document['_id'] !== $ref['rootDocumentId']) {
                $document = $this->getById($ref['rootDocumentEntityType'], $ref['rootDocumentId']);
            }

            if (count($document) === 0) {
                throw new Exception('Invalid document reference (document cannot be found by Id)');
            }
        }

        $container = $document;
        foreach ($ref['path'] as $pathInDocument) {
            if (!array_key_exists($pathInDocument['field'], $container)) {
                throw new Exception('Could not find the path in document');
            }
            $container = $container[$pathInDocument['field']];
            if (empty($pathInDocument['objectId'])) {
                continue;
            }

            if (!is_array($container)) {
                throw new Exception('Invalid value for path in document');
            }
            $result = array_filter($container, function ($item) use ($pathInDocument) {
                return $item['_id'] === $pathInDocument['objectId'];
            });
            if (count($result) === 0) {
                throw new Exception('Empty result of reference');
            }
            $container = reset($result);
        }
        return $container;
    }