2013-07-21 12:23:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A blog category fo generalising blog posts.
|
|
|
|
*
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
|
|
|
*
|
2014-02-16 06:19:26 +01:00
|
|
|
* @author Michael Strong <github@michaelstrong.co.uk>
|
2013-07-21 12:23:35 +02:00
|
|
|
**/
|
|
|
|
class BlogCategory extends DataObject {
|
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
"Title" => "Varchar(255)",
|
|
|
|
);
|
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
private static $has_one = array(
|
|
|
|
"Blog" => "Blog",
|
|
|
|
);
|
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
private static $belongs_many_many = array(
|
2013-07-21 12:23:35 +02:00
|
|
|
"BlogPosts" => "BlogPost",
|
|
|
|
);
|
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
private static $extensions = array(
|
|
|
|
"URLSegmentExtension",
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = new FieldList(
|
2013-08-11 00:34:46 +02:00
|
|
|
TextField::create("Title", _t("BlogCategory.Title", "Title"))
|
2013-08-04 18:38:26 +02:00
|
|
|
);
|
|
|
|
$this->extend("updateCMSFields", $fields);
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a relative link to this category.
|
|
|
|
*
|
|
|
|
* @return string URL
|
|
|
|
**/
|
|
|
|
public function getLink() {
|
|
|
|
return Controller::join_links($this->Blog()->Link(), "category", $this->URLSegment);
|
|
|
|
}
|
|
|
|
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
return $this->Blog()->canView($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canCreate($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
return $this->Blog()->canEdit($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canDelete($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
return $this->Blog()->canEdit($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inherits from the parent blog or can be overwritten using a DataExtension
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null) {
|
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
return $this->Blog()->canEdit($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|