mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-06-26 14:39:30 +02:00
Fix psr-2 formatting
This commit is contained in:
parent
f04975c64e
commit
d2142f252e
|
@ -121,7 +121,7 @@ class SS_Report extends ViewableData
|
||||||
*/
|
*/
|
||||||
public function sourceQuery($params)
|
public function sourceQuery($params)
|
||||||
{
|
{
|
||||||
if($this->hasMethod('sourceRecords')) {
|
if ($this->hasMethod('sourceRecords')) {
|
||||||
return $this->sourceRecords($params, null, null)->dataQuery();
|
return $this->sourceRecords($params, null, null)->dataQuery();
|
||||||
} else {
|
} else {
|
||||||
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
|
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
|
||||||
|
@ -133,12 +133,12 @@ class SS_Report extends ViewableData
|
||||||
*/
|
*/
|
||||||
public function records($params)
|
public function records($params)
|
||||||
{
|
{
|
||||||
if($this->hasMethod('sourceRecords')) {
|
if ($this->hasMethod('sourceRecords')) {
|
||||||
return $this->sourceRecords($params, null, null);
|
return $this->sourceRecords($params, null, null);
|
||||||
} else {
|
} else {
|
||||||
$query = $this->sourceQuery();
|
$query = $this->sourceQuery();
|
||||||
$results = new ArrayList();
|
$results = new ArrayList();
|
||||||
foreach($query->execute() as $data) {
|
foreach ($query->execute() as $data) {
|
||||||
$class = $this->dataClass();
|
$class = $this->dataClass();
|
||||||
$result = new $class($data);
|
$result = new $class($data);
|
||||||
$results->push($result);
|
$results->push($result);
|
||||||
|
@ -158,7 +158,6 @@ class SS_Report extends ViewableData
|
||||||
|
|
||||||
public function getLink($action = null)
|
public function getLink($action = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
return Controller::join_links(
|
return Controller::join_links(
|
||||||
ReportAdmin::singleton()->Link('show'),
|
ReportAdmin::singleton()->Link('show'),
|
||||||
get_class($this),
|
get_class($this),
|
||||||
|
@ -219,7 +218,7 @@ class SS_Report extends ViewableData
|
||||||
$reportsArray = array();
|
$reportsArray = array();
|
||||||
if ($reports && count($reports) > 0) {
|
if ($reports && count($reports) > 0) {
|
||||||
//collect reports into array with an attribute for 'sort'
|
//collect reports into array with an attribute for 'sort'
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
if (in_array($report, self::$excluded_reports)) {
|
if (in_array($report, self::$excluded_reports)) {
|
||||||
continue;
|
continue;
|
||||||
} //don't use the SS_Report superclass
|
} //don't use the SS_Report superclass
|
||||||
|
@ -236,7 +235,7 @@ class SS_Report extends ViewableData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uasort($reportsArray, function($a, $b) {
|
uasort($reportsArray, function ($a, $b) {
|
||||||
if ($a->sort == $b->sort) {
|
if ($a->sort == $b->sort) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,13 +263,13 @@ class SS_Report extends ViewableData
|
||||||
{
|
{
|
||||||
$fields = new FieldList();
|
$fields = new FieldList();
|
||||||
|
|
||||||
if($description = $this->description()) {
|
if ($description = $this->description()) {
|
||||||
$fields->push(new LiteralField('ReportDescription', "<p>" . $description . "</p>"));
|
$fields->push(new LiteralField('ReportDescription', "<p>" . $description . "</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add search fields is available
|
// Add search fields is available
|
||||||
if($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) {
|
if ($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) {
|
||||||
foreach($parameterFields as $field) {
|
foreach ($parameterFields as $field) {
|
||||||
// Namespace fields for easier handling in form submissions
|
// Namespace fields for easier handling in form submissions
|
||||||
$field->setName(sprintf('filters[%s]', $field->getName()));
|
$field->setName(sprintf('filters[%s]', $field->getName()));
|
||||||
$field->addExtraClass('no-change-track'); // ignore in changetracker
|
$field->addExtraClass('no-change-track'); // ignore in changetracker
|
||||||
|
@ -321,14 +320,14 @@ class SS_Report extends ViewableData
|
||||||
new GridFieldDataColumns(),
|
new GridFieldDataColumns(),
|
||||||
new GridFieldPaginator()
|
new GridFieldPaginator()
|
||||||
);
|
);
|
||||||
$gridField = new GridField('Report',null, $items, $gridFieldConfig);
|
$gridField = new GridField('Report', null, $items, $gridFieldConfig);
|
||||||
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
$displayFields = array();
|
$displayFields = array();
|
||||||
$fieldCasting = array();
|
$fieldCasting = array();
|
||||||
$fieldFormatting = array();
|
$fieldFormatting = array();
|
||||||
|
|
||||||
// Parse the column information
|
// Parse the column information
|
||||||
foreach($this->columns() as $source => $info) {
|
foreach ($this->columns() as $source => $info) {
|
||||||
if (is_string($info)) {
|
if (is_string($info)) {
|
||||||
$info = array('title' => $info);
|
$info = array('title' => $info);
|
||||||
}
|
}
|
||||||
|
@ -343,7 +342,7 @@ class SS_Report extends ViewableData
|
||||||
$fieldCasting[$source] = $info['casting'];
|
$fieldCasting[$source] = $info['casting'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($info['link']) && $info['link']) {
|
if (isset($info['link']) && $info['link']) {
|
||||||
$link = singleton('CMSPageEditController')->Link('show');
|
$link = singleton('CMSPageEditController')->Link('show');
|
||||||
$fieldFormatting[$source] = '<a class=\"grid-field__link-block\" href=\"' . $link . '/$ID\">$value</a>';
|
$fieldFormatting[$source] = '<a class=\"grid-field__link-block\" href=\"' . $link . '/$ID\">$value</a>';
|
||||||
}
|
}
|
||||||
|
@ -368,11 +367,11 @@ class SS_Report extends ViewableData
|
||||||
}
|
}
|
||||||
|
|
||||||
$extended = $this->extendedCan('canView', $member);
|
$extended = $this->extendedCan('canView', $member);
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($member && Permission::checkMember($member, array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_ReportAdmin'))) {
|
if ($member && Permission::checkMember($member, array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_ReportAdmin'))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,14 +387,17 @@ class SS_Report extends ViewableData
|
||||||
* @param Member|int $member
|
* @param Member|int $member
|
||||||
* @return boolean|null
|
* @return boolean|null
|
||||||
*/
|
*/
|
||||||
public function extendedCan($methodName, $member) {
|
public function extendedCan($methodName, $member)
|
||||||
|
{
|
||||||
$results = $this->extend($methodName, $member);
|
$results = $this->extend($methodName, $member);
|
||||||
if($results && is_array($results)) {
|
if ($results && is_array($results)) {
|
||||||
// Remove NULLs
|
// Remove NULLs
|
||||||
$results = array_filter($results, function($v) {return !is_null($v);});
|
$results = array_filter($results, function ($v) {return !is_null($v);});
|
||||||
// If there are any non-NULL responses, then return the lowest one of them.
|
// If there are any non-NULL responses, then return the lowest one of them.
|
||||||
// If any explicitly deny the permission, then we don't get access
|
// If any explicitly deny the permission, then we don't get access
|
||||||
if($results) return min($results);
|
if ($results) {
|
||||||
|
return min($results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -481,10 +483,10 @@ abstract class SS_ReportWrapper extends SS_Report
|
||||||
|
|
||||||
public function sourceQuery($params)
|
public function sourceQuery($params)
|
||||||
{
|
{
|
||||||
if($this->baseReport->hasMethod('sourceRecords')) {
|
if ($this->baseReport->hasMethod('sourceRecords')) {
|
||||||
// The default implementation will create a fake query from our sourceRecords() method
|
// The default implementation will create a fake query from our sourceRecords() method
|
||||||
return parent::sourceQuery($params);
|
return parent::sourceQuery($params);
|
||||||
} else if($this->baseReport->hasMethod('sourceQuery')) {
|
} elseif ($this->baseReport->hasMethod('sourceQuery')) {
|
||||||
$this->beforeQuery($params);
|
$this->beforeQuery($params);
|
||||||
$query = $this->baseReport->sourceQuery($params);
|
$query = $this->baseReport->sourceQuery($params);
|
||||||
$this->afterQuery();
|
$this->afterQuery();
|
||||||
|
|
|
@ -101,7 +101,8 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleAction($request, $action) {
|
public function handleAction($request, $action)
|
||||||
|
{
|
||||||
$this->reportClass = $request->param('ReportClass');
|
$this->reportClass = $request->param('ReportClass');
|
||||||
|
|
||||||
// Check report
|
// Check report
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ReportTest extends SapphireTest
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$this->assertNotNull($reports, "Reports returned");
|
$this->assertNotNull($reports, "Reports returned");
|
||||||
$previousSort = 0;
|
$previousSort = 0;
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$this->assertGreaterThanOrEqual($previousSort, $report->sort, "Reports are in correct sort order");
|
$this->assertGreaterThanOrEqual($previousSort, $report->sort, "Reports are in correct sort order");
|
||||||
$previousSort = $report->sort;
|
$previousSort = $report->sort;
|
||||||
}
|
}
|
||||||
|
@ -25,38 +25,38 @@ class ReportTest extends SapphireTest
|
||||||
{
|
{
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$reportNames[] = $report->class;
|
$reportNames[] = $report->class;
|
||||||
}
|
}
|
||||||
$this->assertContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is in reports list');
|
$this->assertContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is in reports list');
|
||||||
|
|
||||||
//exclude one report
|
//exclude one report
|
||||||
SS_Report::add_excluded_reports('ReportTest_FakeTest');
|
SS_Report::add_excluded_reports('ReportTest_FakeTest');
|
||||||
|
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$reportNames[] = $report->class;
|
$reportNames[] = $report->class;
|
||||||
}
|
}
|
||||||
$this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list');
|
$this->assertNotContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is NOT in reports list');
|
||||||
|
|
||||||
//exclude two reports
|
//exclude two reports
|
||||||
SS_Report::add_excluded_reports(array('ReportTest_FakeTest','ReportTest_FakeTest2'));
|
SS_Report::add_excluded_reports(array('ReportTest_FakeTest', 'ReportTest_FakeTest2'));
|
||||||
|
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$reportNames[] = $report->class;
|
$reportNames[] = $report->class;
|
||||||
}
|
}
|
||||||
$this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list');
|
$this->assertNotContains('ReportTest_FakeTest', $reportNames, 'ReportTest_FakeTest is NOT in reports list');
|
||||||
$this->assertNotContains('ReportTest_FakeTest2',$reportNames,'ReportTest_FakeTest2 is NOT in reports list');
|
$this->assertNotContains('ReportTest_FakeTest2', $reportNames, 'ReportTest_FakeTest2 is NOT in reports list');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAbstractClassesAreExcluded()
|
public function testAbstractClassesAreExcluded()
|
||||||
{
|
{
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
foreach($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$reportNames[] = $report->class;
|
$reportNames[] = $report->class;
|
||||||
}
|
}
|
||||||
$this->assertNotContains('ReportTest_FakeTest_Abstract',
|
$this->assertNotContains('ReportTest_FakeTest_Abstract',
|
||||||
|
@ -64,7 +64,8 @@ class ReportTest extends SapphireTest
|
||||||
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract');
|
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPermissions() {
|
public function testPermissions()
|
||||||
|
{
|
||||||
$report = new ReportTest_FakeTest2();
|
$report = new ReportTest_FakeTest2();
|
||||||
|
|
||||||
// Visitor cannot view
|
// Visitor cannot view
|
||||||
|
|
Loading…
Reference in New Issue
Block a user