2013-08-11 00:34:46 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-16 06:19:26 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Provides a component to the {@link GridField} which tells the user whether or not a blog post
|
|
|
|
* has been published and when.
|
2014-02-16 06:19:26 +01:00
|
|
|
*
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2014-12-11 11:42:36 +01:00
|
|
|
class GridFieldBlogPostState extends GridFieldSiteTreeState {
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-08-11 00:34:46 +02:00
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
2015-05-09 16:33:12 +02:00
|
|
|
if($columnName == 'State') {
|
2014-12-11 11:42:36 +01:00
|
|
|
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
2015-05-14 01:11:50 +02:00
|
|
|
if($record instanceof BlogPost) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$modifiedLabel = '';
|
|
|
|
|
2014-06-13 14:48:34 +02:00
|
|
|
if($record->isModifiedOnStage) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>';
|
2014-12-11 11:42:36 +01:00
|
|
|
}
|
2014-06-12 21:42:32 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if(!$record->isPublished()) {
|
2015-05-14 01:11:50 +02:00
|
|
|
/**
|
|
|
|
* @var SS_Datetime $lastEdited
|
|
|
|
*/
|
|
|
|
$lastEdited = $record->dbObject('LastEdited');
|
|
|
|
|
2014-06-13 12:38:15 +02:00
|
|
|
return _t(
|
2015-05-09 16:33:12 +02:00
|
|
|
'GridFieldBlogPostState.Draft',
|
2014-12-11 11:42:36 +01:00
|
|
|
'<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
|
2015-05-09 16:33:12 +02:00
|
|
|
'State for when a post is saved.',
|
2014-06-13 12:38:15 +02:00
|
|
|
array(
|
2015-05-14 01:11:50 +02:00
|
|
|
'date' => $lastEdited->Nice(),
|
2014-06-13 12:38:15 +02:00
|
|
|
)
|
|
|
|
);
|
2015-05-09 16:33:12 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 01:11:50 +02:00
|
|
|
/**
|
|
|
|
* @var SS_Datetime $publishDate
|
|
|
|
*/
|
|
|
|
$publishDate = $record->dbObject('PublishDate');
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if(strtotime($record->PublishDate) > time()) {
|
2013-08-11 00:34:46 +02:00
|
|
|
return _t(
|
2015-05-09 16:33:12 +02:00
|
|
|
'GridFieldBlogPostState.Timer',
|
2014-12-11 11:42:36 +01:00
|
|
|
'<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}',
|
2015-05-09 16:33:12 +02:00
|
|
|
'State for when a post is published.',
|
2013-08-11 00:34:46 +02:00
|
|
|
array(
|
2015-05-14 01:11:50 +02:00
|
|
|
'date' => $publishDate->Nice(),
|
2013-08-11 00:34:46 +02:00
|
|
|
)
|
2014-06-13 12:49:28 +02:00
|
|
|
) . $modifiedLabel;
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
return _t(
|
|
|
|
'GridFieldBlogPostState.Published',
|
|
|
|
'<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
|
|
|
|
'State for when a post is published.',
|
|
|
|
array(
|
2015-05-14 01:11:50 +02:00
|
|
|
'date' => $publishDate->Nice(),
|
2015-05-09 16:33:12 +02:00
|
|
|
)
|
|
|
|
) . $modifiedLabel;
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
return '';
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-08-11 00:34:46 +02:00
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
2015-05-09 16:33:12 +02:00
|
|
|
if($columnName == 'State') {
|
2015-05-14 01:11:50 +02:00
|
|
|
if($record instanceof BlogPost) {
|
2013-08-11 00:34:46 +02:00
|
|
|
$published = $record->isPublished();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
if(!$published) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$class = 'gridfield-icon draft';
|
|
|
|
} else if(strtotime($record->PublishDate) > time()) {
|
|
|
|
$class = 'gridfield-icon timer';
|
2013-08-11 00:34:46 +02:00
|
|
|
} else {
|
2015-05-09 16:33:12 +02:00
|
|
|
$class = 'gridfield-icon published';
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'class' => $class,
|
|
|
|
);
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
return array();
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
}
|