silverstripe-blog/forms/gridfield/GridFieldBlogPostState.php

72 lines
2.1 KiB
PHP
Executable File

<?php
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")) {
$published = $record->isPublished();
if(!$published) {
return _t("GridFieldBlogPostState.Draft", '<i class="btn-icon blog-icon btn-icon-pencil"></i> Saved as Draft');
} else if (strtotime($record->PublishDate) > time()) {
return _t(
"GridFieldBlogPostState.Timer",
'<i class="blog-icon blog-icon-timer"></i> Publish at {date}',
"State for when a post is published.", array(
"date" => $record->dbObject("PublishDate")->Nice()
)
);
} 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()
)
);
}
}
}
}
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"));
}
}
}