2010-03-01 22:56:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a subsite-aware version of another report.
|
|
|
|
* Pass another report (or its classname) into the constructor.
|
|
|
|
*/
|
2010-03-01 22:56:49 +01:00
|
|
|
class SubsiteReportWrapper extends SSReportWrapper {
|
2010-03-01 22:56:32 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Filtering
|
|
|
|
|
|
|
|
function parameterFields() {
|
|
|
|
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
|
|
|
|
$options = $subsites->toDropdownMap('ID', 'Title');
|
2010-03-01 22:56:37 +01:00
|
|
|
|
2010-03-01 22:56:32 +01:00
|
|
|
$subsiteField = new TreeMultiselectField('Subsites', 'Sites', $options);
|
2010-03-01 22:56:37 +01:00
|
|
|
$subsiteField->setValue(array_keys($options));
|
2010-03-01 22:56:32 +01:00
|
|
|
|
2010-03-01 22:56:37 +01:00
|
|
|
// We don't need to make the field editable if only one subsite is available
|
|
|
|
if(sizeof($options) <= 1) {
|
|
|
|
$subsiteField = $subsiteField->performReadonlyTransformation();
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:56:49 +01:00
|
|
|
$fields = parent::parameterFields();
|
2010-03-01 22:56:32 +01:00
|
|
|
if($fields) {
|
|
|
|
$fields->insertBefore($subsiteField, $fields->First()->Name());
|
|
|
|
} else {
|
|
|
|
$fields = new FieldSet($subsiteField);
|
|
|
|
}
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Columns
|
|
|
|
|
|
|
|
function columns() {
|
2010-03-01 22:56:49 +01:00
|
|
|
$columns = parent::columns();
|
2010-03-01 22:56:32 +01:00
|
|
|
$columns['Subsite.Title'] = "Subsite";
|
|
|
|
return $columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Querying
|
|
|
|
|
|
|
|
function beforeQuery($params) {
|
2010-03-01 22:56:37 +01:00
|
|
|
// The user has select a few specific sites
|
2010-03-01 22:56:32 +01:00
|
|
|
if(!empty($params['Subsites'])) {
|
2010-03-01 22:56:37 +01:00
|
|
|
Subsite::$force_subsite = $params['Subsites'];
|
|
|
|
|
|
|
|
// Default: restrict to all accessible sites
|
|
|
|
} else {
|
|
|
|
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
|
|
|
|
$options = $subsites->toDropdownMap('ID', 'Title');
|
|
|
|
Subsite::$force_subsite = join(',', array_keys($options));
|
2010-03-01 22:56:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function afterQuery() {
|
|
|
|
// Manually manage the subsite filtering
|
|
|
|
Subsite::$force_subsite = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|