Создаёт список разделов типа "Галерея изображений" для использования в шаблонах

@param int $root             Идентификатор корневого раздела
@param int $level[optional]  Уровень вложенности ветки

@return array  Описания разделов
351430
private function buildGalleryList($root, $level = 0)
    {
        $lib = Eresus_Kernel::app()->getLegacyKernel()->sections;

        $sections = $lib->children($root);

        // Описания разделов выбранной ветки
        $branch = array();

        /*
         * Отбираем только разделы типа "Галерея изображений" или разделы,
         * содержащие дочерние разделы этого же типа.
         */
        foreach ($sections as $section)
        {
            $item = array(
                'id' => $section['id'],
                'selectable' => false,
                'caption' => $section['caption'],
                'level' => $level
            );

            if ($section['type'] == $this->getName())
            {
                $item['selectable'] = true;
            }

            $subItems = $this->buildGalleryList($section['id'], $level + 1);

            if ($item['selectable'] || $subItems)
            {
                $branch []= $item;
            }

            $branch = array_merge($branch, $subItems);
        }

        return $branch;
    }
974011
public function setIsolationLevel(string $level) : array
    {
        if (!\in_array($level, static::ISOLATION_LEVELS, true)) {
            throw new InvalidIsolationLevelException();
        }

        static $oldIsolationLevel;
        if (!$oldIsolationLevel) {
            $oldIsolationLevel = $this->query('SHOW transaction_isolation')[0]['transaction_isolation'];
        }

        $this->query("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL $level");
        $oldIsolationLevel = $level;

        return [$oldIsolationLevel, $level];
    }
273927
public function getPublicRoots()
    {
        $roots = [];
        foreach ($this->filesystems->keys() as $ident) {
            if ($this->isFilesystemPublic($ident)) {
                $disk = $this->getNamedRoot($ident);
                if ($disk !== null) {
                    $roots[$ident] = $disk;
                }
            }
        }

        return $roots;
    }
519856
public function getDescendants($depth = null)
    {
        if(!$this->hasChildren())
        {
            return array();
        }

        if($this->descendants === null)
        {
            $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder();
            $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias();

            $qb->andWhere("$alias.".$this->getLeftFieldName()." > :lft1")
                ->setParameter('lft1', $this->getLeftValue())
                ->andWhere("$alias.".$this->getRightFieldName()." < :rgt1")
                ->setParameter('rgt1', $this->getRightValue())
                ->orderBy("$alias.".$this->getLeftFieldName(), "ASC");
            if($this->hasManyRoots())
            {
                $qb->andWhere("$alias.".$this->getRootFieldName()." = :root")
                    ->setParameter('root', $this->getRootValue());
            }

            // TODO: Add depth support or self join support?
			$q = $qb->getQuery();
			if ($this->getManager()->getConfiguration()->isQueryHintSet()){
				$q = $this->getManager()->addHintToQuery($q);
			}
            $results = $q->getResult();

            $this->descendants = array();
            foreach($results as $result)
            {
                $this->descendants[] = $this->getManager()->wrapNode($result);
            }
        }

        if($depth !== null)
        {
            // TODO: Don't rebuild filtered array everytime?
            return $this->getManager()->filterNodeDepth($this->descendants, $depth);
        }

        return $this->descendants;
    }
296408
protected function _processPlugins($root, array $plugins = [])
    {
        foreach ($plugins as $plugin) {
            $controllers = $this->getControllerList($plugin);
            $pluginAlias = $this->_pluginAlias($plugin);
            $path = [
                $this->rootNode,
                $pluginAlias
            ];
            $path = implode('/', Hash::filter($path));
            
            if(!in_array($path, $this->ignorePaths) && !in_array($path, $this->ignoreActions)) {
                
                $pathNode = $this->_checkNode($path, $pluginAlias, $root->id);
                $this->foundACOs[$root->id][] = $pluginAlias;
                
                if (isset($this->foundACOs[$pathNode->id])) {
                    $this->foundACOs[$pathNode->id] += $this->_updateControllers($pathNode, $controllers, $plugin);
                } else {
                    $this->foundACOs[$pathNode->id] = $this->_updateControllers($pathNode, $controllers, $plugin);
                }

                if (isset($this->pluginPrefixes[$plugin])) {
                    foreach (array_keys($this->pluginPrefixes[$plugin]) as $prefix) {
                        $path = [
                            $this->rootNode,
                            $pluginAlias
                        ];
                        $path = implode('/', Hash::filter($path));
                        $pluginNode = $this->_checkNode($path, $pluginAlias, $root->id);
                        $this->foundACOs[$root->id][] = $pluginAlias;

                        $path = [
                            $this->rootNode,
                            $pluginAlias,
                            $prefix,
                        ];
                        $path = implode('/', Hash::filter($path));
                        $pathNode = $this->_checkNode($path, $prefix, $pluginNode->id);
                        $this->foundACOs[$pluginNode->id][] = $prefix;

                        $controllers = $this->getControllerList($plugin, $prefix);
                        if (isset($this->foundACOs[$pathNode->id])) {
                            $this->foundACOs[$pathNode->id] += $this->_updateControllers($pathNode, $controllers, $pluginAlias, $prefix);
                        } else {
                            $this->foundACOs[$pathNode->id] = $this->_updateControllers($pathNode, $controllers, $pluginAlias, $prefix);
                        }
                    }
                }
            }
        }
    }
