diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index b72ccec2..42ef58ff 100755 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -37,37 +37,6 @@ class ReportAdmin extends LeftAndMain { Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js'); } - /** - * Returns an array of all the reports classnames that could be shown on this site - * to any user. Base class is not included in the response. - * It does not perform filtering based on canView(). - * - * @return An array of report class-names, i.e.: - * array("AllOrdersReport","CurrentOrdersReport","UnprintedOrderReport") - */ - public function getReportClassNames() { - - $baseClass = 'SS_Report'; - $response = array(); - - // get all sub-classnames (incl. base classname). - $classNames = ClassInfo::subclassesFor( $baseClass ); - - // drop base className - $classNames = array_diff($classNames, array($baseClass)); - - // drop report classes, which are not initiatable. - foreach($classNames as $className) { - - // Remove abstract classes - $classReflection = new ReflectionClass($className); - if($classReflection->isInstantiable() ) { - $response[] = $className; - } - } - return $response; - } - /** * Does the parent permission checks, but also * makes sure that instantiatable subclasses of @@ -78,23 +47,16 @@ class ReportAdmin extends LeftAndMain { * @return boolean */ function canView($member = null) { - if(!$member && $member !== FALSE) { - $member = Member::currentUser(); - } + if(!$member && $member !== FALSE) $member = Member::currentUser(); if(!parent::canView($member)) return false; $hasViewableSubclasses = false; - $subClasses = array_values( $this->getReportClassNames() ); - - foreach($subClasses as $subclass) { - - if(singleton($subclass)->canView()) { - $hasViewableSubclasses = true; - } - + foreach($this->Reports() as $report) { + if($report->canView($member)) return true; } - return $hasViewableSubclasses; + + return false; } /** @@ -104,18 +66,7 @@ class ReportAdmin extends LeftAndMain { * @return DataObjectSet */ public function Reports() { - $processedReports = array(); - $subClasses = $this->getReportClassNames(); - - if($subClasses) { - foreach($subClasses as $subClass) { - $processedReports[] = new $subClass(); - } - } - - $reports = new DataObjectSet($processedReports); - - return $reports; + return new DataObjectSet(SSReport::get_reports('ReportAdmin')); } /** @@ -161,19 +112,14 @@ class ReportAdmin extends LeftAndMain { * @return Form */ public function EditForm() { - $ids = array(); $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage'); - $subClasses = $this->getReportClassNames(); - if($subClasses) { - foreach($subClasses as $subClass) { - $obj = new $subClass(); - $ids[] = $obj->ID(); + if($id) { + foreach($this->Reports() as $report) { + if($id == $report->ID()) return $this->reportEditFormFor($id); } } - - if($id && in_array($id, $ids)) return $this->reportEditFormFor($id); - else return false; + return false; } /** @@ -231,13 +177,7 @@ class ReportAdmin extends LeftAndMain { * @return boolean */ public static function has_reports() { - $subClasses = $this->getReportClassNames(); - if($subClasses) { - foreach($subClasses as $subClass) { - return true; - } - } - return false; + return sizeof(SSReport::get_reports('ReportAdmin')) > 0; } public function updatereport() {