API CHANGE: Added explicit registration of reports with SSReport::register() (from r95857)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@98175 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-02-04 04:48:04 +00:00
parent a6308abc71
commit 1b32326b9e

View File

@ -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() {