Upgrade code for namespaces

Apply SilverStripe\Reports namespace
This commit is contained in:
Damian Mooyman 2016-08-29 13:55:43 +12:00
parent f759a7c6db
commit bd17cca223
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
12 changed files with 243 additions and 233 deletions

View File

@ -10,8 +10,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[{*.yml,package.json}]
[*.{yml,js,json,css,scss,eslintrc}]
indent_size = 2
indent_style = space
# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516

6
.upgrade.yml Normal file
View File

@ -0,0 +1,6 @@
mappings:
SS_Report: SilverStripe\Reports\SS_Report
SS_ReportWrapper: SilverStripe\Reports\SS_ReportWrapper
ReportAdmin: SilverStripe\Reports\ReportAdmin
SideReportView: SilverStripe\Reports\SideReportView
SideReportWrapper: SilverStripe\Reports\SideReportWrapper

View File

@ -1,9 +1,28 @@
<?php
namespace SilverStripe\Reports;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Control\Controller;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Core\Convert;
use SilverStripe\View\ViewableData;
use ReflectionClass;
/**
* Base "abstract" class creating reports on your data.
@ -32,8 +51,6 @@ use SilverStripe\Security\Permission;
*
* Right now, all subclasses of SS_Report will be shown in the ReportAdmin. In SS3 there is only
* one place where reports can go, so this class is greatly simplifed from its version in SS2.
*
* @package reports
*/
class SS_Report extends ViewableData
{
@ -71,9 +88,9 @@ class SS_Report extends ViewableData
* @var array
*/
public static $excluded_reports = array(
'SS_Report',
'SS_ReportWrapper',
'SideReportWrapper',
'SilverStripe\\Reports\\SS_Report',
'SilverStripe\\Reports\\SS_ReportWrapper',
'SilverStripe\\Reports\\SideReportWrapper',
);
/**
@ -325,7 +342,7 @@ class SS_Report extends ViewableData
new GridFieldPaginator()
);
$gridField = new GridField('Report', null, $items, $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
$displayFields = array();
$fieldCasting = array();
$fieldFormatting = array();
@ -426,121 +443,3 @@ class SS_Report extends ViewableData
return $this->title();
}
}
/**
* SS_ReportWrapper is a base class for creating report wappers.
*
* Wrappers encapsulate an existing report to alter their behaviour - they are implementations of
* the standard GoF decorator pattern.
*
* This base class ensure that, by default, wrappers behave in the same way as the report that is
* being wrapped. You should override any methods that need to behave differently in your subclass
* of SS_ReportWrapper.
*
* It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and
* {@link afterQuery()}
*
* @package reports
*/
abstract class SS_ReportWrapper extends SS_Report
{
protected $baseReport;
public function __construct($baseReport)
{
$this->baseReport = is_string($baseReport) ? new $baseReport : $baseReport;
$this->dataClass = $this->baseReport->dataClass();
parent::__construct();
}
public function ID()
{
return get_class($this->baseReport) . '_' . get_class($this);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering
public function parameterFields()
{
return $this->baseReport->parameterFields();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Columns
public function columns()
{
return $this->baseReport->columns();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Querying
/**
* Override this method to perform some actions prior to querying.
*/
public function beforeQuery($params)
{
}
/**
* Override this method to perform some actions after querying.
*/
public function afterQuery()
{
}
public function sourceQuery($params)
{
if ($this->baseReport->hasMethod('sourceRecords')) {
// The default implementation will create a fake query from our sourceRecords() method
return parent::sourceQuery($params);
} elseif ($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);
}
}
public function sourceRecords($params = array(), $sort = null, $limit = null)
{
$this->beforeQuery($params);
$records = $this->baseReport->sourceRecords($params, $sort, $limit);
$this->afterQuery();
return $records;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Pass-through
public function title()
{
return $this->baseReport->title();
}
public function group()
{
/** @skipUpgrade */
return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group';
}
public function sort()
{
return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0;
}
public function description()
{
return $this->baseReport->description();
}
public function canView($member = null)
{
return $this->baseReport->canView($member);
}
}

View File

@ -1,10 +1,25 @@
<?php
namespace SilverStripe\Reports;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldFooter;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
/**
* Reports section of the CMS.
@ -12,10 +27,6 @@ use SilverStripe\Admin\LeftAndMain;
* All reports that should show in the ReportAdmin section
* of the CMS need to subclass {@link SS_Report}, and implement
* the appropriate methods and variables that are required.
*
* @see SS_Report
*
* @package reports
*/
class ReportAdmin extends LeftAndMain implements PermissionProvider
{
@ -25,7 +36,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
private static $template_path = null; // defaults to (project)/templates/email
private static $tree_class = 'SS_Report';
private static $tree_class = 'SilverStripe\\Reports\\SS_Report';
private static $url_handlers = array(
'show/$ReportClass/$Action' => 'handleAction'
@ -160,7 +171,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
// The root element should explicitly point to the root node.
// Uses session state for current record otherwise.
$items[0]->Link = singleton('ReportAdmin')->Link();
$items[0]->Link = singleton('SilverStripe\\Reports\\ReportAdmin')->Link();
if ($this->reportObject) {
//build breadcrumb trail to the current report
@ -217,7 +228,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
);
$gridField = new GridField('Reports', false, $this->Reports(), $gridFieldConfig);
/** @var GridFieldDataColumns $columns */
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
$columns->setDisplayFields(array(
'title' => _t('ReportAdmin.ReportTitle', 'Title'),
));

119
code/SS_ReportWrapper.php Normal file
View File

@ -0,0 +1,119 @@
<?php
namespace SilverStripe\Reports;
/**
* SS_ReportWrapper is a base class for creating report wappers.
*
* Wrappers encapsulate an existing report to alter their behaviour - they are implementations of
* the standard GoF decorator pattern.
*
* This base class ensure that, by default, wrappers behave in the same way as the report that is
* being wrapped. You should override any methods that need to behave differently in your subclass
* of SS_ReportWrapper.
*
* It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and
* {@link afterQuery()}
*/
abstract class SS_ReportWrapper extends SS_Report
{
protected $baseReport;
public function __construct($baseReport)
{
$this->baseReport = is_string($baseReport) ? new $baseReport : $baseReport;
$this->dataClass = $this->baseReport->dataClass();
parent::__construct();
}
public function ID()
{
return get_class($this->baseReport) . '_' . get_class($this);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering
public function parameterFields()
{
return $this->baseReport->parameterFields();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Columns
public function columns()
{
return $this->baseReport->columns();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Querying
/**
* Override this method to perform some actions prior to querying.
*/
public function beforeQuery($params)
{
}
/**
* Override this method to perform some actions after querying.
*/
public function afterQuery()
{
}
public function sourceQuery($params)
{
if ($this->baseReport->hasMethod('sourceRecords')) {
// The default implementation will create a fake query from our sourceRecords() method
return parent::sourceQuery($params);
} elseif ($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);
}
}
public function sourceRecords($params = array(), $sort = null, $limit = null)
{
$this->beforeQuery($params);
$records = $this->baseReport->sourceRecords($params, $sort, $limit);
$this->afterQuery();
return $records;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Pass-through
public function title()
{
return $this->baseReport->title();
}
public function group()
{
/** @skipUpgrade */
return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group';
}
public function sort()
{
return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0;
}
public function description()
{
return $this->baseReport->description();
}
public function canView($member = null)
{
return $this->baseReport->canView($member);
}
}

View File

@ -1,46 +1,50 @@
<?php
namespace SilverStripe\Reports;
use TableListField;
use SilverStripe\Core\Convert;
use SilverStripe\View\ViewableData;
/**
* Renderer for showing SideReports in CMSMain
*
* @package reports
*/
class SideReportView extends ViewableData
{
protected $controller, $report;
protected $parameters;
public function __construct($controller, $report)
{
$this->controller = $controller;
$this->report = $report;
parent::__construct();
}
public function group()
{
return _t('SideReport.OtherGroupTitle', "Other");
}
public function sort()
{
return 0;
}
public function setParameters($parameters)
{
$this->parameters = $parameters;
}
public function forTemplate()
{
$records = $this->report->records($this->parameters);
$columns = $this->report->columns();
if ($records && $records->Count()) {
$result = "<ul class=\"$this->class\">\n";
foreach ($records as $record) {
$result .= "<li>\n";
foreach ($columns as $source => $info) {
@ -63,7 +67,7 @@ class SideReportView extends ViewableData
}
return $result;
}
protected function formatValue($record, $source, $info)
{
// Field sources
@ -78,7 +82,7 @@ class SideReportView extends ViewableData
if (!empty($info['casting'])) {
$val = TableListField::getCastedValue($val, $info['casting']);
}
// Formatting, a la TableListField
if (!empty($info['formatting'])) {
$format = str_replace('$value', "__VAL__", $info['formatting']);
@ -89,13 +93,13 @@ class SideReportView extends ViewableData
$prefix = empty($info['newline']) ? "" : "<br>";
$classClause = "";
if (isset($info['title'])) {
$cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title']);
$classClause = "class=\"$cssClass\"";
}
if (isset($info['link']) && $info['link']) {
$link = ($info['link'] === true && $record->hasMethod('CMSEditLink'))
? $record->CMSEditLink()
@ -106,22 +110,3 @@ class SideReportView extends ViewableData
}
}
}
/**
* A report wrapper that makes it easier to define slightly different behaviour for side-reports.
*
* This report wrapper will use sideReportColumns() for the report columns, instead of columns().
*
* @package reports
*/
class SideReportWrapper extends SS_ReportWrapper
{
public function columns()
{
if ($this->baseReport->hasMethod('sideReportColumns')) {
return $this->baseReport->sideReportColumns();
} else {
return parent::columns();
}
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace SilverStripe\Reports;
/**
* A report wrapper that makes it easier to define slightly different behaviour for side-reports.
*
* This report wrapper will use sideReportColumns() for the report columns, instead of columns().
*/
class SideReportWrapper extends SS_ReportWrapper
{
public function columns()
{
if ($this->baseReport->hasMethod('sideReportColumns')) {
return $this->baseReport->sideReportColumns();
} else {
return parent::columns();
}
}
}

View File

@ -1,29 +1,34 @@
{
"name": "silverstripe/reports",
"type": "silverstripe-module",
"description": "Reports module for SilverStripe CMS",
"homepage": "http://silverstripe.org",
"license": "BSD-3-Clause",
"keywords": ["silverstripe", "cms", "reports"],
"authors": [
{
"name": "SilverStripe",
"homepage": "http://silverstripe.com"
},
{
"name": "The SilverStripe Community",
"homepage": "http://silverstripe.org"
}
],
"require": {
"silverstripe/framework": "^4.0"
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
}
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
}
"name": "silverstripe/reports",
"type": "silverstripe-module",
"description": "Reports module for SilverStripe CMS",
"homepage": "http://silverstripe.org",
"license": "BSD-3-Clause",
"keywords": ["silverstripe", "cms", "reports"],
"authors": [
{
"name": "SilverStripe",
"homepage": "http://silverstripe.com"
},
{
"name": "The SilverStripe Community",
"homepage": "http://silverstripe.org"
}
],
"require": {
"silverstripe/framework": "^4.0"
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
}
},
"autoload": {
"psr-4": {
"SilverStripe\\Reports\\": "code/"
}
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
}
}

View File

@ -1,41 +0,0 @@
<form $FormAttributes>
<p style="display: none;" class="message " id="Form_EditForm_error"/>
<div id="ScrollPanel">
<fieldset>
$FieldMap.ReportTitle.FieldHolder
$FieldMap.ReportDescription.FieldHolder
<% if $FieldMap.Filters.Children %>
<h4><% _t('ReportAdminForm.FILTERBY', 'Filter by') %></h4>
<div class="filters">
<% loop $FieldMap.Filters %>
<% loop $Children %>
$FieldHolder
<% end_loop %>
<% end_loop %>
</div>
<div id="action_updatereport">
<% if $FieldMap.action_updatereport %>
$FieldMap.action_updatereport.Field
<% end_if %>
</div>
<div style="clear: both">&nbsp;</div>
<% end_if %>
$FieldMap.ReportContent.FieldHolder
<% loop $HiddenFields %>$Field<% end_loop %>
</fieldset>
</div>
<div class="clear"><!-- --></div>
</form>

View File

@ -1,6 +1,11 @@
<?php
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\SS_Report;
use SilverStripe\Control\Session;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
/**
* @package reports