2013-07-21 12:23:35 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-16 06:19:26 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* This is responsible for filtering only published posts to users who do not have permission to
|
|
|
|
* view non-published posts.
|
2014-02-16 06:19:26 +01:00
|
|
|
*
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
class BlogPostFilter extends DataExtension {
|
2013-07-21 12:23:35 +02:00
|
|
|
/**
|
2013-08-04 18:38:26 +02:00
|
|
|
* Augment queries so that we don't fetch unpublished articles.
|
2015-05-09 16:33:12 +02:00
|
|
|
*
|
|
|
|
* @param SQLQuery $query
|
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
public function augmentSQL(SQLQuery &$query) {
|
2014-11-13 10:06:48 +01:00
|
|
|
$stage = Versioned::current_stage();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
if($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) {
|
2015-05-14 01:11:50 +02:00
|
|
|
$query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
2014-11-13 10:06:48 +01:00
|
|
|
}
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 17:22:13 +02:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* This is a fix so that when we try to fetch subclasses of BlogPost, lazy loading includes the
|
|
|
|
* BlogPost table in its query. Leaving this table out means the default sort order column
|
|
|
|
* PublishDate causes an error.
|
2014-02-16 06:19:26 +01:00
|
|
|
*
|
|
|
|
* @see https://github.com/silverstripe/silverstripe-framework/issues/1682
|
2015-05-09 16:33:12 +02:00
|
|
|
*
|
|
|
|
* @param SQLQuery $query
|
|
|
|
* @param mixed $dataQuery
|
|
|
|
* @param mixed $parent
|
|
|
|
*/
|
2013-08-23 17:22:13 +02:00
|
|
|
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent) {
|
2015-05-14 01:11:50 +02:00
|
|
|
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
|
2013-08-23 17:22:13 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
}
|