mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API-CHANGE: SSF-168 changing the API/code-conventions for excluding specific reports. get_reports method now returns an ArrayList instead of an array of SS_Reports.
This commit is contained in:
parent
ee220bbcce
commit
349a04d049
@ -147,6 +147,7 @@ class SS_Report extends ViewableData {
|
|||||||
* The default value is zero.
|
* The default value is zero.
|
||||||
*/
|
*/
|
||||||
static function register($list, $reportClass, $priority = 0) {
|
static function register($list, $reportClass, $priority = 0) {
|
||||||
|
Deprecation::notice('3.0', 'All subclasses of SS_Report now appear in the report admin, no need to register');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,21 +155,37 @@ class SS_Report extends ViewableData {
|
|||||||
* All subclasses of SS_Report now appear in the report admin, no need to register or unregister.
|
* All subclasses of SS_Report now appear in the report admin, no need to register or unregister.
|
||||||
*/
|
*/
|
||||||
static function unregister($list, $reportClass) {
|
static function unregister($list, $reportClass) {
|
||||||
self::excludeReport($reportClass);
|
self::add_excluded_reports($reportClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exclude a certain report class from the list of Reports in the CMS
|
* Exclude certain reports classes from the list of Reports in the CMS
|
||||||
* @static
|
* @param $reportClass Can be either a string with the report classname or an array of reports classnames
|
||||||
* @param $reportClass
|
|
||||||
*/
|
*/
|
||||||
static function excludeReport($reportClass) {
|
static function add_excluded_reports($reportClass) {
|
||||||
self::$excluded_reports[] = $reportClass; //add to the excluded reports, so this report doesn't get used
|
if (is_array($reportClass)) {
|
||||||
|
self::$excluded_reports = array_merge(self::$excluded_reports, $reportClass);
|
||||||
|
} else {
|
||||||
|
if (is_string($reportClass)) {
|
||||||
|
//add to the excluded reports, so this report doesn't get used
|
||||||
|
self::$excluded_reports[] = $reportClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of excluded reports. That is, reports that will not be included in
|
||||||
|
* the list of reports in report admin in the CMS.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
static function get_excluded_reports() {
|
||||||
|
return self::$excluded_reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the SS_Report objects making up the given list.
|
* Return the SS_Report objects making up the given list.
|
||||||
* @return An array of SS_Report objects
|
* @return ArrayList an arraylist of SS_Report objects
|
||||||
*/
|
*/
|
||||||
static function get_reports() {
|
static function get_reports() {
|
||||||
$reports = ClassInfo::subclassesFor(get_called_class());
|
$reports = ClassInfo::subclassesFor(get_called_class());
|
||||||
|
@ -20,8 +20,8 @@ class ReportTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
$this->assertContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is in reports list');
|
$this->assertContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is in reports list');
|
||||||
|
|
||||||
//excluse one report
|
//exclude one report
|
||||||
SS_Report::excludeReport('ReportTest_FakeTest');
|
SS_Report::add_excluded_reports('ReportTest_FakeTest');
|
||||||
|
|
||||||
$reports = SS_Report::get_reports();
|
$reports = SS_Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
@ -29,6 +29,17 @@ class ReportTest extends SapphireTest {
|
|||||||
$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
|
||||||
|
SS_Report::add_excluded_reports(array('ReportTest_FakeTest','ReportTest_FakeTest2'));
|
||||||
|
|
||||||
|
$reports = SS_Report::get_reports();
|
||||||
|
$reportNames = array();
|
||||||
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user