mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT: Refactored to handling of valid report-classes in ReportAdmin. Added new method to retrieve all valid report-class names (getReportClassNames) and updated 'canView', 'Reports', 'EditForm' and 'has_reports'.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@80034 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
5cfcf03d11
commit
e46075d3fb
@ -37,6 +37,37 @@ 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 = 'SSReport';
|
||||
$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
|
||||
@ -54,15 +85,15 @@ class ReportAdmin extends LeftAndMain {
|
||||
if(!parent::canView($member)) return false;
|
||||
|
||||
$hasViewableSubclasses = false;
|
||||
$subClasses = array_values(ClassInfo::subclassesFor('SSReport'));
|
||||
$subClasses = array_values( $this->getReportClassNames() );
|
||||
|
||||
foreach($subClasses as $subclass) {
|
||||
// Remove abstract classes and LeftAndMain
|
||||
$classReflection = new ReflectionClass($subclass);
|
||||
if($classReflection->isInstantiable() && $subclass != 'SSReport') {
|
||||
if(singleton($subclass)->canView()) $hasViewableSubclasses = true;
|
||||
}
|
||||
|
||||
if(singleton($subclass)->canView()) {
|
||||
$hasViewableSubclasses = true;
|
||||
}
|
||||
|
||||
}
|
||||
return $hasViewableSubclasses;
|
||||
}
|
||||
|
||||
@ -74,15 +105,13 @@ class ReportAdmin extends LeftAndMain {
|
||||
*/
|
||||
public function Reports() {
|
||||
$processedReports = array();
|
||||
$subClasses = ClassInfo::subclassesFor('SSReport');
|
||||
$subClasses = $this->getReportClassNames();
|
||||
|
||||
if($subClasses) {
|
||||
foreach($subClasses as $subClass) {
|
||||
if($subClass != 'SSReport') {
|
||||
$processedReports[] = new $subClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$reports = new DataObjectSet($processedReports);
|
||||
|
||||
@ -134,16 +163,14 @@ class ReportAdmin extends LeftAndMain {
|
||||
public function EditForm() {
|
||||
$ids = array();
|
||||
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
||||
$subClasses = ClassInfo::subclassesFor('SSReport');
|
||||
$subClasses = $this->getReportClassNames();
|
||||
|
||||
if($subClasses) {
|
||||
foreach($subClasses as $subClass) {
|
||||
if($subClass != 'SSReport') {
|
||||
$obj = new $subClass();
|
||||
$ids[] = $obj->ID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
||||
else return false;
|
||||
@ -192,16 +219,12 @@ class ReportAdmin extends LeftAndMain {
|
||||
* @return boolean
|
||||
*/
|
||||
public static function has_reports() {
|
||||
$subClasses = ClassInfo::subclassesFor('SSReport');
|
||||
|
||||
$subClasses = $this->getReportClassNames();
|
||||
if($subClasses) {
|
||||
foreach($subClasses as $subClass) {
|
||||
if($subClass != 'SSReport') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user