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

View File

@ -17,7 +17,7 @@ class BlogPostFilter extends DataExtension {
$stage = Versioned::current_stage(); $stage = Versioned::current_stage();
if($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) { 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 * @param mixed $parent
*/ */
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $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(); $objClass = $gridField->getModelClass();
/**
* @var DataObject $obj
*/
$obj = new $objClass(); $obj = new $objClass();
if($obj->hasField($dbField)) { if($obj->hasField($dbField)) {
@ -137,7 +140,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* @return string * @return string
*/ */
public function getHTMLFragments($gridField) { public function getHTMLFragments($gridField) {
$dataClass = $gridField->getList()->dataClass(); /**
* @var DataList $dataList
*/
$dataList = $gridField->getList();
$dataClass = $dataList->dataClass();
$obj = singleton($dataClass); $obj = singleton($dataClass);

View File

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

View File

@ -114,10 +114,6 @@ class Blog extends Page implements PermissionProvider {
return; return;
} }
if(!$fields) {
return null;
}
$categories = GridField::create( $categories = GridField::create(
'Categories', 'Categories',
_t('Blog.Categories', 'Categories'), _t('Blog.Categories', 'Categories'),
@ -455,15 +451,15 @@ class Blog extends Page implements PermissionProvider {
$stage = '_' . $stage; $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) { if($month) {
$query->where(sprintf('MONTH(PublishDate) = \'%s\'', Convert::raw2sql($month))); $query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
if($day) { 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; $self =& $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) { $this->beforeUpdateCMSFields(function ($fields) use ($self) {
/**
* @var FieldList $fields
*/
$summary = HtmlEditorField::create('Summary', false); $summary = HtmlEditorField::create('Summary', false);
$summary->setRows(5); $summary->setRows(5);
$summary->setDescription(_t( $summary->setDescription(_t(
@ -186,6 +182,9 @@ class BlogPost extends Page {
$summaryHolder->setHeadingLevel(4); $summaryHolder->setHeadingLevel(4);
$summaryHolder->addExtraClass('custom-summary'); $summaryHolder->addExtraClass('custom-summary');
/**
* @var FieldList $fields
*/
$fields->insertBefore($summaryHolder, 'Content'); $fields->insertBefore($summaryHolder, 'Content');
$uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));

View File

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

View File

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

View File

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

View File

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