public static function getLeafIds($id) { $ret = []; $current = Channel::findOne(['id' => $id]); if ($current['is_leaf']) { $ret[] = $id; return $ret; } $children = Channel::findAll(['parent_id' => $id]); if (count($children) > 0) { foreach ($children as $child) { $temp = Channel::getLeafIds($child['id']); $ret = array_merge($ret, $temp); } } return $ret; }
public static function createChannelCache() { self::createCacheFile(); $content = '<?php' . self::$newLine; $dataList = Channel::_getChannelArrayTree(0, 0); foreach ($dataList as $row) { $id = $row['id']; $parentIds = Channel::getParentIds($id); $childrenIds = Channel::getChildrenIds($id); $leafIds = Channel::getLeafIds($id); $content .= '$cachedChannels[\'' . $row['id'] . '\']=[' . self::$newLine; $content .= self::getCacheItem('id', $row, 'int'); $content .= self::getCacheItem('parent_id', $row, 'int'); $content .= self::getCacheItemValue('parent_ids', implode(',', $parentIds)); $content .= self::getCacheItemValue('child_ids', implode(',', $childrenIds)); $content .= self::getCacheItemValue('leaf_ids', implode(',', $leafIds)); $content .= self::getCacheItem('name', $row); $content .= self::getCacheItem('name_alias', $row); $content .= self::getCacheItem('name_url', $row); $content .= self::getCacheItem('redirect_url', $row); $content .= self::getCacheItem('level', $row, 'int'); $content .= self::getCacheItem('is_leaf', $row, 'bool'); $content .= self::getCacheItem('is_nav', $row, 'bool'); $content .= self::getCacheItem('sort_num', $row, 'int'); $content .= self::getCacheItem('table', $row); $content .= self::getCacheItem('channel_tpl', $row); $content .= self::getCacheItem('list_tpl', $row); $content .= self::getCacheItem('detail_tpl', $row); $content .= self::getCacheItem('page_size', $row, 'int'); $content .= self::getCacheItem('seo_title', $row); $content .= self::getCacheItem('seo_keywords', $row); $content .= self::getCacheItem('seo_description', $row); $content .= "];" . self::$newLine; } self::writeFile('cachedChannels.php', $content); }