Merge pull request #236 from assertchris/clean-up

Clean up
This commit is contained in:
Damian Mooyman 2015-05-14 11:35:56 +12:00
commit 76331a6ee0
10 changed files with 43 additions and 51 deletions

View File

@ -24,8 +24,8 @@ class BlogFilter extends Lumberjack {
}
$dataQuery = $staged->dataQuery()
->innerJoin('BlogPost', sprintf('BlogPost%s.ID = SiteTree%s.ID', $stage, $stage))
->where(sprintf('PublishDate < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
->innerJoin('BlogPost', sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage))
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
$staged = $staged->setDataQuery($dataQuery);
}
@ -48,8 +48,8 @@ class BlogFilter extends Lumberjack {
if(!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
$dataQuery = $staged->dataQuery()
->innerJoin('BlogPost', 'BlogPost_Live.ID = SiteTree_Live.ID')
->where(sprintf('PublishDate < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
->innerJoin('BlogPost', '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"')
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
$staged = $staged->setDataQuery($dataQuery);
}
@ -74,7 +74,7 @@ class BlogFilter extends Lumberjack {
$pages = SiteTree::get()->filter(array(
'ParentID' => $this->owner->ID,
'ClassName' => $excluded
))->sort('SiteTree.Created DESC');
))->sort('"SiteTree"."Created" DESC');
$gridField = new BlogFilter_GridField(
'ChildPages',

View File

@ -17,7 +17,7 @@ class BlogPostFilter extends DataExtension {
$stage = Versioned::current_stage();
if($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) {
$query->addWhere(sprintf('PublishDate < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
$query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
}
}
@ -33,6 +33,6 @@ class BlogPostFilter extends DataExtension {
* @param mixed $parent
*/
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent) {
$dataQuery->innerJoin('BlogPost', 'SiteTree.ID = BlogPost.ID');
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
}
}

View File

@ -64,6 +64,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$objClass = $gridField->getModelClass();
/**
* @var DataObject $obj
*/
$obj = new $objClass();
if($obj->hasField($dbField)) {
@ -137,7 +140,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* @return string
*/
public function getHTMLFragments($gridField) {
$dataClass = $gridField->getList()->dataClass();
/**
* @var DataList $dataList
*/
$dataList = $gridField->getList();
$dataClass = $dataList->dataClass();
$obj = singleton($dataClass);

View File

@ -14,8 +14,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
public function getColumnContent($gridField, $record, $columnName) {
if($columnName == 'State') {
Requirements::css(BLOGGER_DIR . '/css/cms.css');
if($record->hasMethod('isPublished')) {
if($record instanceof BlogPost) {
$modifiedLabel = '';
if($record->isModifiedOnStage) {
@ -23,23 +22,33 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
}
if(!$record->isPublished()) {
/**
* @var SS_Datetime $lastEdited
*/
$lastEdited = $record->dbObject('LastEdited');
return _t(
'GridFieldBlogPostState.Draft',
'<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
'State for when a post is saved.',
array(
'date' => $record->dbObject('LastEdited')->Nice(),
'date' => $lastEdited->Nice(),
)
);
}
/**
* @var SS_Datetime $publishDate
*/
$publishDate = $record->dbObject('PublishDate');
if(strtotime($record->PublishDate) > time()) {
return _t(
'GridFieldBlogPostState.Timer',
'<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}',
'State for when a post is published.',
array(
'date' => $record->dbObject('PublishDate')->Nice(),
'date' => $publishDate->Nice(),
)
) . $modifiedLabel;
}
@ -49,7 +58,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
'<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
'State for when a post is published.',
array(
'date' => $record->dbObject('PublishDate')->Nice(),
'date' => $publishDate->Nice(),
)
) . $modifiedLabel;
}
@ -63,7 +72,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
*/
public function getColumnAttributes($gridField, $record, $columnName) {
if($columnName == 'State') {
if($record->hasMethod('isPublished')) {
if($record instanceof BlogPost) {
$published = $record->isPublished();
if(!$published) {

View File

@ -114,10 +114,6 @@ class Blog extends Page implements PermissionProvider {
return;
}
if(!$fields) {
return null;
}
$categories = GridField::create(
'Categories',
_t('Blog.Categories', 'Categories'),
@ -455,15 +451,15 @@ class Blog extends Page implements PermissionProvider {
$stage = '_' . $stage;
}
$query->innerJoin('BlogPost', sprintf('SiteTree%s.ID = BlogPost%s.ID', $stage, $stage));
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
$query->where(sprintf('YEAR(PublishDate) = \'%s\'', Convert::raw2sql($year)));
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
if($month) {
$query->where(sprintf('MONTH(PublishDate) = \'%s\'', Convert::raw2sql($month)));
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
if($day) {
$query->where(sprintf('DAY(PublishDate) = \'%s\'', Convert::raw2sql($day)));
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
}
}

View File

@ -165,10 +165,6 @@ class BlogPost extends Page {
$self =& $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
/**
* @var FieldList $fields
*/
$summary = HtmlEditorField::create('Summary', false);
$summary->setRows(5);
$summary->setDescription(_t(
@ -186,6 +182,9 @@ class BlogPost extends Page {
$summaryHolder->setHeadingLevel(4);
$summaryHolder->addExtraClass('custom-summary');
/**
* @var FieldList $fields
*/
$fields->insertBefore($summaryHolder, 'Content');
$uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));

View File

@ -55,10 +55,6 @@ class BlogArchiveWidget extends Widget {
$self =& $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
if (!$fields) {
return;
}
/**
* @var Enum $archiveType
*/
@ -92,9 +88,9 @@ class BlogArchiveWidget extends Widget {
$query = $this->Blog()->getBlogPosts()->dataQuery();
if($this->ArchiveType == 'Yearly') {
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y\')');
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')');
} else {
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y-%M\')');
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')');
}
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);

View File

@ -40,10 +40,6 @@ class BlogCategoriesWidget extends Widget {
*/
public function getCMSFields() {
$this->beforeUpdateCMSFields(function ($fields) {
if (!$fields) {
return;
}
/**
* @var FieldList $fields
*/
@ -59,9 +55,7 @@ class BlogCategoriesWidget extends Widget {
* @return array
*/
public function getCategories() {
$blog = $this->Blog();
if($blog) {
if($blog = $this->Blog()) {
return $blog->Categories();
}

View File

@ -44,10 +44,6 @@ class BlogRecentPostsWidget extends Widget {
*/
public function getCMSFields() {
$this->beforeUpdateCMSFields(function ($fields) {
if (!$fields) {
return;
}
/**
* @var FieldList $fields
*/
@ -68,7 +64,7 @@ class BlogRecentPostsWidget extends Widget {
if($blog) {
return $blog->getBlogPosts()
->sort('PublishDate DESC')
->sort('"PublishDate" DESC')
->limit($this->NumberOfPosts);
}

View File

@ -40,10 +40,6 @@ class BlogTagsWidget extends Widget {
*/
public function getCMSFields() {
$this->beforeUpdateCMSFields(function ($fields) {
if (!$fields) {
return;
}
/**
* @var FieldList $fields
*/
@ -59,9 +55,7 @@ class BlogTagsWidget extends Widget {
* @return array
*/
public function getTags() {
$blog = $this->Blog();
if($blog) {
if($blog = $this->Blog()) {
return $blog->Tags();
}