本文整理汇总了PHP中CategoryModel::getSubtree方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getSubtree方法的具体用法?PHP CategoryModel::getSubtree怎么用?PHP CategoryModel::getSubtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::getSubtree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: discussion
/**
* Create or update a discussion.
*
* @since 2.0.0
* @access public
*
* @param int $CategoryID Unique ID of the category to add the discussion to.
*/
public function discussion($CategoryUrlCode = '')
{
// Override CategoryID if categories are disabled
$UseCategories = $this->ShowCategorySelector = (bool) c('Vanilla.Categories.Use');
if (!$UseCategories) {
$CategoryUrlCode = '';
}
// Setup head
$this->addJsFile('jquery.autosize.min.js');
$this->addJsFile('autosave.js');
$this->addJsFile('post.js');
$Session = Gdn::session();
Gdn_Theme::section('PostDiscussion');
// Set discussion, draft, and category data
$DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : '';
$DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0;
$Category = false;
$CategoryModel = new CategoryModel();
if (isset($this->Discussion)) {
$this->CategoryID = $this->Discussion->CategoryID;
$Category = CategoryModel::categories($this->CategoryID);
} elseif ($CategoryUrlCode != '') {
$Category = CategoryModel::categories($CategoryUrlCode);
if ($Category) {
$this->CategoryID = val('CategoryID', $Category);
}
}
if ($Category) {
$this->Category = (object) $Category;
$this->setData('Category', $Category);
$this->Form->addHidden('CategoryID', $this->Category->CategoryID);
if (val('DisplayAs', $this->Category) == 'Discussions' && !$DraftID) {
$this->ShowCategorySelector = false;
} else {
// Get all our subcategories to add to the category if we are in a Header or Categories category.
$this->Context = CategoryModel::getSubtree($this->CategoryID);
}
} else {
$this->CategoryID = 0;
$this->Category = null;
}
$CategoryData = $this->ShowCategorySelector ? CategoryModel::categories() : false;
// Check permission
if (isset($this->Discussion)) {
// Make sure that content can (still) be edited.
$CanEdit = DiscussionModel::canEdit($this->Discussion);
if (!$CanEdit) {
throw permissionException('Vanilla.Discussions.Edit');
}
// Make sure only moderators can edit closed things
if ($this->Discussion->Closed) {
$this->permission('Vanilla.Discussions.Edit', true, 'Category', $this->Category->PermissionCategoryID);
}
$this->Form->setFormValue('DiscussionID', $this->Discussion->DiscussionID);
$this->title(t('Edit Discussion'));
if ($this->Discussion->Type) {
$this->setData('Type', $this->Discussion->Type);
} else {
$this->setData('Type', 'Discussion');
}
} else {
// Permission to add.
if ($this->Category) {
$this->permission('Vanilla.Discussions.Add', true, 'Category', $this->Category->PermissionCategoryID);
} else {
$this->permission('Vanilla.Discussions.Add');
}
$this->title(t('New Discussion'));
}
touchValue('Type', $this->Data, 'Discussion');
// See if we should hide the category dropdown.
if ($this->ShowCategorySelector) {
$AllowedCategories = CategoryModel::getByPermission('Discussions.Add', $this->Form->getValue('CategoryID', $this->CategoryID), ['Archived' => 0, 'AllowDiscussions' => 1], ['AllowedDiscussionTypes' => $this->Data['Type']]);
if (count($AllowedCategories) == 1) {
$AllowedCategory = array_pop($AllowedCategories);
$this->ShowCategorySelector = false;
$this->Form->addHidden('CategoryID', $AllowedCategory['CategoryID']);
if ($this->Form->isPostBack() && !$this->Form->getFormValue('CategoryID')) {
$this->Form->setFormValue('CategoryID', $AllowedCategory['CategoryID']);
}
}
}
// Set the model on the form
$this->Form->setModel($this->DiscussionModel);
if (!$this->Form->isPostBack()) {
// Prep form with current data for editing
if (isset($this->Discussion)) {
$this->Form->setData($this->Discussion);
} elseif (isset($this->Draft)) {
$this->Form->setData($this->Draft);
} else {
if ($this->Category !== null) {
//.........这里部分代码省略.........
示例2: index
/**
* Show all discussions in a particular category.
*
* @since 2.0.0
* @access public
*
* @param string $CategoryIdentifier Unique category slug or ID.
* @param int $Offset Number of discussions to skip.
*/
public function index($CategoryIdentifier = '', $Page = '0')
{
// Figure out which category layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Categories.Layout');
if ($CategoryIdentifier == '') {
switch ($Layout) {
case 'mixed':
$this->View = 'discussions';
$this->discussions();
break;
case 'table':
$this->table();
break;
default:
$this->View = 'all';
$this->all('', CategoryModel::getRootDisplayAs());
break;
}
return;
} else {
$Category = CategoryModel::categories($CategoryIdentifier);
if (empty($Category)) {
throw notFoundException();
}
$Category = (object) $Category;
Gdn_Theme::section($Category->CssClass);
// Load the breadcrumbs.
$this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $Category)));
$this->setData('Category', $Category, true);
$this->title(htmlspecialchars(val('Name', $Category, '')));
$this->description(val('Description', $Category), true);
switch ($Category->DisplayAs) {
case 'Flat':
case 'Heading':
case 'Categories':
$stopHeadings = val('Depth', $Category) > CategoryModel::instance()->getNavDepth();
CategoryModel::instance()->setStopHeadingsCalculation($stopHeadings);
if ($this->SyndicationMethod != SYNDICATION_NONE) {
// RSS can't show a category list so just tell it to expand all categories.
saveToConfig('Vanilla.ExpandCategories', true, false);
} else {
// This category is an overview style category and displays as a category list.
switch ($Layout) {
case 'mixed':
$this->View = 'discussions';
$this->discussions($CategoryIdentifier);
break;
case 'table':
$this->table($CategoryIdentifier, $Category->DisplayAs);
break;
default:
$this->View = 'all';
$this->All($CategoryIdentifier, $Category->DisplayAs);
break;
}
return;
}
break;
}
Gdn_Theme::section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
$this->setData('CategoryTree', $this->getCategoryTree($CategoryIdentifier, val('DisplayAs', $Category)));
// Add a backwards-compatibility shim for the old categories.
$this->categoriesCompatibilityCallback = function () use($CategoryIdentifier) {
$categories = CategoryModel::getSubtree($CategoryIdentifier, false);
return $categories;
};
// Setup head
$this->Menu->highlightRoute('/discussions');
if ($this->Head) {
$this->addJsFile('discussions.js');
$this->Head->addRss(categoryUrl($Category) . '/feed.rss', $this->Head->title());
}
// Set CategoryID
$CategoryID = val('CategoryID', $Category);
$this->setData('CategoryID', $CategoryID, true);
// Add modules
$this->addModule('NewDiscussionModule');
$this->addModule('DiscussionFilterModule');
$this->addModule('CategoriesModule');
//.........这里部分代码省略.........