silverstripe-blog/code/model/BlogCategory.php

146 lines
2.8 KiB
PHP
Raw Normal View History

2013-07-21 12:23:35 +02:00
<?php
/**
2015-05-09 16:33:12 +02:00
* A blog category for generalising blog posts.
2013-07-21 12:23:35 +02:00
*
* @package silverstripe
* @subpackage blog
*
2015-05-09 16:33:12 +02:00
* @method Blog Blog()
*
* @property string $URLSegment
* @property int $BlogID
*/
class BlogCategory extends DataObject implements CategorisationObject {
/**
* @var array
*/
2013-07-21 12:23:35 +02:00
private static $db = array(
2015-05-09 16:33:12 +02:00
'Title' => 'Varchar(255)',
2013-07-21 12:23:35 +02:00
);
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
2013-07-21 12:23:35 +02:00
private static $has_one = array(
2015-05-09 16:33:12 +02:00
'Blog' => 'Blog',
2013-07-21 12:23:35 +02:00
);
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
2013-08-04 18:38:26 +02:00
private static $belongs_many_many = array(
2015-05-09 16:33:12 +02:00
'BlogPosts' => 'BlogPost',
2013-07-21 12:23:35 +02:00
);
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
2013-08-04 18:38:26 +02:00
private static $extensions = array(
2015-05-09 16:33:12 +02:00
'URLSegmentExtension',
2013-08-04 18:38:26 +02:00
);
/**
* @return DataList
*/
public function BlogPosts() {
$blogPosts = parent::BlogPosts();
$this->extend("updateGetBlogPosts", $blogPosts);
return $blogPosts;
}
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
2013-08-04 18:38:26 +02:00
public function getCMSFields() {
$fields = new FieldList(
2015-05-09 16:33:12 +02:00
TextField::create('Title', _t('BlogCategory.Title', 'Title'))
2013-08-04 18:38:26 +02:00
);
2015-05-09 16:33:12 +02:00
$this->extend('updateCMSFields', $fields);
2013-08-04 18:38:26 +02:00
2015-05-09 16:33:12 +02:00
return $fields;
}
2013-08-04 18:38:26 +02:00
/**
* Returns a relative link to this category.
*
2015-05-09 16:33:12 +02:00
* @return string
*/
2013-08-04 18:38:26 +02:00
public function getLink() {
2015-05-09 16:33:12 +02:00
return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment);
2013-08-04 18:38:26 +02:00
}
/**
2015-05-09 16:33:12 +02:00
* Inherits from the parent blog or can be overwritten using a DataExtension.
*
2015-05-09 16:33:12 +02:00
* @param null|Member $member
*
2015-05-09 16:33:12 +02:00
* @return bool
*/
public function canView($member = null) {
$extended = $this->extendedCan(__FUNCTION__, $member);
2015-05-09 16:33:12 +02:00
if($extended !== null) {
return $extended;
}
2015-05-09 16:33:12 +02:00
return $this->Blog()->canView($member);
}
/**
2015-05-09 16:33:12 +02:00
* Inherits from the parent blog or can be overwritten using a DataExtension.
*
2015-05-09 16:33:12 +02:00
* @param null|Member $member
*
2015-05-09 16:33:12 +02:00
* @return bool
*/
public function canCreate($member = null) {
$extended = $this->extendedCan(__FUNCTION__, $member);
2015-05-09 16:33:12 +02:00
if($extended !== null) {
return $extended;
}
$permission = Blog::config()->grant_user_permission;
2015-05-09 16:33:12 +02:00
return Permission::checkMember($member, $permission);
}
/**
2015-05-09 16:33:12 +02:00
* Inherits from the parent blog or can be overwritten using a DataExtension.
*
2015-05-09 16:33:12 +02:00
* @param null|Member $member
*
2015-05-09 16:33:12 +02:00
* @return bool
*/
public function canDelete($member = null) {
$extended = $this->extendedCan(__FUNCTION__, $member);
2015-05-09 16:33:12 +02:00
if($extended !== null) {
return $extended;
}
2015-05-09 16:33:12 +02:00
return $this->Blog()->canEdit($member);
}
/**
2015-05-09 16:33:12 +02:00
* Inherits from the parent blog or can be overwritten using a DataExtension.
*
2015-05-09 16:33:12 +02:00
* @param null|Member $member
*
2015-05-09 16:33:12 +02:00
* @return bool
*/
public function canEdit($member = null) {
$extended = $this->extendedCan(__FUNCTION__, $member);
2015-05-09 16:33:12 +02:00
if($extended !== null) {
return $extended;
}
2015-05-09 16:33:12 +02:00
return $this->Blog()->canEdit($member);
}
}