From a548f0290e1f573ee75aa5aa5eafb2e2c773095c Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 25 Oct 2017 18:00:23 +0100 Subject: [PATCH 01/11] Add composer autoloading support to 3.x --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index f585dfce..9e1c8f0b 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,8 @@ }, "require-dev": { "phpunit/PHPUnit": "~3.7" + }, + "autoload": { + "classmap": ["code"] } } From 26dc7373bae2fde3889f67103bd2db2c59d70afb Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 30 Oct 2017 11:51:00 +1300 Subject: [PATCH 02/11] FIX Add primary button class to 'Filter' button --- code/Report.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/Report.php b/code/Report.php index 14bfe5d5..1e727d42 100644 --- a/code/Report.php +++ b/code/Report.php @@ -292,8 +292,8 @@ class Report extends ViewableData } // Add a search button - $formAction = new FormAction('updatereport', _t('SilverStripe\\Forms\\GridField\\GridField.Filter', 'Filter')); - $formAction->addExtraClass("mb-4"); + $formAction = FormAction::create('updatereport', _t('SilverStripe\\Forms\\GridField\\GridField.Filter', 'Filter')); + $formAction->addExtraClass('btn-primary mb-4'); $fields->push($formAction); } From b406d8724fe276da61214137adc49b07c797d2b5 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 17 Nov 2017 11:41:43 +0000 Subject: [PATCH 03/11] Loosen PHPUnit constraints --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9e1c8f0b..2c22111b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require-dev": { - "phpunit/PHPUnit": "~3.7" + "phpunit/phpunit": "^3 || ^4 || ^5" }, "autoload": { "classmap": ["code"] From 14eeb10d31beb013f047b55ff3149fd3bb8e89ec Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 17 Nov 2017 12:07:34 +0000 Subject: [PATCH 04/11] Remove php7 test suite as its pointless --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3894944..212be62c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ php: - 5.4 - 5.5 - 5.6 - - 7.0 env: - DB=MYSQL CORE_RELEASE=3.3 @@ -22,8 +21,6 @@ matrix: env: DB=PGSQL CORE_RELEASE=3 - php: 5.6 env: DB=PGSQL CORE_RELEASE=3.2 - allow_failures: - - php: 7.0 before_script: - composer self-update || true From 5b335ad511a9cdef77c1ecb568d0cb92ba2dd2db Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 23 Oct 2017 22:40:53 +1300 Subject: [PATCH 05/11] NEW Add support for callable link formatting --- code/Report.php | 52 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/code/Report.php b/code/Report.php index 1e727d42..9f08ea8b 100644 --- a/code/Report.php +++ b/code/Report.php @@ -25,7 +25,8 @@ use SilverStripe\Security\Member; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; use SilverStripe\View\ViewableData; - +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Control\HTTPRequest; /** * Base "abstract" class creating reports on your data. * @@ -85,6 +86,8 @@ class Report extends ViewableData */ protected $sort = 0; + protected $params = []; + /** * Reports which should not be collected and returned in get_reports * @@ -97,6 +100,15 @@ class Report extends ViewableData SideReportWrapper::class, ]; + public function __construct() + { + if (Injector::inst()->has(HTTPRequest::class)) { + $this->params = Injector::inst()->get(HTTPRequest::class)->param('filters'); + } + + parent::__construct(); + } + /** * Return the title of this report. * @@ -162,6 +174,11 @@ class Report extends ViewableData } } + public function columns() + { + return []; + } + /** * Return the data class for this report */ @@ -324,9 +341,7 @@ class Report extends ViewableData */ public function getReportField() { - // TODO Remove coupling with global state - $params = isset($_REQUEST['filters']) ? $_REQUEST['filters'] : array(); - $items = $this->sourceRecords($params, null, null); + $items = $this->sourceRecords($this->params, null, null); $gridFieldConfig = GridFieldConfig::create()->addComponents( @@ -334,7 +349,6 @@ class Report extends ViewableData new GridFieldPrintButton('buttons-before-left'), new GridFieldExportButton('buttons-before-left'), new GridFieldToolbarHeader(), - new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator() ); @@ -361,18 +375,22 @@ class Report extends ViewableData } if (isset($info['link']) && $info['link']) { - $fieldFormatting[$source] = function ($value, $item) { - if ($item instanceof CMSPreviewable) { - /** @var CMSPreviewable $item */ - return sprintf( - '%s', - Convert::raw2att($item->CMSEditLink()), - Convert::raw2att($value), - Convert::raw2xml($value) - ); - } - return $value; - }; + if (is_callable($info['link'])) { + $fieldFormatting[$source] = $info['link']; + } else { + $fieldFormatting[$source] = function ($value, $item) { + if ($item instanceof CMSPreviewable) { + /** @var CMSPreviewable $item */ + return sprintf( + '%s', + Convert::raw2att($item->CMSEditLink()), + Convert::raw2att($value), + Convert::raw2xml($value) + ); + } + return $value; + }; + } } $displayFields[$source] = isset($info['title']) ? $info['title'] : $source; From 86f845972f926d09186eabcd39cdabfa672b9f35 Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Mon, 27 Nov 2017 14:29:19 +1300 Subject: [PATCH 06/11] BUG Actioned feedback --- code/Report.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/code/Report.php b/code/Report.php index 9f08ea8b..0cdfe155 100644 --- a/code/Report.php +++ b/code/Report.php @@ -86,8 +86,6 @@ class Report extends ViewableData */ protected $sort = 0; - protected $params = []; - /** * Reports which should not be collected and returned in get_reports * @@ -100,15 +98,6 @@ class Report extends ViewableData SideReportWrapper::class, ]; - public function __construct() - { - if (Injector::inst()->has(HTTPRequest::class)) { - $this->params = Injector::inst()->get(HTTPRequest::class)->param('filters'); - } - - parent::__construct(); - } - /** * Return the title of this report. * @@ -341,7 +330,13 @@ class Report extends ViewableData */ public function getReportField() { - $items = $this->sourceRecords($this->params, null, null); + $params = []; + if (Injector::inst()->has(HTTPRequest::class)) { + /** @var HTTPRequest $request */ + $request = Injector::inst()->get(HTTPRequest::class); + $params = $request->param('filters') ?: []; + } + $items = $this->sourceRecords($params, null, null); $gridFieldConfig = GridFieldConfig::create()->addComponents( @@ -349,19 +344,20 @@ class Report extends ViewableData new GridFieldPrintButton('buttons-before-left'), new GridFieldExportButton('buttons-before-left'), new GridFieldToolbarHeader(), + new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator() ); $gridField = new GridField('Report', null, $items, $gridFieldConfig); - $columns = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); - $displayFields = array(); - $fieldCasting = array(); - $fieldFormatting = array(); + $columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); + $displayFields = []; + $fieldCasting = []; + $fieldFormatting = []; // Parse the column information foreach ($this->columns() as $source => $info) { if (is_string($info)) { - $info = array('title' => $info); + $info = ['title' => $info]; } if (isset($info['formatting'])) { From ed16d968427aa9106b7748e475635a7ad81924ff Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 7 Dec 2017 11:08:26 +1300 Subject: [PATCH 07/11] Update translations --- lang/hr.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lang/hr.yml diff --git a/lang/hr.yml b/lang/hr.yml new file mode 100644 index 00000000..1e3accd4 --- /dev/null +++ b/lang/hr.yml @@ -0,0 +1,6 @@ +hr: + SilverStripe\Reports\ReportAdmin: + MENUTITLE: IzvjeĆĄtaji + ReportTitle: Naslov + SilverStripe\Reports\SideReport: + OtherGroupTitle: Drugi From 4d8053611d4b669e0f637c207ac7d8de728ee296 Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Mon, 11 Dec 2017 12:06:02 +1300 Subject: [PATCH 08/11] Feature Set .gitattributes to ignore docs and tests folder, and some source asset files which are not needed --- .gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 475f5f20..2502a575 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ /tests export-ignore -/docs export-ignore +/.tx export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /.scrutinizer.yml export-ignore +/*.dist export-ignore From b4a3529339345b88cf9db9503caef1b386709dc6 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 14 Dec 2017 13:32:50 +1300 Subject: [PATCH 09/11] FIX Minor linting violation in Report --- code/Report.php | 1 + 1 file changed, 1 insertion(+) diff --git a/code/Report.php b/code/Report.php index 0cdfe155..d38c4540 100644 --- a/code/Report.php +++ b/code/Report.php @@ -27,6 +27,7 @@ use SilverStripe\Security\Security; use SilverStripe\View\ViewableData; use SilverStripe\Core\Injector\Injector; use SilverStripe\Control\HTTPRequest; + /** * Base "abstract" class creating reports on your data. * From b006a9968ad4d5f073fa1ef784a89ecab8113e50 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 14 Dec 2017 13:37:25 +1300 Subject: [PATCH 10/11] Linting, phpdoc and code style fixes --- code/Report.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/code/Report.php b/code/Report.php index d38c4540..d57d58c3 100644 --- a/code/Report.php +++ b/code/Report.php @@ -3,11 +3,15 @@ namespace SilverStripe\Reports; use ReflectionClass; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; +use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormAction; +use SilverStripe\Forms\FormField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldButtonRow; use SilverStripe\Forms\GridField\GridFieldConfig; @@ -20,13 +24,13 @@ use SilverStripe\Forms\GridField\GridFieldToolbarHeader; use SilverStripe\Forms\LiteralField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\CMSPreviewable; +use SilverStripe\ORM\DataList; +use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\SS_List; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; use SilverStripe\View\ViewableData; -use SilverStripe\Core\Injector\Injector; -use SilverStripe\Control\HTTPRequest; /** * Base "abstract" class creating reports on your data. @@ -55,6 +59,8 @@ use SilverStripe\Control\HTTPRequest; * * 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. + * + * @method SS_List|DataList sourceRecords($params = [], $sort = null, $limit = null) List of records to show for this report */ class Report extends ViewableData { @@ -79,7 +85,7 @@ class Report extends ViewableData * The class of object being managed by this report. * Set by overriding in your subclass. */ - protected $dataClass = 'SilverStripe\\CMS\\Model\\SiteTree'; + protected $dataClass = SiteTree::class; /** * A field that specifies the sort order of this report @@ -134,7 +140,10 @@ class Report extends ViewableData } /** - * Return the {@link SilverStripe\ORM\Queries\SQLSelect} that provides your report data. + * Return the {@link DataQuery} that provides your report data. + * + * @param array $params + * @return DataQuery */ public function sourceQuery($params) { @@ -147,6 +156,9 @@ class Report extends ViewableData /** * Return a SS_List records for this report. + * + * @param array $params + * @return SS_List */ public function records($params) { @@ -227,7 +239,8 @@ class Report extends ViewableData /** * Return the SS_Report objects making up the given list. - * @return Array of SS_Report objects + * + * @return Report[] Array of Report objects */ public static function get_reports() { @@ -248,6 +261,7 @@ class Report extends ViewableData continue; } + /** @var Report $reportObj */ $reportObj = $report::create(); if ($reportObj->hasMethod('sort')) { // Use the sort method to specify the sort field @@ -291,6 +305,7 @@ class Report extends ViewableData // Add search fields is available if ($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) { + /** @var FormField $field */ foreach ($parameterFields as $field) { // Namespace fields for easier handling in form submissions $field->setName(sprintf('filters[%s]', $field->getName())); From 8a29918ac586b2254a7e8daf7121105cee350b99 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Sun, 17 Dec 2017 21:25:19 +1300 Subject: [PATCH 11/11] NEW Remove duplicated report heading --- code/Report.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/Report.php b/code/Report.php index d57d58c3..200a1d2b 100644 --- a/code/Report.php +++ b/code/Report.php @@ -20,7 +20,6 @@ use SilverStripe\Forms\GridField\GridFieldExportButton; use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\Forms\GridField\GridFieldPrintButton; use SilverStripe\Forms\GridField\GridFieldSortableHeader; -use SilverStripe\Forms\GridField\GridFieldToolbarHeader; use SilverStripe\Forms\LiteralField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\CMSPreviewable; @@ -359,7 +358,6 @@ class Report extends ViewableData new GridFieldButtonRow('before'), new GridFieldPrintButton('buttons-before-left'), new GridFieldExportButton('buttons-before-left'), - new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator()