Skip to content

Commit

Permalink
Merge pull request #220 from tractorcow/psr-2
Browse files Browse the repository at this point in the history
Reformat for psr-2
  • Loading branch information
dhensby committed Nov 24, 2015
2 parents 5f02e0c + a0ede56 commit a4c925b
Show file tree
Hide file tree
Showing 30 changed files with 3,789 additions and 3,477 deletions.
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
CMSPagesController::add_extension('SubsiteMenuExtension');
SubsiteAdmin::add_extension('SubsiteMenuExtension');
CMSSettingsController::add_extension('SubsiteMenuExtension');

40 changes: 20 additions & 20 deletions code/SubsiteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
*
* @package subsites
*/
class SubsiteAdmin extends ModelAdmin {
private static $managed_models = array('Subsite');
class SubsiteAdmin extends ModelAdmin
{
private static $managed_models = array('Subsite');

private static $url_segment = 'subsites';
private static $menu_title = "Subsites";
private static $url_segment = 'subsites';
private static $menu_title = "Subsites";

private static $menu_icon = "subsites/images/subsites.png";
public $showImportForm=false;
private static $menu_icon = "subsites/images/subsites.png";
public $showImportForm=false;

private static $tree_class = 'Subsite';
private static $tree_class = 'Subsite';

public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);

$grid=$form->Fields()->dataFieldByName('Subsite');
if($grid) {
$grid->getConfig()->removeComponentsByType('GridFieldDetailForm');
$grid->getConfig()->addComponent(new GridFieldSubsiteDetailForm());
}

return $form;
}
$grid=$form->Fields()->dataFieldByName('Subsite');
if ($grid) {
$grid->getConfig()->removeComponentsByType('GridFieldDetailForm');
$grid->getConfig()->addComponent(new GridFieldSubsiteDetailForm());
}

return $form;
}
}
118 changes: 61 additions & 57 deletions code/SubsiteReportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,66 @@
* Creates a subsite-aware version of another report.
* Pass another report (or its classname) into the constructor.
*/
class SubsiteReportWrapper extends SS_ReportWrapper {
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering

function parameterFields() {
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
$options = $subsites->toDropdownMap('ID', 'Title');

$subsiteField = new TreeMultiselectField(
'Subsites',
_t('SubsiteReportWrapper.ReportDropdown', 'Sites'),
$options
);
$subsiteField->setValue(array_keys($options));
class SubsiteReportWrapper extends SS_ReportWrapper
{
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering

// 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();
if($fields) {
$fields->insertBefore($subsiteField, $fields->First()->Name());
} else {
$fields = new FieldList($subsiteField);
}
return $fields;
}
public function parameterFields()
{
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
$options = $subsites->toDropdownMap('ID', 'Title');

$subsiteField = new TreeMultiselectField(
'Subsites',
_t('SubsiteReportWrapper.ReportDropdown', 'Sites'),
$options
);
$subsiteField->setValue(array_keys($options));

///////////////////////////////////////////////////////////////////////////////////////////
// Columns

function columns() {
$columns = parent::columns();
$columns['Subsite.Title'] = "Subsite";
return $columns;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Querying

function beforeQuery($params) {
// The user has select a few specific sites
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));
}
}
function afterQuery() {
// Manually manage the subsite filtering
Subsite::$force_subsite = null;
}

}
// 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();
if ($fields) {
$fields->insertBefore($subsiteField, $fields->First()->Name());
} else {
$fields = new FieldList($subsiteField);
}
return $fields;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Columns

public function columns()
{
$columns = parent::columns();
$columns['Subsite.Title'] = "Subsite";
return $columns;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Querying

public function beforeQuery($params)
{
// The user has select a few specific sites
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));
}
}
public function afterQuery()
{
// Manually manage the subsite filtering
Subsite::$force_subsite = null;
}
}
87 changes: 48 additions & 39 deletions code/SubsiteXHRController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,52 @@
/**
* Section-agnostic PJAX controller.
*/
class SubsiteXHRController extends LeftAndMain {

/**
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
*/
public function canView($member = null) {
if (parent::canView()) return true;

if (Subsite::all_accessible_sites()->count()>0) return true;

return false;
}

/**
* Similar as above, but for the LeftAndMainSubsites - allow access if user allowed into the CMS at all.
*/
public function canAccess() {
if (Subsite::all_accessible_sites()->count()>0) return true;
}

public function getResponseNegotiator() {
$negotiator = parent::getResponseNegotiator();
$self = $this;

// Register a new callback
$negotiator->setCallback('SubsiteList', function() use(&$self) {
return $self->SubsiteList();
});

return $negotiator;
}

/**
* Provide the list of available subsites as a cms-section-agnostic PJAX handler.
*/
public function SubsiteList() {
return $this->renderWith('SubsiteList');
}

class SubsiteXHRController extends LeftAndMain
{
/**
* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
*/
public function canView($member = null)
{
if (parent::canView()) {
return true;
}

if (Subsite::all_accessible_sites()->count()>0) {
return true;
}

return false;
}

/**
* Similar as above, but for the LeftAndMainSubsites - allow access if user allowed into the CMS at all.
*/
public function canAccess()
{
if (Subsite::all_accessible_sites()->count()>0) {
return true;
}
}

public function getResponseNegotiator()
{
$negotiator = parent::getResponseNegotiator();
$self = $this;

// Register a new callback
$negotiator->setCallback('SubsiteList', function () use (&$self) {
return $self->SubsiteList();
});

return $negotiator;
}

/**
* Provide the list of available subsites as a cms-section-agnostic PJAX handler.
*/
public function SubsiteList()
{
return $this->renderWith('SubsiteList');
}
}
Loading

0 comments on commit a4c925b

Please sign in to comment.