格式化菜单列表数据

@param array $list
@param integer $level

@return array
349357
private function _toFormatTree($list, $level = 0)
    {
        $formatTree = [];
        foreach ($list as $val) {
            $tmp_str = str_repeat($this->tabSize, $level);
            $tmp_str .= "└&nbsp;";
            
            $val['level'] = intval($level);
            $val[$this->showTitleField] = $level == 0 ? $val[$this->showTitleField] : $tmp_str . $val[$this->showTitleField];
            if (!array_key_exists('_child', $val)) {
                array_push($formatTree, $val);
            } else {
                $tmp_ary = $val['_child'];
                unset($val['_child']);
                array_push($formatTree, $val);
                $formatTree = array_merge($formatTree, $this->_toFormatTree($tmp_ary, $level + 1));
            }
        }
        
        return $formatTree;
    }
365104
public function serialize(Level $level, array $options = [])
    {
        $serialized = [
            'id' => $level->getUuid(),
            'name' => $level->getName(),
            'value' => $level->getValue(),
        ];

        return $serialized;
    }
579982
public static function listToTree($list, $pk = 'id', $pid = 'parent_id', $child = '_child', $root = 0): array
    {
        // 创建Tree
        $tree = [];
        if (is_array($list)) {
            // 创建基于主键的数组引用
            $refer = [];
            foreach ($list as $key => $data) {
                $refer[$data[$pk]] = &$list[$key];
            }
            foreach ($list as $key => $data) {
                // 判断是否存在parent
                $parentId = $data[$pid];
                if ($root == $parentId) {
                    $tree[] = &$list[$key];
                } else {
                    if (isset($refer[$parentId])) {
                        $parent = &$refer[$parentId];
                        $parent[$child][] = &$list[$key];
                    }
                }
            }
        }
        
        return $tree;
    }
4792
public function getPaths(\DOMElement $nodeList, $level = 0)
    {
        $output = $nodeList->getNodePath();

        foreach ($nodeList->childNodes as $childObject) {
            $output .= $childObject->getNodePath() . "\n";

            if ($childObject instanceof \DOMElement) {
                $output .= $this->getElement($childObject, $level + 1, true);
            }
        }
        return $output;
    }
420882
public static function getLevelCode(
        /*# string */ $level
    )/*# : int */ {
        if (is_string($level) &&
            isset(self::$levels[$level])) {
            return self::$levels[$level];
        }

        throw new Exception\InvalidArgumentException(
            Message::get(
                Message::INVALID_LOG_LEVEL,
                (string) $level
            ),
            Message::INVALID_LOG_LEVEL
        );
    }
780406
private static function arrayMergeRecursive($a, $b, $level = 0)
    {
        // merge arrays if both variables are arrays
        if (is_array($a) && is_array($b)) {
            // loop through each right array's entry and merge it into $a
            foreach ($b as $key => $value) {
                if (isset($a[$key])) {
                    if (is_int($key) && ! is_array($value)) {
                        $a[] = $value;
                    } else {
                        $a[$key] = self::arrayMergeRecursive($a[$key], $value, $level + 1);
                    }
                } else {
                    if ($key === 0) {
                        $a = array(
                            0 => self::arrayMergeRecursive($a, $value, $level + 1)
                        );
                    } else {
                        $a[$key] = $value;
                    }
                }
            }
        } else {
            // at least one of values is not an array
            $a = $b;
        }
        return $a;
    }
646650
private function prepareLogLevels(string $level)
    {
        $levels = [
            LogLevel::EMERGENCY,
            LogLevel::ALERT,
            LogLevel::CRITICAL,
            LogLevel::ERROR,
            LogLevel::WARNING,
            LogLevel::NOTICE,
            LogLevel::INFO,
            LogLevel::DEBUG,
        ];

        $key = array_search($level, $levels);

        if (null !== $key) {
            $this->levels = array_slice($levels, 0, $key + 1);
        }
    }
1110400
public function filterByLevel($level)
    {
        return $this->filter(function(LogEntry $entry) use ($level) {
            return $entry->isSameLevel($level);
        });
    }
455306
public function level($level = null)
    {
        if ($level !== null) {
            $this->_level = $level;
        }

        return $this->_level;
    }
1209903
private static function buildList(array $list, Structure $structure)
    {
        $insertTab = ($structure->getTab()) ? true : false;

        $result = '';
        foreach ($list as $value) {
            $result .= ($insertTab ? $structure->getTab() : '') . $structure->getIteratorCharacter() . ' ' . $value . PHP_EOL;
        }

        return $result;
    }
196991
public function getLogs($level = null)
	{
		// If no level was given, return all logs.
		if(is_null($level))
		{
			return $this->logs;
		}

		else
		{
			if(isset($this->logs[$level]))
			{
				return $this->logs[$level];
			}
		}

		// If the level doesn't exist, just return an empty array.
		//
		// @todo: check that the level exists, otherwise throw an exception. 
		return array();
	}
1369764
public function getList($list)
	{
		$filteredList = [];

		foreach (explode(',', $list) as $item)
		{
			if ($item != '')
			{
				$filteredList[] = $item;
			}
		}

		return $filteredList;
	}
731004
private function extract($record,$level) {
		extract($this->map);
		
		$out = $record[$model];
		
		foreach($relation as $modelName => $type ) {
			$key =  (in_array($type, array('hasOne','belongsTo')))? '_id' : '_ids';
			$key = strtolower($modelName).$key;
			$association = $record[$modelName];
			
			if (isset($association[0])){
				$out[$key] =  Hash::extract($association,'{n}.id');
			} else {
				if($association['id'] === null){
					continue;
				}
				$out[$key] = $association['id'];
			}
			
			$this->associationsMerege($modelName,$association);
			
		}

		$this->models[ Inflector::tableize($model)][] = $out;
	}
78458
public function log($level, $message, array $context = []) {
		if (!Logger::check($level)) {
			return;
		}
		//获取SeasLog的常量
		\SeasLog::log($this->getLevel($level), $message, $context, Logger::getName());
	}
1070215
public function getParentByLevel($level = 1)
    {
        if ($level === $this->getLvl()) {
            return $this;
        }

        if (!$this->getParent()) {
            return false;
        }

        if ($level === $this->getParent()->getLvl()) {
            return $this->getParent();
        }

        return $this->getParent()->getParentByLevel($level);
    }
993182
protected function createLine($level = 1) {
        //线条
        for ($i = 0; $i < 6; $i ++) {
            imageline(
                $this->image,
                mt_rand(0, $this->width),
                mt_rand(0, $this->height),
                mt_rand(0, $this->width),
                mt_rand(0, $this->height),
                $this->getColorWithRGB(mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156))
            );
        }
        //雪花
        for ($i = 0, $length = $level * 20; $i < $length; $i ++) {
            imagestring(
                $this->image,
                mt_rand(1, 5),
                mt_rand(0, $this->width),
                mt_rand(0, $this->height),
                '*',
                $this->getColorWithRGB(mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255))
            );
        }
    }
606653
public function Level($level)
    {
        $parent = $this;
        $stack = array($parent);
        while ($parent = $parent->Parent) {
            array_unshift($stack, $parent);
        }

        return isset($stack[$level-1]) ? $stack[$level-1] : null;
    }