diff --git a/.editorconfig b/.editorconfig index 47ae637b..3dfb23c7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.upgrade.yml b/.upgrade.yml new file mode 100644 index 00000000..6432d7c0 --- /dev/null +++ b/.upgrade.yml @@ -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 diff --git a/code/Report.php b/code/Report.php index e5bedd9a..b43905f3 100644 --- a/code/Report.php +++ b/code/Report.php @@ -1,9 +1,28 @@ 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); - } -} diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index 9f5267ad..e533dd05 100644 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -1,10 +1,25 @@ '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'), )); diff --git a/code/SS_ReportWrapper.php b/code/SS_ReportWrapper.php new file mode 100644 index 00000000..cd2cc930 --- /dev/null +++ b/code/SS_ReportWrapper.php @@ -0,0 +1,119 @@ +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); + } +} diff --git a/code/SideReport.php b/code/SideReport.php index 72fee965..f9394958 100644 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -1,46 +1,50 @@ 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 = "