本文整理汇总了PHP中CategoryModel::AllowedDiscussionTypes方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::AllowedDiscussionTypes方法的具体用法?PHP CategoryModel::AllowedDiscussionTypes怎么用?PHP CategoryModel::AllowedDiscussionTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::AllowedDiscussionTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ToString
/**
* Render the module.
*
* @return string
*/
public function ToString()
{
// Set CategoryID if we have one.
if ($this->CategoryID === NULL) {
$this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
}
// Allow plugins and themes to modify parameters.
Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
// Make sure the user has the most basic of permissions first.
$PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
if ($this->CategoryID) {
$Category = CategoryModel::Categories($this->CategoryID);
$HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
} else {
$HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
}
// Determine if this is a guest & we're using "New Discussion" button as call to action.
$PrivilegedGuest = $this->ShowGuests && !Gdn::Session()->IsValid();
// No module for you!
if (!$HasPermission && !$PrivilegedGuest) {
return '';
}
// Grab the allowed discussion types.
$DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
foreach ($DiscussionTypes as $Key => $Type) {
if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
unset($DiscussionTypes[$Key]);
continue;
}
// If user !$HasPermission, they are $PrivilegedGuest so redirect to $GuestUrl.
$Url = $HasPermission ? GetValue('AddUrl', $Type) : $this->GuestUrl;
if (!$Url) {
continue;
}
if (isset($Category) && $HasPermission) {
$Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
}
$this->AddButton(T(GetValue('AddText', $Type)), $Url);
}
// Add QueryString to URL if one is defined.
if ($this->QueryString && $HasPermission) {
foreach ($this->Buttons as &$Row) {
$Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
}
}
return parent::ToString();
}
示例2: ToString
public function ToString()
{
if ($this->CategoryID === NULL) {
$this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
}
Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
// Make sure the user has the most basic of permissions first.
$PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
if ($this->CategoryID) {
$Category = CategoryModel::Categories($this->CategoryID);
$HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
} else {
$HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
}
if (!$HasPermission) {
return '';
}
// Grab the allowed discussion types.
$DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
foreach ($DiscussionTypes as $Key => $Type) {
if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
unset($DiscussionTypes[$Key]);
continue;
}
$Url = GetValue('AddUrl', $Type);
if (!$Url) {
continue;
}
if (isset($Category)) {
$Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
}
$this->AddButton(T(GetValue('AddText', $Type)), $Url);
}
if ($this->QueryString) {
foreach ($this->Buttons as &$Row) {
$Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
}
}
return parent::ToString();
}