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()
|
|
|
|
* @method ManyManyList BlogPosts()
|
|
|
|
*
|
|
|
|
* @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
|
|
|
);
|
2015-11-17 04:06:19 +01: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
|
|
|
}
|
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension.
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param null|Member $member
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2014-07-27 10:40:08 +02:00
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +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.
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param null|Member $member
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2014-07-27 10:40:08 +02:00
|
|
|
*/
|
|
|
|
public function canCreate($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2015-03-25 02:59:58 +01:00
|
|
|
|
|
|
|
$permission = Blog::config()->grant_user_permission;
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-03-25 02:59:58 +01:00
|
|
|
return Permission::checkMember($member, $permission);
|
2014-07-27 10:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension.
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param null|Member $member
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2014-07-27 10:40:08 +02:00
|
|
|
*/
|
|
|
|
public function canDelete($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +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.
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param null|Member $member
|
2014-07-27 10:40:08 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2014-07-27 10:40:08 +02:00
|
|
|
*/
|
|
|
|
public function canEdit($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
return $this->Blog()->canEdit($member);
|
|
|
|
}
|
|
|
|
}
|