Ejemplo n.º 1
0
 public function testDeletingProtectedNewsCategory()
 {
     $newsCategory = NewsCategory::get(1);
     $newsCategory->delete();
     $this->assertEquals('enabled', $newsCategory->getStatus());
     $this->assertArrayContainsModel($newsCategory, NewsCategory::getCategories());
 }
 public function getCategory()
 {
     $Params = $this->getURLParams();
     if (is_numeric($Params['ID']) && ($Category = NewsCategory::get()->byID((int) $Params['ID']))) {
         return $Category;
     }
 }
 public function __construct($modelClass, $newsAdmin = null, $fields = null, $filters = null)
 {
     $fields = new FieldList(TextField::create('Title'), TextField::create('URLSegment'), DropdownField::create('ParentID', 'Parent page')->setSource(NewsIndex::get()->map('ID', 'Title')->toArray())->setEmptyString('Select'), HeaderField::create('DatesHeader', 'Dates')->setHeadingLevel(3), DateField::create('StartDate')->setTitle(null)->setAttribute('placeholder', 'Start Date'), DateField::create('EndDate')->setTitle(null)->setAttribute('placeholder', 'End Date'), CheckboxSetField::create('Types')->setSource(NewsSearchContext::GetNewsTypes($newsAdmin))->setValue(isset($_REQUEST['q']) && isset($_REQUEST['q']['Types']) ? $_REQUEST['q']['Types'] : null), TextField::create('Tags'), TextField::create('Summary'), TextField::create('Content'), TextField::create('Author'), CheckboxSetField::create('Categories')->setSource(NewsCategory::get()->map('ID', 'Title')->toArray())->setValue(isset($_REQUEST['q']) && isset($_REQUEST['q']['Categories']) ? $_REQUEST['q']['Categories'] : null));
     $filters = array('Title' => new PartialMatchFilter('Title'), 'URLSegment' => new PartialMatchFilter('URLSegment'), 'ParentID' => new ExactMatchFilter('ParentID'), 'Tags' => new PartialMatchFilter('Tags'), 'Summary' => new PartialMatchFilter('Summary'), 'Content' => new PartialMatchFilter('Content'), 'Author' => new PartialMatchFilter('Author'), 'StartDate' => new GreaterThanOrEqualFilter('DateTime'), 'EndDate' => new LessThanOrEqualFilter('DateTime'));
     if ($newsAdmin) {
         $this->newsAdmin = $newsAdmin;
     }
     parent::__construct($modelClass, $fields, $filters);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab('Root.Main', $dateTimeField = new DatetimeField('Date'), 'Content');
     $dateTimeField->getDateField()->setConfig('showcalendar', true);
     $categories = NewsCategory::get()->sort('Title ASC');
     if ($categories && $categories->exists()) {
         $fields->addFieldToTab('Root.Main', new DropdownField('CategoryID', 'Category', $categories->map()), 'Content');
     }
     $fields->addFieldToTab('Root.Main', new TextareaField('Abstract'), 'Content');
     return $fields;
 }
 public function getCMSFields()
 {
     $datefield = DateField::create('Date')->setTitle('Article Date');
     $datefield->setConfig('showcalendar', true);
     $datefield->setConfig('dateformat', 'MM/dd/YYYY');
     $imagefield = UploadField::create('Photo')->setTitle('Featured Photo');
     $imagefield->folderName = 'News';
     $imagefield->getValidator()->allowedExtensions = array('jpg', 'jpeg', 'gif', 'png');
     $imagefield->getValidator()->setAllowedMaxFileSize('2097152');
     // 2 MB in bytes
     $categoriesMap = NewsCategory::get()->filter('NewsHolderID', $this->Parent()->ID)->sort('Title ASC')->map('ID', 'Title')->toArray();
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Main', array($datefield, TextField::create('Author')->setTitle('Author Name'), $imagefield, ListboxField::create('NewsCategories')->setTitle('Category')->setMultiple(true)->setSource($categoriesMap)), 'Content');
     return $fields;
 }
Ejemplo n.º 6
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if (!Config::inst()->get('NewsPost', 'pages_admin')) {
         $arrTypes = NewsPost::GetNewsTypes();
         if (count($arrTypes) > 1) {
             $arrDropDownSource = array();
             foreach ($arrTypes as $strType) {
                 $arrDropDownSource[$strType] = $strType;
             }
             $fields->addFieldToTab('Root.Main', DropdownField::create('ClassName')->setSource($arrDropDownSource)->setTitle('Type'), 'Content');
         }
     }
     $fields->addFieldsToTab('Root.Main', array(DropdownField::create('ParentID')->setSource(NewsIndex::get()->map()->toArray())->setTitle('Parent Page'), DatetimeField::create('DateTime'), TextField::create('Tags'), TextField::create('Author'), HtmlEditorField::create('Summary')->setRows(5)), 'Content');
     if ($this->ID) {
         $fields->addFieldToTab('Root.Main', CheckboxSetField::create('Categories')->setSource(NewsCategory::get()->map('ID', 'Title')->toArray()), 'Content');
         $fields->addFieldToTab('Root.RelatedArticles', GridField::create('RelatedArticles', 'Related Articles')->setList($this->RelatedArticles())->setConfig($relatedArticlesConfig = new GridFieldConfig_RelationEditor()));
     }
     $this->extend('updateNewsPostCMSFields', $fields);
     return $fields;
 }
Ejemplo n.º 7
0
 public function getCategories()
 {
     return NewsCategory::get()->sort('Title', 'DESC');
 }
Ejemplo n.º 8
0
 public function CurrentCategory()
 {
     $segment = $this->request->latestParam('ID');
     return NewsCategory::get()->filter('URLSegment', $segment)->First();
 }
Ejemplo n.º 9
0
 /**
  * Get the category of the news article
  * @return NewsCategory The category of the post
  */
 public function getCategory()
 {
     return NewsCategory::get($this->category);
 }
Ejemplo n.º 10
0
 /**
  * @return DataList
  */
 public function NewsCategories()
 {
     return NewsCategory::get();
 }