2013-08-11 00:34:46 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-16 06:19:26 +01: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
|
|
|
|
*
|
|
|
|
* @author Michael Strong <github@michaelstrong.co.uk>
|
|
|
|
**/
|
2013-08-11 00:34:46 +02:00
|
|
|
class GridFieldBlogPostState implements GridField_ColumnProvider {
|
|
|
|
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
|
|
|
// Ensure Actions always appears as the last column.
|
|
|
|
$key = array_search("Actions", $columns);
|
|
|
|
if($key !== FALSE) unset($columns[$key]);
|
|
|
|
|
|
|
|
$columns = array_merge($columns, array(
|
|
|
|
"State",
|
|
|
|
"Actions",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnsHandled($gridField) {
|
|
|
|
return array("State");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
|
|
|
if($columnName == "State") {
|
|
|
|
if($record->hasMethod("isPublished")) {
|
2014-06-12 21:42:32 +02:00
|
|
|
$modifiedLabel = "";
|
2014-06-13 14:48:34 +02:00
|
|
|
if($record->isModifiedOnStage) {
|
2014-06-13 12:49:28 +02:00
|
|
|
$modifiedLabel = "<span class='modified'>" . _t("GridFieldBlogPostState.Modified") . "</span>";
|
2014-06-12 21:42:32 +02:00
|
|
|
}
|
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
$published = $record->isPublished();
|
|
|
|
if(!$published) {
|
2014-06-13 12:38:15 +02:00
|
|
|
return _t(
|
|
|
|
"GridFieldBlogPostState.Draft",
|
2014-06-12 19:49:01 +02:00
|
|
|
'<i class="btn-icon blog-icon btn-icon-pencil"></i> Saved as Draft on {date}',
|
2014-06-13 12:38:15 +02:00
|
|
|
"State for when a post is saved.",
|
|
|
|
array(
|
2014-06-12 19:49:01 +02:00
|
|
|
"date" => $record->dbObject("LastEdited")->Nice()
|
2014-06-13 12:38:15 +02:00
|
|
|
)
|
|
|
|
);
|
2013-08-11 00:34:46 +02:00
|
|
|
} else if (strtotime($record->PublishDate) > time()) {
|
|
|
|
return _t(
|
|
|
|
"GridFieldBlogPostState.Timer",
|
|
|
|
'<i class="blog-icon blog-icon-timer"></i> Publish at {date}',
|
2014-06-13 12:38:15 +02:00
|
|
|
"State for when a post is published.",
|
|
|
|
array(
|
2013-08-11 00:34:46 +02:00
|
|
|
"date" => $record->dbObject("PublishDate")->Nice()
|
|
|
|
)
|
2014-06-13 12:49:28 +02:00
|
|
|
) . $modifiedLabel;
|
2013-08-11 00:34:46 +02:00
|
|
|
} else {
|
|
|
|
return _t(
|
|
|
|
"GridFieldBlogPostState.Published",
|
|
|
|
'<i class="btn-icon blog-icon btn-icon-accept"></i> Published on {date}',
|
|
|
|
"State for when a post is published.",
|
|
|
|
array(
|
|
|
|
"date" => $record->dbObject("PublishDate")->Nice()
|
|
|
|
)
|
2014-06-13 12:49:28 +02:00
|
|
|
) . $modifiedLabel;
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
|
|
|
if($columnName == "State") {
|
|
|
|
if($record->hasMethod("isPublished")) {
|
|
|
|
$published = $record->isPublished();
|
|
|
|
if(!$published) {
|
|
|
|
$class = "blog-icon draft";
|
|
|
|
} else if (strtotime($record->PublishDate) > time()) {
|
|
|
|
$class = "blog-icon timer";
|
|
|
|
} else {
|
|
|
|
$class = "blog-icon published";
|
|
|
|
}
|
|
|
|
return array("class" => $class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnMetaData($gridField, $columnName) {
|
|
|
|
switch($columnName) {
|
|
|
|
case 'State':
|
|
|
|
return array("title" => _t("GridFieldBlogPostState.StateTitle", "State", "Column title for state"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-13 14:48:34 +02:00
|
|
|
}
|