/**
  * Get the forums. Actually its a bit more complex than that
  * we need to group by the Forum Categories.
  *
  * @return ArrayList
  */
 function Forums()
 {
     $categoryText = isset($_REQUEST['Category']) ? Convert::raw2xml($_REQUEST['Category']) : null;
     $holder = $this;
     if ($this->getShowInCategories()) {
         return ForumCategory::get()->filter('ForumHolderID', $this->ID)->filterByCallback(function ($category) use($categoryText, $holder) {
             // Don't include if we've specified a Category, and it doesn't match this one
             if ($categoryText !== null && $category->Title != $categoryText) {
                 return false;
             }
             // Get a list of forums that live under this holder & category
             $category->CategoryForums = Forum::get()->filter(array('CategoryID' => $category->ID, 'ParentID' => $holder->ID, 'ShowInMenus' => 1))->filterByCallback(function ($forum) {
                 return $forum->canView();
             });
             return $category->CategoryForums->exists();
         });
     } else {
         return Forum::get()->filter(array('ParentID' => $this->ID, 'ShowInMenus' => 1))->filterByCallback(function ($forum) {
             return $forum->canView();
         });
     }
 }
示例#2
0
 /**
  * Returns a FieldList with which to create the CMS editing form
  *
  * @return FieldList The fields to be displayed in the CMS.
  */
 function getCMSFields()
 {
     Requirements::javascript("forum/javascript/ForumAccess.js");
     Requirements::css("forum/css/Forum_CMS.css");
     $fields = parent::getCMSFields();
     $fields->addFieldToTab("Root.Access", new HeaderField(_t('Forum.ACCESSPOST', 'Who can post to the forum?'), 2));
     $fields->addFieldToTab("Root.Access", $optionSetField = new OptionsetField("CanPostType", "", array("Inherit" => "Inherit", "Anyone" => _t('Forum.READANYONE', 'Anyone'), "LoggedInUsers" => _t('Forum.READLOGGEDIN', 'Logged-in users'), "OnlyTheseUsers" => _t('Forum.READLIST', 'Only these people (choose from list)'), "NoOne" => _t('Forum.READNOONE', 'Nobody. Make Forum Read Only'))));
     $optionSetField->addExtraClass('ForumCanPostTypeSelector');
     $fields->addFieldsToTab("Root.Access", array(new TreeMultiselectField("PosterGroups", _t('Forum.GROUPS', "Groups")), new OptionsetField("CanAttachFiles", _t('Forum.ACCESSATTACH', 'Can users attach files?'), array("1" => _t('Forum.YES', 'Yes'), "0" => _t('Forum.NO', 'No')))));
     //Dropdown of forum category selection.
     $categories = ForumCategory::get()->map();
     $fields->addFieldsToTab("Root.Main", DropdownField::create('CategoryID', _t('Forum.FORUMCATEGORY', 'Forum Category'), $categories), 'Content');
     //GridField Config - only need to attach or detach Moderators with existing Member accounts.
     $moderatorsConfig = GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldAddExistingAutocompleter('buttons-before-right'))->addComponent(new GridFieldToolbarHeader())->addComponent($sort = new GridFieldSortableHeader())->addComponent($columns = new GridFieldDataColumns())->addComponent(new GridFieldDeleteAction(true))->addComponent(new GridFieldPageCount('toolbar-header-right'))->addComponent($pagination = new GridFieldPaginator());
     // Use GridField for Moderator management
     $moderators = GridField::create('Moderators', _t('MODERATORS', 'Moderators for this forum'), $this->Moderators(), $moderatorsConfig);
     $columns->setDisplayFields(array('Nickname' => 'Nickname', 'FirstName' => 'First name', 'Surname' => 'Surname', 'Email' => 'Email', 'LastVisited.Long' => 'Last Visit'));
     $sort->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
     $fields->addFieldToTab('Root.Moderators', $moderators);
     return $fields;
 }