API Apply SilverStripe\ORM namespace

This commit is contained in:
Damian Mooyman 2016-06-16 17:06:51 +12:00
parent 1890c208e3
commit ab81961115
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
3 changed files with 59 additions and 50 deletions

View File

@ -1,32 +1,36 @@
<?php <?php
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\SS_List;
/** /**
* Base "abstract" class creating reports on your data. * Base "abstract" class creating reports on your data.
* *
* Creating reports * Creating reports
* ================ * ================
* *
* Creating a new report is a matter overloading a few key methods * Creating a new report is a matter overloading a few key methods
* *
* {@link title()}: Return the title - i18n is your responsibility * {@link title()}: Return the title - i18n is your responsibility
* {@link description()}: Return the description - i18n is your responsibility * {@link description()}: Return the description - i18n is your responsibility
* {@link sourceQuery()}: Return a SS_List of the search results * {@link sourceQuery()}: Return a SS_List of the search results
* {@link columns()}: Return information about the columns in this report. * {@link columns()}: Return information about the columns in this report.
* {@link parameterFields()}: Return a FieldList of the fields that can be used to filter this * {@link parameterFields()}: Return a FieldList of the fields that can be used to filter this
* report. * report.
* *
* If you wish to modify the report in more extreme ways, you could overload these methods instead. * If you wish to modify the report in more extreme ways, you could overload these methods instead.
* *
* {@link getReportField()}: Return a FormField in the place where your report's TableListField * {@link getReportField()}: Return a FormField in the place where your report's TableListField
* usually appears. * usually appears.
* {@link getCMSFields()}: Return the FieldList representing the complete right-hand area of the * {@link getCMSFields()}: Return the FieldList representing the complete right-hand area of the
* report, including the title, description, parameter fields, and results. * report, including the title, description, parameter fields, and results.
* *
* Showing reports to the user * Showing reports to the user
* =========================== * ===========================
* *
* Right now, all subclasses of SS_Report will be shown in the ReportAdmin. In SS3 there is only * 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. * one place where reports can go, so this class is greatly simplifed from its version in SS2.
* *
* @package reports * @package reports
*/ */
class SS_Report extends ViewableData class SS_Report extends ViewableData
@ -47,7 +51,7 @@ class SS_Report extends ViewableData
* @var string * @var string
*/ */
protected $description = ''; protected $description = '';
/** /**
* The class of object being managed by this report. * The class of object being managed by this report.
* Set by overriding in your subclass. * Set by overriding in your subclass.
@ -75,41 +79,41 @@ class SS_Report extends ViewableData
'SideReport_BrokenLinks', // @deprecated 3.2..4.0 'SideReport_BrokenLinks', // @deprecated 3.2..4.0
'SideReport_BrokenFiles' // @deprecated 3.2..4.0 'SideReport_BrokenFiles' // @deprecated 3.2..4.0
); );
/** /**
* Return the title of this report. * Return the title of this report.
* *
* You have two ways of specifying the description: * You have two ways of specifying the description:
* - overriding description(), which lets you support i18n * - overriding description(), which lets you support i18n
* - defining the $description property * - defining the $description property
*/ */
public function title() public function title()
{ {
return $this->title; return $this->title;
} }
/** /**
* Allows access to title as a property * Allows access to title as a property
* *
* @return string * @return string
*/ */
public function getTitle() public function getTitle()
{ {
return $this->title(); return $this->title();
} }
/** /**
* Return the description of this report. * Return the description of this report.
* *
* You have two ways of specifying the description: * You have two ways of specifying the description:
* - overriding description(), which lets you support i18n * - overriding description(), which lets you support i18n
* - defining the $description property * - defining the $description property
*/ */
public function description() public function description()
{ {
return $this->description; return $this->description;
} }
/** /**
* Return the {@link SQLQuery} that provides your report data. * Return the {@link SQLQuery} that provides your report data.
*/ */
@ -121,7 +125,7 @@ class SS_Report extends ViewableData
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);
} }
} }
/** /**
* Return a SS_List records for this report. * Return a SS_List records for this report.
*/ */
@ -261,11 +265,11 @@ class SS_Report extends ViewableData
if($title = $this->title()) { if($title = $this->title()) {
$fields->push(new LiteralField('ReportTitle', "<h3>{$title}</h3>")); $fields->push(new LiteralField('ReportTitle', "<h3>{$title}</h3>"));
} }
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) {
@ -278,14 +282,14 @@ class SS_Report extends ViewableData
// Add a search button // Add a search button
$fields->push(new FormAction('updatereport', _t('GridField.Filter'))); $fields->push(new FormAction('updatereport', _t('GridField.Filter')));
} }
$fields->push($this->getReportField()); $fields->push($this->getReportField());
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);
return $fields; return $fields;
} }
public function getCMSActions() public function getCMSActions()
{ {
// getCMSActions() can be extended with updateCMSActions() on a extension // getCMSActions() can be extended with updateCMSActions() on a extension
@ -293,11 +297,11 @@ class SS_Report extends ViewableData
$this->extend('updateCMSActions', $actions); $this->extend('updateCMSActions', $actions);
return $actions; return $actions;
} }
/** /**
* Return a field, such as a {@link GridField} that is * Return a field, such as a {@link GridField} that is
* used to show and manipulate data relating to this report. * used to show and manipulate data relating to this report.
* *
* Generally, you should override {@link columns()} and {@link records()} to make your report, * Generally, you should override {@link columns()} and {@link records()} to make your report,
* but if they aren't sufficiently flexible, then you can override this method. * but if they aren't sufficiently flexible, then you can override this method.
* *
@ -329,7 +333,7 @@ class SS_Report extends ViewableData
if (is_string($info)) { if (is_string($info)) {
$info = array('title' => $info); $info = array('title' => $info);
} }
if (isset($info['formatting'])) { if (isset($info['formatting'])) {
$fieldFormatting[$source] = $info['formatting']; $fieldFormatting[$source] = $info['formatting'];
} }
@ -353,7 +357,7 @@ class SS_Report extends ViewableData
return $gridField; return $gridField;
} }
/** /**
* @param Member $member * @param Member $member
* @return boolean * @return boolean
@ -363,7 +367,7 @@ class SS_Report extends ViewableData
if (!$member && $member !== false) { if (!$member && $member !== false) {
$member = Member::currentUser(); $member = Member::currentUser();
} }
$extended = $this->extendedCan('canView', $member); $extended = $this->extendedCan('canView', $member);
if($extended !== null) { if($extended !== null) {
return $extended; return $extended;
@ -372,7 +376,7 @@ class SS_Report extends ViewableData
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;
} }
return false; return false;
} }
@ -396,7 +400,7 @@ class SS_Report extends ViewableData
} }
return null; return null;
} }
/** /**
* Return the name of this report, which * Return the name of this report, which
@ -414,17 +418,17 @@ class SS_Report extends ViewableData
/** /**
* SS_ReportWrapper is a base class for creating report wappers. * SS_ReportWrapper is a base class for creating report wappers.
* *
* Wrappers encapsulate an existing report to alter their behaviour - they are implementations of * Wrappers encapsulate an existing report to alter their behaviour - they are implementations of
* the standard GoF decorator pattern. * the standard GoF decorator pattern.
* *
* This base class ensure that, by default, wrappers behave in the same way as the report that is * This base class ensure that, by default, wrappers behave in the same way as the report that is
* being wrapped. You should override any methods that need to behave differently in your subclass * being wrapped. You should override any methods that need to behave differently in your subclass
* of SS_ReportWrapper. * of SS_ReportWrapper.
* *
* It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and * It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and
* {@link afterQuery()} * {@link afterQuery()}
* *
* @package reports * @package reports
*/ */
abstract class SS_ReportWrapper extends SS_Report abstract class SS_ReportWrapper extends SS_Report
@ -507,12 +511,12 @@ abstract class SS_ReportWrapper extends SS_Report
{ {
return $this->baseReport->title(); return $this->baseReport->title();
} }
public function group() public function group()
{ {
return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group'; return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group';
} }
public function sort() public function sort()
{ {
return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0; return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0;
@ -526,5 +530,5 @@ abstract class SS_ReportWrapper extends SS_Report
public function canView($member = null) public function canView($member = null)
{ {
return $this->baseReport->canView($member); return $this->baseReport->canView($member);
} }
} }

