当前位置: 首页>>代码示例>>PHP>>正文


PHP CategoryModel::getByPermission方法代码示例

本文整理汇总了PHP中CategoryModel::getByPermission方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getByPermission方法的具体用法?PHP CategoryModel::getByPermission怎么用?PHP CategoryModel::getByPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CategoryModel的用法示例。


在下文中一共展示了CategoryModel::getByPermission方法的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) {
//.........这里部分代码省略.........
开发者ID:vanilla,项目名称:vanilla,代码行数:101,代码来源:class.postcontroller.php

示例2: categoryDropDown

 /**
  * Returns XHTML for a select list containing categories that the user has
  * permission to use.
  *
  * @param array $FieldName An array of category data to render.
  * @param array $Options An associative array of options for the select. Here
  * is a list of "special" options and their default values:
  *
  *   Attribute     Options                        Default
  *   ------------------------------------------------------------------------
  *   Value         The ID of the category that    FALSE
  *                 is selected.
  *   IncludeNull   Include a blank row?           TRUE
  *   Context       A set of categories to         []
  *                 interset with the CategoryData
  *                 that is relative to the category
  *                 we're in.
  *   CategoryData  Custom set of categories to    CategoryModel::Categories()
  *                 display.
  *
  * @return string
  */
 public function categoryDropDown($FieldName = 'CategoryID', $Options = array())
 {
     $this->EventArguments['Options'] =& $Options;
     $this->fireEvent('BeforeCategoryDropDown');
     $Value = arrayValueI('Value', $Options);
     // The selected category id
     $CategoryData = val('CategoryData', $Options);
     if (!$CategoryData && val('Context', $Options)) {
         $CategoryData = val('Context', $Options);
     } elseif ($CategoryData && val('Context', $Options)) {
         $CategoryData = array_intersect_key($CategoryData, val('Context', $Options));
     }
     // Sanity check
     if (is_object($CategoryData)) {
         $CategoryData = (array) $CategoryData;
     } elseif (!is_array($CategoryData)) {
         $CategoryData = array();
     }
     $Permission = val('Permission', $Options, 'add');
     // Grab the category data.
     if (!$CategoryData) {
         $CategoryData = CategoryModel::getByPermission('Discussions.View', $Value, val('Filter', $Options, array('Archived' => 0)), val('PermFilter', $Options, array()));
     }
     // Respect category permissions (remove categories that the user shouldn't see).
     $SafeCategoryData = array();
     foreach ($CategoryData as $CategoryID => $Category) {
         $Name = $Category['Name'];
         if ($Value != $CategoryID) {
             if ($Category['CategoryID'] <= 0 || !$Category['PermsDiscussionsView']) {
                 continue;
             }
             if ($Category['Archived']) {
                 continue;
             }
         }
         $SafeCategoryData[$CategoryID] = $Category;
     }
     unset($Options['Filter'], $Options['PermFilter'], $Options['Context'], $Options['CategoryData']);
     if (!isset($Options['class'])) {
         $Options['class'] = $this->getStyle('dropdown');
     } else {
         $Options['class'] = $this->translateClasses($Attributes['class']);
     }
     // Opening select tag
     $Return = '<select';
     $Return .= $this->_idAttribute($FieldName, $Options);
     $Return .= $this->_nameAttribute($FieldName, $Options);
     $Return .= $this->_attributesToString($Options);
     $Return .= ">\n";
     // Get value from attributes
     if ($Value === false) {
         $Value = $this->getValue($FieldName);
     }
     if (!is_array($Value)) {
         $Value = array($Value);
     }
     // Prevent default $Value from matching key of zero
     $HasValue = $Value !== array(false) && $Value !== array('') ? true : false;
     // Start with null option?
     $IncludeNull = val('IncludeNull', $Options);
     if ($IncludeNull === true) {
         $Return .= '<option value="">' . t('Select a category...') . '</option>';
     } elseif (is_array($IncludeNull)) {
         $Return .= "<option value=\"{$IncludeNull[0]}\">{$IncludeNull[1]}</option>\n";
     } elseif ($IncludeNull) {
         $Return .= "<option value=\"\">{$IncludeNull}</option>\n";
     } elseif (!$HasValue) {
         $Return .= '<option value=""></option>';
     }
     // Show root categories as headings (ie. you can't post in them)?
     $DoHeadings = val('Headings', $Options, c('Vanilla.Categories.DoHeadings'));
     // If making headings disabled and there was no default value for
     // selection, make sure to select the first non-disabled value, or the
     // browser will auto-select the first disabled option.
     $ForceCleanSelection = $DoHeadings && !$HasValue && !$IncludeNull;
     // Write out the category options
     if (is_array($SafeCategoryData)) {
         foreach ($SafeCategoryData as $CategoryID => $Category) {
//.........这里部分代码省略.........
开发者ID:vanilla,项目名称:vanilla,代码行数:101,代码来源:class.form.php


注:本文中的CategoryModel::getByPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。