2015-11-21 07:17:29 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
namespace SilverStripe\Blog\Forms\GridField;
|
|
|
|
|
|
|
|
use SilverStripe\Blog\Model\BlogPost;
|
2017-09-14 00:44:21 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState;
|
2018-01-24 04:28:12 +01:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
/**
|
|
|
|
* Provides a component to the {@link GridField} which tells the user whether or not a blog post
|
|
|
|
* has been published and when.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class GridFieldBlogPostState extends GridFieldSiteTreeState
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName)
|
|
|
|
{
|
|
|
|
if ($columnName == 'State') {
|
2018-01-24 04:28:12 +01:00
|
|
|
Requirements::css('silverstripe/blog:css/cms.css');
|
2015-11-21 07:17:29 +01:00
|
|
|
if ($record instanceof BlogPost) {
|
|
|
|
$modifiedLabel = '';
|
|
|
|
|
|
|
|
if ($record->isModifiedOnStage) {
|
2017-09-14 00:27:40 +02:00
|
|
|
$modifiedLabel = '<span class="modified">' . _t(__CLASS__ . '.Modified') . '</span>';
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$record->isPublished()) {
|
|
|
|
/**
|
2018-01-24 04:28:12 +01:00
|
|
|
* @var DBDatetime $lastEdited
|
2015-11-21 07:17:29 +01:00
|
|
|
*/
|
|
|
|
$lastEdited = $record->dbObject('LastEdited');
|
|
|
|
|
2018-01-24 04:28:12 +01:00
|
|
|
return '<i class="font-icon-edit mr-2"></i> ' . _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
__CLASS__ . '.Draft',
|
2017-09-18 05:27:39 +02:00
|
|
|
'Saved as Draft on {date}',
|
2015-11-21 07:17:29 +01:00
|
|
|
'State for when a post is saved.',
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-03-04 20:31:22 +01:00
|
|
|
'date' => $lastEdited->FormatFromSettings(),
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-24 04:28:12 +01:00
|
|
|
* @var DBDatetime $publishDate
|
2015-11-21 07:17:29 +01:00
|
|
|
*/
|
|
|
|
$publishDate = $record->dbObject('PublishDate');
|
|
|
|
|
|
|
|
if (strtotime($record->PublishDate) > time()) {
|
2018-01-24 20:46:05 +01:00
|
|
|
return '<i class="font-icon-clock mr-2"></i> ' . _t(
|
2017-09-14 00:59:01 +02:00
|
|
|
__CLASS__ . '.Timer',
|
2017-09-18 05:27:39 +02:00
|
|
|
'Publish at {date}',
|
2015-11-21 07:17:29 +01:00
|
|
|
'State for when a post is published.',
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-03-04 20:31:22 +01:00
|
|
|
'date' => $publishDate->FormatFromSettings(),
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2015-11-21 07:17:29 +01:00
|
|
|
) . $modifiedLabel;
|
|
|
|
}
|
|
|
|
|
2018-01-24 04:28:12 +01:00
|
|
|
return '<i class="font-icon-check-mark-circle text-success mr-2"></i> ' . _t(
|
2017-09-14 00:59:01 +02:00
|
|
|
__CLASS__ . '.Published',
|
2017-09-18 05:27:39 +02:00
|
|
|
'Published on {date}',
|
2015-11-21 07:17:29 +01:00
|
|
|
'State for when a post is published.',
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-03-04 20:31:22 +01:00
|
|
|
'date' => $publishDate->FormatFromSettings(),
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2015-11-21 07:17:29 +01:00
|
|
|
) . $modifiedLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName)
|
|
|
|
{
|
|
|
|
if ($columnName == 'State') {
|
|
|
|
if ($record instanceof BlogPost) {
|
|
|
|
$published = $record->isPublished();
|
|
|
|
|
|
|
|
if (!$published) {
|
|
|
|
$class = 'gridfield-icon draft';
|
|
|
|
} elseif (strtotime($record->PublishDate) > time()) {
|
|
|
|
$class = 'gridfield-icon timer';
|
|
|
|
} else {
|
|
|
|
$class = 'gridfield-icon published';
|
|
|
|
}
|
|
|
|
|
2017-09-14 00:59:01 +02:00
|
|
|
return [
|
2015-11-21 07:17:29 +01:00
|
|
|
'class' => $class,
|
2017-09-14 00:59:01 +02:00
|
|
|
];
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-14 00:59:01 +02:00
|
|
|
return [];
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
}
|