本文整理汇总了PHP中CategoryModel::getTreeAsFlat方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getTreeAsFlat方法的具体用法?PHP CategoryModel::getTreeAsFlat怎么用?PHP CategoryModel::getTreeAsFlat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::getTreeAsFlat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getChildren
/**
* Get a list of immediate children for the configured category.
*
* @return array|null
*/
public function getChildren()
{
$category = $this->getCategory();
if ($category && !$this->children) {
$this->children = $this->categoryModel->getTreeAsFlat(val('CategoryID', $category), 0, $this->getLimit(), $this->getFilter());
$this->categoryModel->joinRecent($this->children);
}
return $this->children;
}
示例2: getCategoryTree
/**
* Build a structured tree of children for the specified category.
*
* @param int|string|object|array|null $category Category or code/ID to build the tree for. Null for all.
* @param string|null $displayAs What display should the tree be configured for?
* @param bool $recent Join in recent record info?
* @param bool $watching Filter categories by "watching" status?
* @return array
*/
private function getCategoryTree($category = null, $displayAs = null, $recent = false, $watching = false)
{
$categoryIdentifier = null;
if (is_string($category) || is_numeric($category)) {
$category = CategoryModel::categories($category);
}
if ($category) {
if ($displayAs === null) {
$displayAs = val('DisplayAs', $category, 'Discussions');
}
$categoryIdentifier = val('CategoryID', $category, null);
}
switch ($displayAs) {
case 'Flat':
$perPage = c('Vanilla.Categories.PerPage', 30);
$page = Gdn::request()->get('Page', Gdn::request()->get('page', null));
list($offset, $limit) = offsetLimit($page, $perPage);
$categoryTree = $this->CategoryModel->getTreeAsFlat($categoryIdentifier, $offset, $limit);
$this->setData('_Limit', $perPage);
$this->setData('_CurrentRecords', count($categoryTree));
break;
case 'Categories':
case 'Discussions':
case 'Default':
case 'Nested':
default:
$categoryTree = $this->CategoryModel->setJoinUserCategory(true)->getChildTree($categoryIdentifier ?: null, ['depth' => CategoryModel::instance()->getMaxDisplayDepth() ?: 10]);
}
if ($recent) {
$this->CategoryModel->joinRecent($categoryTree);
}
return $categoryTree;
}
示例3: categories
/**
* Manage the category hierarchy.
*
* @param string $parent The URL slug of a parent category if looking at a sub tree.
*/
public function categories($parent = '')
{
$this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
$this->setHighlightRoute('vanilla/settings/categories');
// Make sure we are reading the categories from the database only.
$collection = $this->CategoryModel->createCollection(Gdn::sql(), new Gdn_Dirtycache());
$allowSorting = true;
$usePagination = false;
$perPage = 30;
$page = Gdn::request()->get('Page', Gdn::request()->get('page', null));
list($offset, $limit) = offsetLimit($page, $perPage);
if (!empty($parent)) {
$categoryRow = $collection->get((string) $parent);
if (empty($categoryRow)) {
throw notFoundException('Category');
}
$this->setData('Category', $categoryRow);
$parentID = $categoryRow['CategoryID'];
$parentDisplayAs = val('DisplayAs', $categoryRow);
} else {
$parentID = -1;
$parentDisplayAs = CategoryModel::getRootDisplayAs();
}
if (in_array($parentDisplayAs, ['Flat'])) {
$allowSorting = false;
$usePagination = true;
}
if ($parentDisplayAs === 'Flat') {
$categories = $this->CategoryModel->getTreeAsFlat($parentID, $offset, $limit);
} else {
$categories = $collection->getTree($parentID, ['maxdepth' => 10, 'collapsecategories' => true]);
}
$this->setData('ParentID', $parentID);
$this->setData('Categories', $categories);
$this->setData('_Limit', $perPage);
$this->setData('_CurrentRecords', count($categories));
if ($parentID > 0) {
$ancestors = $collection->getAncestors($parentID, true);
$this->setData('Ancestors', $ancestors);
}
$this->setData('AllowSorting', $allowSorting);
$this->setData('UsePagination', $usePagination);
$this->addDefinition('AllowSorting', $allowSorting);
$this->addJsFile('category-settings.js');
$this->addJsFile('manage-categories.js');
$this->addJsFile('jquery.nestable.js');
require_once $this->fetchViewLocation('category-settings-functions');
$this->addAsset('Content', $this->fetchView('symbols'));
$this->render();
}