mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge branch '3'
This commit is contained in:
commit
537f4da88f
@ -23,6 +23,7 @@ use SilverStripe\Forms\GridField\GridField;
|
|||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\View\ViewableData;
|
use SilverStripe\View\ViewableData;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
use SilverStripe\Admin\CMSPreviewable ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base "abstract" class creating reports on your data.
|
* Base "abstract" class creating reports on your data.
|
||||||
@ -369,12 +370,15 @@ class Report extends ViewableData
|
|||||||
|
|
||||||
if (isset($info['link']) && $info['link']) {
|
if (isset($info['link']) && $info['link']) {
|
||||||
$fieldFormatting[$source] = function($value, $item) {
|
$fieldFormatting[$source] = function($value, $item) {
|
||||||
/** @var CMSPreviewable $item */
|
if ($item instanceof CMSPreviewable) {
|
||||||
return sprintf(
|
/** @var CMSPreviewable $item */
|
||||||
'<a class="grid-field__link-block" href="%s">%s</a>',
|
return sprintf(
|
||||||
Convert::raw2att($item->CMSEditLink()),
|
'<a class="grid-field__link-block" href="%s">%s</a>',
|
||||||
Convert::raw2xml($value)
|
Convert::raw2att($item->CMSEditLink()),
|
||||||
);
|
Convert::raw2xml($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Reports\Report;
|
use SilverStripe\Reports\Report;
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Session;
|
use SilverStripe\Control\Session;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Admin\CMSPreviewable ;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,9 +88,53 @@ class ReportTest extends SapphireTest
|
|||||||
$this->logInWithPermission('CMS_ACCESS_ReportAdmin');
|
$this->logInWithPermission('CMS_ACCESS_ReportAdmin');
|
||||||
$this->assertTrue($report->canView());
|
$this->assertTrue($report->canView());
|
||||||
|
|
||||||
// Admin can view
|
// Admin can view
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
$this->assertTrue($report->canView());
|
$this->assertTrue($report->canView());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testColumnLink() {
|
||||||
|
$report = new ReportTest_FakeTest();
|
||||||
|
/** @var GridField $gridField */
|
||||||
|
$gridField = $report->getReportField();
|
||||||
|
/** @var GridFieldDataColumns $columns */
|
||||||
|
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||||
|
|
||||||
|
$page = new ReportTest_FakeObject();
|
||||||
|
$page->Title = 'My Object';
|
||||||
|
$page->ID = 959547;
|
||||||
|
|
||||||
|
$titleContent = $columns->getColumnContent($gridField, $page, 'Title');
|
||||||
|
$this->assertEquals('<a href="dummy-edit-link/959547" title="My Object">My Object</a>', $titleContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReportTest_FakeObject extends DataObject implements CMSPreviewable, TestOnly {
|
||||||
|
|
||||||
|
private static $db = array(
|
||||||
|
'Title' => 'Varchar'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return String Absolute URL to the end-user view for this record.
|
||||||
|
* Example: http://mysite.com/my-record
|
||||||
|
*/
|
||||||
|
public function Link()
|
||||||
|
{
|
||||||
|
return Controller::join_links('dummy-link', $this->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function CMSEditLink()
|
||||||
|
{
|
||||||
|
return Controller::join_links('dummy-edit-link', $this->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function PreviewLink($action = null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMimeType() {
|
||||||
|
return 'text/html';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +152,8 @@ class ReportTest_FakeTest extends Report implements TestOnly
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
"Title" => array(
|
"Title" => array(
|
||||||
"title" => "Page Title"
|
"title" => "Page Title",
|
||||||
|
"link" => true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user