/** * returns a DataObjectSet of all the BlogCategories * @return {DataObjectSet} */ public function getAllBlogCategories() { if (Config::inst()->get('BlogCategory', 'limit_to_holder') && $this->owner->Parent()->ClassName == 'BlogHolder') { return $this->owner->Parent()->BlogCategories(); } else { return BlogCategory::get(); } }
public function LookForExistingURLSegment($URLSegment) { $existing = BlogCategory::get()->filter(array("URLSegment" => $URLSegment, 'ParentID' => $this->ParentID)); if ($this->ID) { $existing = $existing->exclude("ID", $this->ID); } return $existing->count(); }
/** * Get the blog categories * @return ArrayList */ public function getCategories() { $categories = new ArrayList(); foreach (BlogCategory::get() as $category) { $data = array('Title' => $category->Title, 'Link' => $category->Parent()->Link('category/' . $category->URLSegment), 'ShowCount' => $this->ShowCount, 'Count' => $this->totalEntries($category->ID)); $categories->push(new ArrayData($data)); } return $categories; }
public function index($arguments) { $slug = $arguments->param('Slug'); $blogcategory = BlogCategory::get()->filter(array('Slug' => $slug))->First(); $this->Title = $blogcategory->Name; $this->BlogCategoryID = $blogcategory->ID; $this->Entries = $blogcategory->BlogEntries()->sort('Date DESC'); return $this->renderWith(array('BlogEntries', 'Page')); }
/** * updates the fields used in the CMS * @see DataExtension::updateCMSFields() * @TODO remove the add/edit buttons from the authors gridfield */ public function updateCMSFields(FieldList $fields) { // Categories tab: Show either on BlogTree or BlogHoder depending on limit settings $limit = Config::inst()->get('BlogCategory', 'limit_to_holder'); if ($limit && $this->owner instanceof BlogHolder || !$limit && !$this->owner instanceof BlogHolder) { $categories = $limit ? $this->owner->BlogCategories() : BlogCategory::get(); $fields->addFieldToTab('Root.Categories', GridField::create('BlogCategories', 'Blog Categories', $categories, GridFieldConfig_RecordEditor::create())); } }
public function getFeaturedBlogPost() { $category = $this->getCategory(); $tag = $this->getTag(); $archive = $this->getArchive(); if ($category) { $category = BlogCategory::get()->filter("URLSegment", $category)->first(); return $category->BlogPosts()->filter("FeaturedPost", true)->first(); } if ($tag) { $tag = BlogTag::get()->filter("URLSegment", $tag)->first(); return $tag->BlogPosts()->filter("FeaturedPost", true)->first(); } if ($archive) { return $this->owner->getArchivedBlogPosts($archive["Year"], $archive["Month"], $archive["Day"])->filter("FeaturedPost", true)->first(); } return BlogPost::get()->filter("FeaturedPost", true)->first(); }
/** * @return ArrayList of {@link BlogCategoryCloud_Category} */ public function Categories() { $result = new ArrayList(); $cats = BlogCategory::get(); $entries = BlogEntry::get(); if ($this->holderId) { $cats = $cats->filter('ParentID', $this->holderId); $entries = $entries->filter('ParentID', $this->holderId); } $totalEntryCount = $entries->count(); // TODO Not possible in a single query due to SS3 ORM $aggregateQuery = clone $cats->dataQuery()->query(); $aggregateQuery->addLeftJoin('BlogEntry_BlogCategories', '"BlogEntry_BlogCategories"."BlogCategoryID" = "BlogCategory"."ID"'); $aggregateQuery->addLeftJoin('BlogEntry', '"BlogEntry_BlogCategories"."BlogEntryID" = "BlogEntry"."ID"'); $aggregateQuery->setSelect(array('"BlogCategory"."ID"')); $aggregateQuery->selectField('COUNT("BlogEntry"."ID")', 'BlogEntryCount'); $aggregateQuery->setGroupBy(array('"BlogCategory"."ID"')); $aggregateResults = array(); $maxEntryCount = 0; foreach ($aggregateQuery->execute() as $v) { $aggregateResults[$v['ID']] = $v; if ($v['BlogEntryCount'] > $maxEntryCount) { $maxEntryCount = $v['BlogEntryCount']; } } foreach ($cats as $cat) { $result->push(BlogCategoryCloud_Category::create($cat, $aggregateResults[$cat->ID]['BlogEntryCount'], $totalEntryCount, $maxEntryCount)); } // Sort in-memory since it might be related to dynamic values like frequency // TODO Convert frequency calc to subselect and do sorting in SQL if ($this->limit) { $result = $result->sort($this->limitSortBy); $result = $result->limit($this->limit); } $result = $result->sort($this->sort); return $result; }
/** * {@inheritdoc} */ public function getCMSFields() { Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); $self =& $this; $this->beforeUpdateCMSFields(function ($fields) use($self) { $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); /** * @var FieldList $fields */ $fields->insertAfter($uploadField, 'Content'); $summary = HtmlEditorField::create('Summary', false); $summary->setRows(5); $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.')); $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary)); $summaryHolder->setHeadingLevel(4); $summaryHolder->addExtraClass('custom-summary'); $fields->insertAfter($summaryHolder, 'FeaturedImage'); $fields->push(HiddenField::create('MenuTitle')); $urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment->setURLPrefix($self->Parent()->RelativeLink()); $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment')); $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray())->setMultiple(true); $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024)->setDescription(_t('BlogPost.AdditionalCredits_Description', 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.')); if (!$self->canEditAuthors()) { $authorField = $authorField->performDisabledTransformation(); $authorNames = $authorNames->performDisabledTransformation(); } $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate->getDateField()->setConfig('showcalendar', true); if (!$self->PublishDate) { $publishDate->setDescription(_t('BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.')); } // Get categories and tags $parent = $self->Parent(); $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get(); $tags = $parent instanceof Blog ? $parent->Tags() : BlogTag::get(); $options = BlogAdminSidebar::create($publishDate, $urlSegment, TagField::create('Categories', _t('BlogPost.Categories', 'Categories'), $categories, $self->Categories())->setCanCreate($self->canCreateCategories())->setShouldLazyLoad(true), TagField::create('Tags', _t('BlogPost.Tags', 'Tags'), $tags, $self->Tags())->setCanCreate($self->canCreateTags())->setShouldLazyLoad(true), $authorField, $authorNames)->setTitle('Post Options'); $options->setName('blog-admin-sidebar'); $fields->insertBefore($options, 'Root'); }); $fields = parent::getCMSFields(); $fields->fieldByName('Root')->setTemplate('TabSet_holder'); return $fields; }
public function AllBlogCategories() { $categories = BlogCategory::get(); return $categories; }
/** * {@inheritdoc} */ public function getCMSFields() { Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); $self =& $this; $this->beforeUpdateCMSFields(function ($fields) use($self) { $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); /** * @var FieldList $fields */ $fields->insertAfter($uploadField, 'Content'); $summary = HtmlEditorField::create('Summary', false); $summary->setRows(5); $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.')); $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary)); $summaryHolder->setHeadingLevel(4); $summaryHolder->addExtraClass('custom-summary'); $fields->insertAfter($summaryHolder, 'FeaturedImage'); $fields->push(HiddenField::create('MenuTitle')); $urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment->setURLPrefix($self->Parent()->RelativeLink()); $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment')); $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), Member::get()->map()->toArray())->setMultiple(true); $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024); $authorNames->setDescription('If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.'); if (!$self->canEditAuthors()) { $authorField = $authorField->performDisabledTransformation(); $authorNames = $authorNames->performDisabledTransformation(); } $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate->getDateField()->setConfig('showcalendar', true); // Get categories and tags $parent = $self->Parent(); $categories = $parent instanceof Blog ? $parent->Categories()->exclude('CatID', 0) : BlogCategory::get()->exclude('CatID', 0); $list = array(); foreach ($categories->sort('CatID, Title ASC') as $cat) { $list[$cat->ID] = sprintf('%s/%s', $cat->Cat()->Title, $cat->Title); } $val = ''; if ($this->Categories()->count() > 0) { $val = $this->Categories()->first()->ID; } $options = BlogAdminSidebar::create($publishDate, $urlSegment, $catField = DropDownField::create('Category', 'Category', $list, $value = $val)->setEmptyString('(select one)'), $authorField, $authorNames)->setTitle('Post Options'); $fields->insertBefore($options, 'Root'); }); $fields = parent::getCMSFields(); $fields->fieldByName('Root')->setTemplate('TabSet_holder'); return $fields; }
protected function importTags($obj, $val, $record) { if ($obj->many_many('BlogCategories')) { // Optionally import into many_many created by the "ioti/blogcategories" module $holder = $this->getHolder($record); $obj->ParentID = $holder->ID; $obj->write(); // required so relation setting works // Import to BlogCategory instead of tags text field $tags = explode(',', $val); $tags = array_map('trim', $tags); $obj->BlogCategories()->removeAll(); foreach ($tags as $tag) { if (!$tag) { continue; } $cat = isset($this->_cache_categories[$tag]) ? $this->_cache_categories[$tag] : null; if (!$cat) { $cat = BlogCategory::get()->filter(array('Title' => $tag))->First(); if (!$cat) { $cat = new BlogCategory(array('Title' => $tag)); } $cat->write(); $this->_cache_categories[$tag] = $cat; } $obj->BlogCategories()->add($cat); // Not entirely accurate, since the title -> slug conversion rules // are slightly different between SS and Drupal. Should catch the majority though. $this->urlMap['category/tag-list/' . $cat->URLSegment] = $cat->getLink(); } } else { $tags = explode(',', $val); $tags = array_map('trim', $tags); $obj->Tags = implode(', ', $tags); } }