mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #446 from creative-commoners/issue/ss-widgets/144
FIX select list not in group-by clause error
This commit is contained in:
commit
619df86693
@ -84,52 +84,47 @@ class BlogArchiveWidget extends Widget
|
|||||||
/**
|
/**
|
||||||
* Returns a list of months where blog posts are present.
|
* Returns a list of months where blog posts are present.
|
||||||
*
|
*
|
||||||
* @return DataList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
public function getArchive()
|
public function getArchive()
|
||||||
{
|
{
|
||||||
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
$format = ($this->ArchiveType == 'Yearly') ? '%Y' : '%Y-%m';
|
||||||
|
$publishDate = DB::get_conn()->formattedDatetimeClause('"PublishDate"', $format);
|
||||||
|
$fields = array(
|
||||||
|
'PublishDate' => $publishDate,
|
||||||
|
'Total' => "Count('PublishDate')"
|
||||||
|
);
|
||||||
|
|
||||||
if ($this->ArchiveType == 'Yearly') {
|
$stage = Versioned::current_stage();
|
||||||
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')');
|
$suffix = ($stage == 'Stage') ? '' : "_{$stage}";
|
||||||
} else {
|
$query = SQLSelect::create($fields, "BlogPost{$suffix}")
|
||||||
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')');
|
->addGroupBy($publishDate)
|
||||||
}
|
->addOrderBy('PublishDate Desc')
|
||||||
|
->addWhere(array('PublishDate < ?' => SS_Datetime::now()->Format('Y-m-d')));
|
||||||
|
|
||||||
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
$posts = $query->execute();
|
||||||
|
$result = new ArrayList();
|
||||||
|
while ($next = $posts->next()) {
|
||||||
|
$date = Date::create();
|
||||||
|
$date->setValue(strtotime($next['PublishDate']));
|
||||||
|
$year = $date->Format('Y');
|
||||||
|
|
||||||
if ($this->NumberToDisplay > 0) {
|
if ($this->ArchiveType == 'Yearly') {
|
||||||
$posts = $posts->limit($this->NumberToDisplay);
|
$month = null;
|
||||||
}
|
$title = $year;
|
||||||
|
} else {
|
||||||
$archive = new ArrayList();
|
$month = $date->Format('m');
|
||||||
|
$title = $date->FormatI18N('%B %Y');
|
||||||
if ($posts->count() > 0) {
|
|
||||||
foreach ($posts as $post) {
|
|
||||||
/**
|
|
||||||
* @var BlogPost $post
|
|
||||||
*/
|
|
||||||
$date = Date::create();
|
|
||||||
$date->setValue($post->PublishDate);
|
|
||||||
|
|
||||||
if ($this->ArchiveType == 'Yearly') {
|
|
||||||
$year = $date->Format("Y");
|
|
||||||
$month = null;
|
|
||||||
$title = $year;
|
|
||||||
} else {
|
|
||||||
$year = $date->Format("Y");
|
|
||||||
$month = $date->Format("m");
|
|
||||||
$title = $date->FormatI18N("%B %Y");
|
|
||||||
}
|
|
||||||
|
|
||||||
$archive->push(new ArrayData(array(
|
|
||||||
'Title' => $title,
|
|
||||||
'Link' => Controller::join_links($this->Blog()->Link('archive'), $year, $month)
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result->push(new ArrayData(array(
|
||||||
|
'Title' => $title,
|
||||||
|
'Link' => Controller::join_links($this->Blog()->Link('archive'), $year, $month)
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $archive;
|
$this->extend('updateGetArchive', $result);
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user