silverstripe-blog/code/forms/gridfield/GridFieldBlogPostState.php

95 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
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.
*
* @package silverstripe
* @subpackage blog
2015-05-09 16:33:12 +02:00
*/
class GridFieldBlogPostState extends GridFieldSiteTreeState {
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
public function getColumnContent($gridField, $record, $columnName) {
2015-05-09 16:33:12 +02:00
if($columnName == 'State') {
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 = '';
if($record->isModifiedOnStage) {
2015-05-09 16:33:12 +02:00
$modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>';
}
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');
return _t(
2015-05-09 16:33:12 +02:00
'GridFieldBlogPostState.Draft',
'<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.',
array(
2015-05-14 01:11:50 +02:00
'date' => $lastEdited->Nice(),
)
);
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()) {
return _t(
2015-05-09 16:33:12 +02:00
'GridFieldBlogPostState.Timer',
'<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.',
array(
2015-05-14 01:11:50 +02:00
'date' => $publishDate->Nice(),
)
) . $modifiedLabel;
}
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;
}
}
2015-05-09 16:33:12 +02:00
return '';
}
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
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) {
$published = $record->isPublished();
2015-05-09 16:33:12 +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';
} else {
2015-05-09 16:33:12 +02:00
$class = 'gridfield-icon published';
}
2015-05-09 16:33:12 +02:00
return array(
'class' => $class,
);
}
}
2015-05-09 16:33:12 +02:00
return array();
}
2015-05-09 16:33:12 +02:00
}