Populates the catalog with all Items.
@param int $deep If 0 all items are retrieved, else if great of 0, then retrieves only the first $deep levels.
436372
public function populate(int $deep = 0)
    {
        $nb_catalog = $this->getCatalog();
        $this->clear();
        $this->merge(CNabuCatalogItem::getItemsForCatalog($nb_catalog, $deep));
        $translations = CNabuCatalogItem::getItemTranslationsForCatalog($nb_catalog, $deep);
        $translations->iterate(
            function ($key, $translation)
            {
                $item = $this->getItem($translation->getCatalogItemId());
                if ($item instanceof INabuTranslated) {
                    $item->setTranslation($translation);
                }
                return true;
            }
        );
    }
201520
public function setCatalogs(array $catalogs) {
		$cache = $this->getCacheFrontend();
		
		if (count($catalogs) === 1) {
			reset($catalogs);
			
			return $cache->set(key($catalogs), current($catalogs), $this->lifetime);
		}
		
		return $cache->setMany($catalogs, $this->lifetime);
	}
1184045
public function populate(int $deep = 0)
    {
        $nb_site = $this->getSite();
        $this->merge(CNabuSiteMap::getMapsForSite($nb_site));
        $translations = CNabuSiteMapLanguage::getMapTranslationsForSite($nb_site);
        if (is_array($translations) && count($translations) > 0) {
            foreach ($translations as $translation) {
                $item = $this->getItem($translation->getSiteMapId());
                $item->setTranslation($translation);
            }
        }
        $roles = CNabuSiteMapRole::getMapRolesForSite($nb_site);
        if (is_array($roles) && count($roles) > 0) {
            foreach ($roles as $role) {
                $item = $this->getItem($role->getSiteMapId());
                $item->addRole($role);
            }
        }
    }
678415
public static function reset(array $array, $deep = false)
    {
        $target = [];

        foreach ($array as $key => $value) {
            if ($deep && is_array($value)) {
                $value = static::reset($value);
            }

            if (is_numeric($key)) {
                $target[] = $value;
            } else {
                $target[$key] = $value;
            }
        }

        return $target;
    }
657191
public function getTree($groups = [], $deep = 0)
    {
        $deep = (int) $deep;
        $deep--;

        /** @var $group Group */
        foreach ($this as $group) {
            $groups[] = $group;
            // 参数为0时,当前为-1,则一直获取下去
            if ($deep) {
                $groups = $group->getChildren()->findAll()->getTree($groups, $deep);
            }
        }

        return $groups;
    }
207512
public function CategoryMenu($level = 1)
    {
        if ($level == 1) {
            $result = CatalogueCategory::get()->filter(array(
                "ParentID" => 0
            ));
        } else {
            $parent = $this->data();
            $stack = array($parent);

            if ($parent) {
                while ($parent = $parent->Parent) {
                    array_unshift($stack, $parent);
                }
            }

            if (isset($stack[$level-2])) {
                $result = $stack[$level-2]->Children();
            }
        }

        $visible = array();

        if (isset($result)) {
            foreach ($result as $item) {
                if ($item->canView()) {
                    $visible[] = $item;
                }
            }
        }

        return new ArrayList($visible);
    }
52732
protected function loadRelatedEntities($entities, $depth)
    {
        if (0 <= $depth) {
            return;
        }
        $relatedEntities = [];
        foreach ($entities as $entity) {
            if (null === $entity) {
                continue;
            }
            $family = $entity->getFamily();
            foreach ($family->getAttributes() as $attribute) {
                $this->appendRelatedEntities($relatedEntities, $attribute, $entity);
            }
        }

        $this->load($relatedEntities, $depth - 1);
    }
530155
private function searchTree(int $depth = 0)
    {
        $this->depth = $depth;
        foreach ($this->children->getList() as $node) {
            if ($depth > count($this->treePath)) {
                break;
            }

            if ($this->treePath[$depth] != $node->key) {
                continue;
            }

            /**
             * @var $node TreeNode
             */
            if (count($this->treePath) > $depth && $this->allowedToDiveDeeper($depth)) {
                $node->setTreePath($this->treePath);

                return $node->searchTree(++$depth);
            }
        }

        return $this;
    }
978146
public function setNestingLevel($level = null)
	{
		if (func_num_args() and is_numeric($level) and $level > 0)
		{
			$this->maxNestingLevel = $level;
		}

		return $this->maxNestingLevel;
	}
1115986
public function setLevel($level)
    {
        parent::setLevel($level);

        foreach ($this->items as $item) {
            $item->setLevel($level + 1);
        }
    }
1112691
public function get($key, $default = null, $deep = false)
    {
        if (is_array($key)) {
            $request = [];
            foreach ($key as $k) {
                $_default = is_array($default) && isset($default[$k]) ? $default[$k] : null;
                $request[$k] = parent::get($k, $_default);
            }
        }
        else {
            $request = parent::get($key, $default);
        }

        return $request;
    }