View File

@ -1,24 +1,27 @@
<?php <?php
use SilverStripe\ORM\ArrayList;
/** /**
* Reports section of the CMS. * Reports section of the CMS.
* *
* All reports that should show in the ReportAdmin section * All reports that should show in the ReportAdmin section
* of the CMS need to subclass {@link SS_Report}, and implement * of the CMS need to subclass {@link SS_Report}, and implement
* the appropriate methods and variables that are required. * the appropriate methods and variables that are required.
* *
* @see SS_Report * @see SS_Report
* *
* @package reports * @package reports
*/ */
class ReportAdmin extends LeftAndMain implements PermissionProvider class ReportAdmin extends LeftAndMain implements PermissionProvider
{ {
private static $url_segment = 'reports'; private static $url_segment = 'reports';
private static $url_rule = '/$ReportClass/$Action'; private static $url_rule = '/$ReportClass/$Action';
private static $menu_title = 'Reports'; private static $menu_title = 'Reports';
private static $template_path = null; // defaults to (project)/templates/email private static $template_path = null; // defaults to (project)/templates/email
private static $tree_class = 'SS_Report'; private static $tree_class = 'SS_Report';
@ -28,7 +31,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
); );
/** /**
* Variable that describes which report we are currently viewing based on * Variable that describes which report we are currently viewing based on
* the URL (gets set in init method). * the URL (gets set in init method).
* *
* @var string * @var string
@ -36,7 +39,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
protected $reportClass; protected $reportClass;
protected $reportObject; protected $reportObject;
public function init() public function init()
{ {
parent::init(); parent::init();
@ -126,7 +129,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
public function Breadcrumbs($unlinked = false) public function Breadcrumbs($unlinked = false)
{ {
$items = parent::Breadcrumbs($unlinked); $items = parent::Breadcrumbs($unlinked);
// The root element should explicitly point to the root node. // The root element should explicitly point to the root node.
// Uses session state for current record otherwise. // Uses session state for current record otherwise.
$items[0]->Link = singleton('ReportAdmin')->Link(); $items[0]->Link = singleton('ReportAdmin')->Link();

View File

@ -1,5 +1,7 @@
<?php <?php
use SilverStripe\ORM\ArrayList;
/** /**
* @package reports * @package reports
* @subpackage tests * @subpackage tests
@ -146,7 +148,7 @@ class ReportTest_FakeTest2 extends SS_Report implements TestOnly
*/ */
abstract class ReportTest_FakeTest_Abstract extends SS_Report implements TestOnly abstract class ReportTest_FakeTest_Abstract extends SS_Report implements TestOnly
{ {
public function title() public function title()
{ {
return 'Report title Abstract'; return 'Report title Abstract';