Skip to content
This repository
Browse code

API-CHANGE: SSF-168 changing the API/code-conventions for excluding s…

…pecific reports. get_reports method now returns an ArrayList instead of an array of SS_Reports.
  • Loading branch information...
commit 349a04d049b454b616ca332b1f2e4fe517cbb796 1 parent ee220bb
Julian Seidenberg authored April 04, 2012
31  code/reports/Report.php
@@ -147,6 +147,7 @@ function dataClass() {
147 147
 	 * The default value is zero.
148 148
 	 */
149 149
 	static function register($list, $reportClass, $priority = 0) {
  150
+		Deprecation::notice('3.0', 'All subclasses of SS_Report now appear in the report admin, no need to register');
150 151
 	}
151 152
 
152 153
 	/**
@@ -154,21 +155,37 @@ static function register($list, $reportClass, $priority = 0) {
154 155
 	 * All subclasses of SS_Report now appear in the report admin, no need to register or unregister.
155 156
 	 */
156 157
 	static function unregister($list, $reportClass) {
157  
-		self::excludeReport($reportClass);
  158
+		self::add_excluded_reports($reportClass);
158 159
 	}
159 160
 
160 161
 	/**
161  
-	 * Exclude a certain report class from the list of Reports in the CMS
162  
-	 * @static
163  
-	 * @param $reportClass
  162
+	 * Exclude certain reports classes from the list of Reports in the CMS
  163
+	 * @param $reportClass Can be either a string with the report classname or an array of reports classnames
164 164
 	 */
165  
-	static function excludeReport($reportClass) {
166  
-		self::$excluded_reports[] = $reportClass;   //add to the excluded reports, so this report doesn't get used
  165
+	static function add_excluded_reports($reportClass) {
  166
+		if (is_array($reportClass)) {
  167
+			self::$excluded_reports = array_merge(self::$excluded_reports, $reportClass);
  168
+		} else {
  169
+			if (is_string($reportClass)) {
  170
+				//add to the excluded reports, so this report doesn't get used
  171
+				self::$excluded_reports[] = $reportClass;
  172
+			}
  173
+		}
  174
+	}
  175
+
  176
+
  177
+	/**
  178
+	 * Return an array of excluded reports. That is, reports that will not be included in
  179
+	 * the list of reports in report admin in the CMS.
  180
+	 * @return array
  181
+	 */
  182
+	static function get_excluded_reports() {
  183
+		return self::$excluded_reports;
167 184
 	}
168 185
 
169 186
 	/**
170 187
 	 * Return the SS_Report objects making up the given list.
171  
-	 * @return An array of SS_Report objects
  188
+	 * @return ArrayList an arraylist of SS_Report objects
172 189
 	 */
173 190
 	static function get_reports() {
174 191
 		$reports = ClassInfo::subclassesFor(get_called_class());
15  tests/reports/ReportTest.php
@@ -20,8 +20,8 @@ function testExcludeReport() {
20 20
 		}
21 21
 		$this->assertContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is in reports list');
22 22
 
23  
-		//excluse one report
24  
-		SS_Report::excludeReport('ReportTest_FakeTest');
  23
+		//exclude one report
  24
+		SS_Report::add_excluded_reports('ReportTest_FakeTest');
25 25
 
26 26
 		$reports = SS_Report::get_reports();
27 27
 		$reportNames = array();
@@ -29,6 +29,17 @@ function testExcludeReport() {
29 29
 			$reportNames[] = $report->class;
30 30
 		}
31 31
 		$this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list');
  32
+
  33
+		//exclude two reports
  34
+		SS_Report::add_excluded_reports(array('ReportTest_FakeTest','ReportTest_FakeTest2'));
  35
+
  36
+		$reports = SS_Report::get_reports();
  37
+		$reportNames = array();
  38
+		foreach($reports as $report) {
  39
+			$reportNames[] = $report->class;
  40
+		}
  41
+		$this->assertNotContains('ReportTest_FakeTest',$reportNames,'ReportTest_FakeTest is NOT in reports list');
  42
+		$this->assertNotContains('ReportTest_FakeTest2',$reportNames,'ReportTest_FakeTest2 is NOT in reports list');
32 43
 	}
33 44
 }
34 45
 

0 notes on commit 349a04d

Please sign in to comment.
Something went wrong with that request. Please try again.