silverstripe-subsites/code/SubsiteReportWrapper.php

69 lines
1.9 KiB
PHP
Raw Normal View History

2010-03-01 22:56:32 +01:00
<?php
2016-09-22 16:38:29 +02:00
use SilverStripe\Forms\TreeMultiselectField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Reports\ReportWrapper;
2010-03-01 22:56:32 +01:00
/**
* Creates a subsite-aware version of another report.
* Pass another report (or its classname) into the constructor.
*/
2016-09-22 16:38:29 +02:00
class SubsiteReportWrapper extends ReportWrapper {
2010-03-01 22:56:32 +01:00
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering
function parameterFields() {
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
2010-03-01 22:56:32 +01:00
$options = $subsites->toDropdownMap('ID', 'Title');
2013-10-30 13:43:59 +01:00
$subsiteField = new TreeMultiselectField(
'Subsites',
_t('SubsiteReportWrapper.ReportDropdown', 'Sites'),
$options
);
$subsiteField->setValue(array_keys($options));
2010-03-01 22:56:32 +01:00
// We don't need to make the field editable if only one subsite is available
if(sizeof($options) <= 1) {
$subsiteField = $subsiteField->performReadonlyTransformation();
}
$fields = parent::parameterFields();
2010-03-01 22:56:32 +01:00
if($fields) {
$fields->insertBefore($subsiteField, $fields->First()->Name());
} else {
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
2012-03-25 18:35:01 +02:00
$fields = new FieldList($subsiteField);
2010-03-01 22:56:32 +01:00
}
return $fields;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Columns
function columns() {
$columns = parent::columns();
2010-03-01 22:56:32 +01:00
$columns['Subsite.Title'] = "Subsite";
return $columns;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Querying
function beforeQuery($params) {
// The user has select a few specific sites
2010-03-01 22:56:32 +01:00
if(!empty($params['Subsites'])) {
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;
}
}