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)
|
||||
{
|
||||
if($this->hasMethod('sourceRecords')) {
|
||||
if ($this->hasMethod('sourceRecords')) {
|
||||
return $this->sourceRecords($params, null, null)->dataQuery();
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
if($this->hasMethod('sourceRecords')) {
|
||||
if ($this->hasMethod('sourceRecords')) {
|
||||
return $this->sourceRecords($params, null, null);
|
||||
} else {
|
||||
$query = $this->sourceQuery();
|
||||
$results = new ArrayList();
|
||||
foreach($query->execute() as $data) {
|
||||
foreach ($query->execute() as $data) {
|
||||
$class = $this->dataClass();
|
||||
$result = new $class($data);
|
||||
$results->push($result);
|
||||
|
@ -158,7 +158,6 @@ class SS_Report extends ViewableData
|
|||
|
||||
public function getLink($action = null)
|
||||
{
|
||||
|
||||
return Controller::join_links(
|
||||
ReportAdmin::singleton()->Link('show'),
|
||||
get_class($this),
|
||||
|
@ -219,7 +218,7 @@ class SS_Report extends ViewableData
|
|||
$reportsArray = array();
|
||||
if ($reports && count($reports) > 0) {
|
||||
//collect reports into array with an attribute for 'sort'
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
if (in_array($report, self::$excluded_reports)) {
|
||||
continue;
|
||||
} //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) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -264,13 +263,13 @@ class SS_Report extends ViewableData
|
|||
{
|
||||
$fields = new FieldList();
|
||||
|
||||
if($description = $this->description()) {
|
||||
if ($description = $this->description()) {
|
||||
$fields->push(new LiteralField('ReportDescription', "<p>" . $description . "</p>"));
|
||||
}
|
||||
|
||||
// Add search fields is available
|
||||
if($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) {
|
||||
foreach($parameterFields as $field) {
|
||||
if ($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) {
|
||||
foreach ($parameterFields as $field) {
|
||||
// Namespace fields for easier handling in form submissions
|
||||
$field->setName(sprintf('filters[%s]', $field->getName()));
|
||||
$field->addExtraClass('no-change-track'); // ignore in changetracker
|
||||
|
@ -321,14 +320,14 @@ class SS_Report extends ViewableData
|
|||
new GridFieldDataColumns(),
|
||||
new GridFieldPaginator()
|
||||
);
|
||||
$gridField = new GridField('Report',null, $items, $gridFieldConfig);
|
||||
$gridField = new GridField('Report', null, $items, $gridFieldConfig);
|
||||
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||
$displayFields = array();
|
||||
$fieldCasting = array();
|
||||
$fieldFormatting = array();
|
||||
|
||||
// Parse the column information
|
||||
foreach($this->columns() as $source => $info) {
|
||||
foreach ($this->columns() as $source => $info) {
|
||||
if (is_string($info)) {
|
||||
$info = array('title' => $info);
|
||||
}
|
||||
|
@ -343,7 +342,7 @@ class SS_Report extends ViewableData
|
|||
$fieldCasting[$source] = $info['casting'];
|
||||
}
|
||||
|
||||
if(isset($info['link']) && $info['link']) {
|
||||
if (isset($info['link']) && $info['link']) {
|
||||
$link = singleton('CMSPageEditController')->Link('show');
|
||||
$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);
|
||||
if($extended !== null) {
|
||||
if ($extended !== null) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -388,14 +387,17 @@ class SS_Report extends ViewableData
|
|||
* @param Member|int $member
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function extendedCan($methodName, $member) {
|
||||
public function extendedCan($methodName, $member)
|
||||
{
|
||||
$results = $this->extend($methodName, $member);
|
||||
if($results && is_array($results)) {
|
||||
if ($results && is_array($results)) {
|
||||
// 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 any explicitly deny the permission, then we don't get access
|
||||
if($results) return min($results);
|
||||
if ($results) {
|
||||
return min($results);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -481,10 +483,10 @@ abstract class SS_ReportWrapper extends SS_Report
|
|||
|
||||
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
|
||||
return parent::sourceQuery($params);
|
||||
} else if($this->baseReport->hasMethod('sourceQuery')) {
|
||||
} elseif ($this->baseReport->hasMethod('sourceQuery')) {
|
||||
$this->beforeQuery($params);
|
||||
$query = $this->baseReport->sourceQuery($params);
|
||||
$this->afterQuery();
|
||||
|
|
|
@ -101,7 +101,8 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
|
|||
return $output;
|
||||
}
|
||||
|
||||
public function handleAction($request, $action) {
|
||||
public function handleAction($request, $action)
|
||||
{
|
||||
$this->reportClass = $request->param('ReportClass');
|
||||
|
||||
// Check report
|
||||
|
|
|
@ -15,7 +15,7 @@ class ReportTest extends SapphireTest
|
|||
$reports = SS_Report::get_reports();
|
||||
$this->assertNotNull($reports, "Reports returned");
|
||||
$previousSort = 0;
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
$this->assertGreaterThanOrEqual($previousSort, $report->sort, "Reports are in correct sort order");
|
||||
$previousSort = $report->sort;
|
||||
}
|
||||
|
@ -25,38 +25,38 @@ class ReportTest extends SapphireTest
|
|||
{
|
||||
$reports = SS_Report::get_reports();
|
||||
$reportNames = array();
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
$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
|
||||
SS_Report::add_excluded_reports('ReportTest_FakeTest');
|
||||
|
||||
$reports = SS_Report::get_reports();
|
||||
$reportNames = array();
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
$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
|
||||
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();
|
||||
$reportNames = array();
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
$reportNames[] = $report->class;
|
||||
}
|
||||
$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_FakeTest', $reportNames, 'ReportTest_FakeTest is NOT in reports list');
|
||||
$this->assertNotContains('ReportTest_FakeTest2', $reportNames, 'ReportTest_FakeTest2 is NOT in reports list');
|
||||
}
|
||||
|
||||
public function testAbstractClassesAreExcluded()
|
||||
{
|
||||
$reports = SS_Report::get_reports();
|
||||
$reportNames = array();
|
||||
foreach($reports as $report) {
|
||||
foreach ($reports as $report) {
|
||||
$reportNames[] = $report->class;
|
||||
}
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testPermissions() {
|
||||
public function testPermissions()
|
||||
{
|
||||
$report = new ReportTest_FakeTest2();
|
||||
|
||||
// Visitor cannot view
|
||||
|
|
Loading…
Reference in New Issue