772451
protected function fillItems()
    {
        $migrations = [];
        foreach (Directory::iterator($this->folder) as $file) {
            $class = $this->namespace . '\\' . Str::cut($file->getFilename(), '.php');
            $model = Model::fromClass($class);
            if ($this->mustBeFiltered($model)) {
                continue;
            }
            $migrations[] = $model;
        }

        $migrations = $this->sort($migrations);

        $this->items = $this->onlyOne
            ? count($migrations) ? [$migrations[0]] : []
            : ($this->last === null
                ? $migrations
                : Arr::last($migrations, $this->last)
            );
    }
1346449
protected function allowedToDiveDeeper(int $depth) : bool
    {
        if ($this->maxDepth == 0) {
            return true;
        }

        return $this->maxDepth >= $depth;
    }
534266
public final function populateObjectList($input, $deep = true)
	{
		if($this instanceof ArrayAccess == false)
			throw new Exception("Cannot set properties on objects that are not children of 'ArrayAccess'");
		
		if(!is_array($input))
		{
			if($input instanceof Traversable && method_exists($input, "toArray"))
				$input = $input->toArray();
			elseif($input instanceof Traversable)
				$input = iterator_to_array($input);
			else
				$input = [];
		}
		
		if($deep)
		{
			foreach($input as $key => $value)
			{
				if(is_null($value) || is_scalar($value))
					$this[$key] = $value;
				else
					$this[$key] = (new static())->populateObjectList($value, $deep);
			}
		}
		else
		{
			foreach($input as $key => $value)
			{
				# if we're not in deep mode then all we're doing is going through
				# each of the items and tacking them onto the stack, or something
				$this[$key] = $value;
			}
		}
		
		return $this;
	}
1132442
public function toArray($ignore = array('_type'), $recursive = false, $deep = 3)
    {
        if (!empty($ignore)) {
            $ignores = array();
            foreach ($ignore as $val) {
                $ignores[$val] = 1;
            }
            $ignore = $ignores;
        }
        if ($recursive === true && $deep > 0) {
            $attrs = $this->getAttrs();
            foreach ($this->cleanData as $key => $value) {
                if (isset($attrs[$key])
                    && isset($attrs[$key]['type'])
                    && ( $attrs[$key]['type'] == self::DATA_TYPE_REFERENCE || $attrs[$key]['type'] == self::DATA_TYPE_REFERENCES )
                ) {
                    if ($attrs[$key]['type'] == self::DATA_TYPE_REFERENCE &&
                        isset($attrs[$key]['model']) && !empty($attrs[$key]['model'])) {
                        $model = $attrs[$key]['model'];
                        if (!is_array($value)) {
                            $value = (array)$value;
                        }
                        $obj = $model::id($value['$id']);
                        if ($obj) {
                            $this->cleanData[$key] = $obj->toArray($ignore, $recursive, --$deep);
                        }
                    } else if ($attrs[$key]['type'] == self::DATA_TYPE_REFERENCES &&
                        isset($attrs[$key]['model']) && !empty($attrs[$key]['model'])) {
                        $model = $attrs[$key]['model'];
                        $data = array();
                        foreach($value as $item) {
                            if (!is_array($item)) {
                                $item = (array)$item;
                            }
                            $obj = $model::id($item['$id']);
                            if ($obj) {
                               $data[]  = $obj->toArray($ignore, $recursive, --$deep);
                            }
                        }
                        if (!empty($data))
                            $this->cleanData[$key] = $data;
                    }
                }
            }
        }
        return array_diff_key($this->cleanData, $ignore);
    }
1167148
private static function arrayFlatten($array, $depth = INF)
    {
        return array_reduce($array, function ($result, $item) use ($depth) {
            if ($item instanceof CollectionContract) {
                $item = $item->all();
            }
            if (!is_array($item)) {
                return array_merge($result, [$item]);
            }
            else if ($depth === 1) {
                return array_merge($result, array_values($item));
            }
            else {
                return array_merge($result, static::arrayFlatten($item, $depth - 1));
            }
        }, []);
    }
903970
public function get($category, $key = null, $default = null)
    {
        $this->load($category);

        if ($key === null) {
            return isset($this->items[$category]) && !empty($this->items[$category]) ? $this->items[$category] : $default;
        }

        if (is_string($key)) {
            return isset($this->items[$category][$key]) ? $this->items[$category][$key] : $default;
        }

        if (is_array($key)) {
            $result = [];
            foreach ($key as $val) {
                $result[$val] = isset($this->items[$category][$val]) ? $this->items[$category][$val] : (is_array($default) && isset($default[$val]) ? $default[$val] : null);
            }
            return $result;
        }

        return $default;
    }