mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
REFACTORING: Update SubsiteReportWrapper to use SSReportWrapper base class. (from r96273)
This commit is contained in:
parent
f511ceb0e4
commit
298534fea1
@ -4,19 +4,7 @@
|
||||
* Creates a subsite-aware version of another report.
|
||||
* Pass another report (or its classname) into the constructor.
|
||||
*/
|
||||
class SubsiteReportWrapper extends SSReport {
|
||||
protected $baseReport;
|
||||
|
||||
function __construct($baseReport) {
|
||||
$this->baseReport = is_string($baseReport) ? new $baseReport : $baseReport;
|
||||
$this->dataClass = $this->baseReport->dataClass();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function ID() {
|
||||
return get_class($this->baseReport) . '_subsite';
|
||||
}
|
||||
|
||||
class SubsiteReportWrapper extends SSReportWrapper {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Filtering
|
||||
|
||||
@ -32,7 +20,7 @@ class SubsiteReportWrapper extends SSReport {
|
||||
$subsiteField = $subsiteField->performReadonlyTransformation();
|
||||
}
|
||||
|
||||
$fields = $this->baseReport->parameterFields();
|
||||
$fields = parent::parameterFields();
|
||||
if($fields) {
|
||||
$fields->insertBefore($subsiteField, $fields->First()->Name());
|
||||
} else {
|
||||
@ -45,7 +33,7 @@ class SubsiteReportWrapper extends SSReport {
|
||||
// Columns
|
||||
|
||||
function columns() {
|
||||
$columns = $this->baseReport->columns();
|
||||
$columns = parent::columns();
|
||||
$columns['Subsite.Title'] = "Subsite";
|
||||
return $columns;
|
||||
}
|
||||
@ -70,44 +58,4 @@ class SubsiteReportWrapper extends SSReport {
|
||||
Subsite::$force_subsite = null;
|
||||
}
|
||||
|
||||
function sourceQuery($params) {
|
||||
if($this->baseReport->hasMethod('sourceRecords')) {
|
||||
// The default implementation will create a fake query from our sourceRecords() method
|
||||
return parent::sourceQuery($params);
|
||||
|
||||
} else if($this->baseReport->hasMethod('sourceQuery')) {
|
||||
$this->beforeQuery($params);
|
||||
$query = $this->baseReport->sourceQuery($params);
|
||||
$this->afterQuery();
|
||||
return $query;
|
||||
|
||||
} else {
|
||||
user_error("Please override sourceQuery()/sourceRecords() and columns() in your base report", E_USER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sourceRecords($params, $sort, $limit) {
|
||||
$this->beforeQuery($params);
|
||||
$records = $this->baseReport->sourceRecords($params, $sort, $limit);
|
||||
$this->afterQuery();
|
||||
return $records;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pass-through
|
||||
|
||||
function title() {
|
||||
return $this->baseReport->title();
|
||||
}
|
||||
|
||||
function description() {
|
||||
return $this->baseReport->title();
|
||||
}
|
||||
|
||||
function canView() {
|
||||
return $this->baseReport->canView();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user