2015-11-21 07:17:29 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
namespace SilverStripe\Blog\Model;
|
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
use SilverStripe\Blog\Model\Blog;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogObject;
|
2017-01-26 09:28:42 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogPost;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Blog\Model\CategorisationObject;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* A blog category for generalising blog posts.
|
|
|
|
*
|
2017-09-14 00:01:45 +02:00
|
|
|
*
|
2015-11-21 07:17:29 +01:00
|
|
|
* @method Blog Blog()
|
|
|
|
*
|
2016-06-02 03:11:05 +02:00
|
|
|
* @property string $Title
|
2015-11-21 07:17:29 +01:00
|
|
|
* @property string $URLSegment
|
|
|
|
* @property int $BlogID
|
|
|
|
*/
|
|
|
|
class BlogCategory extends DataObject implements CategorisationObject
|
|
|
|
{
|
2016-06-02 03:11:05 +02:00
|
|
|
use BlogObject;
|
2016-02-05 01:33:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use an exception code so that attempted writes can continue on
|
|
|
|
* duplicate errors.
|
|
|
|
*
|
|
|
|
* @const string
|
|
|
|
* This must be a string because ValidationException has decided we can't use int
|
|
|
|
*/
|
2016-06-02 03:11:05 +02:00
|
|
|
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
2016-02-05 01:33:40 +01:00
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $table_name = 'BlogCategory';
|
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $db = array(
|
2016-12-15 04:41:49 +01:00
|
|
|
'Title' => 'Varchar(255)',
|
|
|
|
'URLSegment' => 'Varchar(255)'
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $has_one = array(
|
2017-01-26 09:28:42 +01:00
|
|
|
'Blog' => Blog::class,
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $belongs_many_many = array(
|
2017-01-26 09:28:42 +01:00
|
|
|
'BlogPosts' => BlogPost::class,
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2016-06-02 03:11:05 +02:00
|
|
|
protected function getListUrlSegment()
|
2015-11-21 07:17:29 +01:00
|
|
|
{
|
2017-01-13 03:55:48 +01:00
|
|
|
return 'category';
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-05 01:33:40 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2016-06-02 03:11:05 +02:00
|
|
|
protected function getDuplicateError()
|
2016-02-05 01:33:40 +01:00
|
|
|
{
|
2016-06-02 03:11:05 +02:00
|
|
|
return _t('BlogCategory.Duplicate', 'A blog category already exists with that name.');
|
2016-02-05 01:33:40 +01:00
|
|
|
}
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|