mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
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:
parent
a6308abc71
commit
1b32326b9e
@ -37,37 +37,6 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
|
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
|
* Does the parent permission checks, but also
|
||||||
* makes sure that instantiatable subclasses of
|
* makes sure that instantiatable subclasses of
|
||||||
@ -78,23 +47,16 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function canView($member = null) {
|
function canView($member = null) {
|
||||||
if(!$member && $member !== FALSE) {
|
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
||||||
$member = Member::currentUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!parent::canView($member)) return false;
|
if(!parent::canView($member)) return false;
|
||||||
|
|
||||||
$hasViewableSubclasses = false;
|
$hasViewableSubclasses = false;
|
||||||
$subClasses = array_values( $this->getReportClassNames() );
|
foreach($this->Reports() as $report) {
|
||||||
|
if($report->canView($member)) return true;
|
||||||
foreach($subClasses as $subclass) {
|
|
||||||
|
|
||||||
if(singleton($subclass)->canView()) {
|
|
||||||
$hasViewableSubclasses = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $hasViewableSubclasses;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,18 +66,7 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
* @return DataObjectSet
|
* @return DataObjectSet
|
||||||
*/
|
*/
|
||||||
public function Reports() {
|
public function Reports() {
|
||||||
$processedReports = array();
|
return new DataObjectSet(SSReport::get_reports('ReportAdmin'));
|
||||||
$subClasses = $this->getReportClassNames();
|
|
||||||
|
|
||||||
if($subClasses) {
|
|
||||||
foreach($subClasses as $subClass) {
|
|
||||||
$processedReports[] = new $subClass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$reports = new DataObjectSet($processedReports);
|
|
||||||
|
|
||||||
return $reports;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,19 +112,14 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
* @return Form
|
* @return Form
|
||||||
*/
|
*/
|
||||||
public function EditForm() {
|
public function EditForm() {
|
||||||
$ids = array();
|
|
||||||
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
||||||
$subClasses = $this->getReportClassNames();
|
|
||||||
|
|
||||||
if($subClasses) {
|
if($id) {
|
||||||
foreach($subClasses as $subClass) {
|
foreach($this->Reports() as $report) {
|
||||||
$obj = new $subClass();
|
if($id == $report->ID()) return $this->reportEditFormFor($id);
|
||||||
$ids[] = $obj->ID();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
|
||||||
else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,13 +177,7 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function has_reports() {
|
public static function has_reports() {
|
||||||
$subClasses = $this->getReportClassNames();
|
return sizeof(SSReport::get_reports('ReportAdmin')) > 0;
|
||||||
if($subClasses) {
|
|
||||||
foreach($subClasses as $subClass) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatereport() {
|
public function updatereport() {
|
||||||
|
Loading…
Reference in New Issue
Block a user