1244682
public function getSiteMenu($level = 1)
    {
        $site   = Multisites::inst()->getCurrentSite();
        $page   = $this->owner->data();
        $result = new ArrayList();

        if ($level == 1) {
            $pages = SiteTree::get()->filter(array(
                'ParentID' => $site ? $site->ID : 0,
                'ShowInMenus' => true
            ));
        } else {
            $parent = $page;
            $stack  = array($page);

            while (($parent = $parent->Parent()) && $parent->ID > 0 && !($parent instanceof Site)) {
                array_unshift($stack, $parent);
            }

            if (!isset($stack[$level - 2])) {
                return;
            }

            $pages = $stack[$level - 2]->Children();
        }

        foreach ($pages as $page) {
            if ($page->canView()) $result->push($page);
        }

        return $result;
    }
365104
public function serialize(Level $level, array $options = [])
    {
        $serialized = [
            'id' => $level->getUuid(),
            'name' => $level->getName(),
            'value' => $level->getValue(),
        ];

        return $serialized;
    }
1224279
private function getDocument($root = null)
    {
        return $this->document !== null ? $this->document : $this->document = $this->createDocument($root);
    }
713901
public function getSet($root)
    {
        $child = ucfirst(AnInflector::pluralize($this->getChild()->name));
        $parent = $this->getJunctionAlias().'.'.$this->_child_key;
        $filters = $this->getQueryFilters();
        $filters['where'] = array($parent => $root);
        $options = array(
            'repository' => $this->getTargetRepository(),
            'query' => $filters,
            'root' => $root,
            'property' => $this->getChildKey(),
            'target_property' => $this->getTargetChildKey(),
            'child' => $this->getChildRepository(),
        );

        $set = AnService::get('anahita:domain.entityset.decorator.manytomany', $options);

        return $set;
    }
488021
public function descendants($level = null)
	{
		$instance = self::blank();
		$instance->where('level', '>', $this->level)
		         ->order('lft', 'asc');

		if (isset($level))
		{
			$instance->where('level', '<=', $this->level + $level);
		}

		return $instance->where('lft', '>', $this->lft)
		                ->where('rgt', '<', $this->rgt)
		                ->applyScopesWhere($this);
	}
495357
public function findChildren(callable $callback, $depth = null, $level = null)
    {

        $level = $level ?: 0;

        foreach ($this->children as $child) {

            /** @var NodeInterface $child */
            if ($child->is($callback))
                yield $child;

            if ($depth === null || $level < $depth) {

                if ($child instanceof NodeInterface)
                    foreach ($child->findChildren($callback, $depth, $level + 1) as $subChild)
                        yield $subChild;
            }
        }
    }
643537
protected function toList(array $items = [], $level = 0)
    {
        $prefix = str_repeat('&nbsp;&nbsp;', $level);

        $pages = [];

        foreach ($items as $item) {
            $pages[$item['id']] = $prefix . '' . $item['title'];

            if ($item['children']) {
                $pages += $this->toList($item['children'], $level + 1);
            }
        }

        return $pages;
    }
530337
public static function getFilesArray($root)
	{
		$alias=array();
		$directories=array();
		$last_letter=$root[strlen($root)-1];
		$root= ($last_letter=='\\' || $last_letter=='/')? $root : $root.DIRECTORY_SEPARATOR;

		$directories[]=$root;

		while (sizeof($directories)) {
			$dir=array_pop($directories);
			if ($handle=opendir($dir)) {
				while (FALSE!==($file=readdir($handle))) {
					if ($file=='.' || $file=='..') {
						continue;
						}
					$file=$dir.$file;
					if (is_dir($file)) {
						$directory_path=$file.DIRECTORY_SEPARATOR;
						array_push($directories, $directory_path);
						}
					elseif (is_file($file)) {
						$key=basename($file);
						$alias[substr($key, 1, strpos($key, '.')-1)]=$file;
						}
					}
				closedir($handle);
				}
			}

		return $alias;
	}
428407
public static function toXml($resource, $root = 'root') {
		if (self::isXml($resource)) {
			return $resource;
		}

		$array = self::toArray($resource);

		if (!empty($array)) {
			$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><'. $root .'></'. $root .'>');
			$response = self::buildXml($xml, $array);

			return $response->asXML();
		}

		return $resource;
	}
153101
protected function build(XmlElement $root, $meta)
    {
        foreach ($meta as $key => $value) {
            // Used to create self-closing tags, attributes without value or merging array,
            // eq. ['dog' => ['@can_hau']] (equals ['dog' => [0 => '@can_hau']]).
            //                                      is_int ---^
            //
            // Merging array example:
            // ['dog' => ['@attr', ['@other']]] (equals ['dog' => ['@attr', '@other']]).
            if (is_int($key)) {
                $key = $value;
                $value = null;
            }

            $this->buildFor($root, $key, $value);
        }

        return $root;
    }
366336
protected static function enableToolbar($root)
    {
        if (!$root instanceof Toolbar) {
            $group = $root;
            $root  = static::createToolbar(array(), true);

            if ($group instanceof Group && $group->getChildren()) {
                $root->addChild($group);
            }
        }

        return $root;
    }
1043612
private function adminSectionBranch($owner = 0, $level = 0)
    {
        $result = array();
        $items = Eresus_CMS::getLegacyKernel()->sections->children($owner, GUEST, SECTIONS_ACTIVE);
        if (count($items))
        {
            foreach ($items as $item)
            {
                $result [] = array(
                    'caption' => str_repeat('- ', $level) . $item['caption'],
                    'id' => $item['id']
                );
                $sub = $this->adminSectionBranch($item['id'], $level + 1);
                if (count($sub))
                {
                    $result = array_merge($result, $sub);
                }
            }
        }
        return $result;
    }