2013-08-04 18:38:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-16 06:19:26 +01:00
|
|
|
* This class is responsible for filtering the SiteTree when necessary and also
|
|
|
|
* overlaps into filtering only published posts.
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
|
|
|
*
|
2014-02-16 06:19:26 +01:00
|
|
|
* @author Michael Strong <github@michaelstrong.co.uk>
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
|
|
|
**/
|
2014-12-11 11:42:36 +01:00
|
|
|
class BlogFilter extends Lumberjack {
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Augments (@link Hierarchy::stageChildren()}
|
|
|
|
*
|
|
|
|
* @param $staged DataList
|
|
|
|
* @param $showAll boolean
|
|
|
|
**/
|
|
|
|
public function stageChildren($showAll = false) {
|
|
|
|
$staged = parent::stageChildren($showAll);
|
|
|
|
|
2014-12-11 11:42:36 +01:00
|
|
|
if(!$this->shouldFilter()
|
|
|
|
&& in_array(get_class($this->owner), ClassInfo::subClassesFor("Blog"))
|
2014-02-16 06:19:26 +01:00
|
|
|
&& !Permission::check("VIEW_DRAFT_CONTENT")
|
|
|
|
) {
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
// Get the current stage.
|
|
|
|
$stage = Versioned::current_stage();
|
|
|
|
if($stage == "Stage") $stage = "";
|
|
|
|
else $stage = "_" . Convert::raw2sql($stage);
|
|
|
|
|
2014-02-16 06:19:26 +01:00
|
|
|
// Filter published posts
|
2013-08-04 18:38:26 +02:00
|
|
|
$dataQuery = $staged->dataQuery()
|
2014-12-11 11:42:36 +01:00
|
|
|
->innerJoin("BlogPost", '"BlogPost' . $stage . '"."ID" = "SiteTree' . $stage . '"."ID"')
|
|
|
|
->where('"PublishDate" < \'' . Convert::raw2sql(SS_Datetime::now()) . '\'');
|
2013-08-04 18:38:26 +02:00
|
|
|
$staged = $staged->setDataQuery($dataQuery);
|
|
|
|
}
|
|
|
|
return $staged;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Augments (@link Hierarchy::liveChildren()}
|
|
|
|
*
|
|
|
|
* @param $staged DataList
|
|
|
|
* @param $showAll boolean
|
|
|
|
**/
|
|
|
|
public function liveChildren($showAll = false, $onlyDeletedFromStage = false) {
|
|
|
|
$staged = parent::liveChildren($showAll, $onlyDeletedFromStage);
|
|
|
|
|
2014-12-11 11:42:36 +01:00
|
|
|
if(!$this->shouldFilter()
|
|
|
|
&& in_array(get_class($this->owner), ClassInfo::subClassesFor("Blog"))
|
2014-02-16 06:19:26 +01:00
|
|
|
&& !Permission::check("VIEW_DRAFT_CONTENT")
|
|
|
|
) {
|
|
|
|
// Filter publish posts
|
2013-08-04 18:38:26 +02:00
|
|
|
$dataQuery = $staged->dataQuery()
|
2014-12-11 11:42:36 +01:00
|
|
|
->innerJoin("BlogPost", '"BlogPost_Live"."ID" = "SiteTree"_"Live"."ID"')
|
|
|
|
->where('"PublishDate" < \'' . Convert::raw2sql(SS_Datetime::now()) . '\'');
|
2013-08-04 18:38:26 +02:00
|
|
|
$staged = $staged->setDataQuery($dataQuery);
|
|
|
|
}
|
|
|
|
return $staged;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|