mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge pull request #36 from open-sausages/features/4.0/gridfield-styles
Class change for new gridfield styles, moved report actions to appear above gridfield
This commit is contained in:
commit
77a696ecdd
@ -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
|
||||
@ -312,21 +311,23 @@ class SS_Report extends ViewableData
|
||||
$items = $this->sourceRecords($params, null, null);
|
||||
|
||||
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||
|
||||
new GridFieldButtonRow('before'),
|
||||
new GridFieldPrintButton('buttons-before-left'),
|
||||
new GridFieldExportButton('buttons-before-left'),
|
||||
new GridFieldToolbarHeader(),
|
||||
new GridFieldSortableHeader(),
|
||||
new GridFieldDataColumns(),
|
||||
new GridFieldPaginator(),
|
||||
new GridFieldButtonRow('after'),
|
||||
new GridFieldPrintButton('buttons-after-left'),
|
||||
new GridFieldExportButton('buttons-after-left')
|
||||
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);
|
||||
}
|
||||
@ -341,9 +342,15 @@ class SS_Report extends ViewableData
|
||||
$fieldCasting[$source] = $info['casting'];
|
||||
}
|
||||
|
||||
if(isset($info['link']) && $info['link']) {
|
||||
$link = singleton('CMSPageEditController')->Link('show');
|
||||
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
|
||||
if (isset($info['link']) && $info['link']) {
|
||||
$fieldFormatting[$source] = function($value, $item) {
|
||||
/** @var CMSPreviewable $item */
|
||||
return sprintf(
|
||||
'<a class="grid-field__link-block" href="%s">%s</a>',
|
||||
Convert::raw2att($item->CMSEditLink()),
|
||||
Convert::raw2xml($value)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
|
||||
@ -366,11 +373,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;
|
||||
}
|
||||
|
||||
@ -386,14 +393,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;
|
||||
}
|
||||
@ -479,10 +489,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
|
||||
@ -204,7 +205,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
|
||||
));
|
||||
|
||||
$columns->setFieldFormatting(array(
|
||||
'title' => '<a href=\"$Link\" class=\"cms-panel-link\">$value ($Count)</a>'
|
||||
'title' => '<a href=\"$Link\" class=\"grid-field__link-block\">$value ($Count)</a>'
|
||||
));
|
||||
$gridField->addExtraClass('all-reports-gridfield');
|
||||
$fields->push($gridField);
|
||||
|
@ -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
Block a user