mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API CHANGE: Introduced new API for SS_Report (from r98215)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105808 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
97031196fa
commit
ce675197bb
@ -35,37 +35,6 @@ class ReportAdmin extends LeftAndMain {
|
||||
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin.Tree.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
|
||||
@ -76,23 +45,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,36 +64,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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EditForm for the class specified in request or in session variable
|
||||
*
|
||||
* @param HTTPRequest
|
||||
* @return Form
|
||||
*/
|
||||
public function EditForm($request = null) {
|
||||
$className = Session::get('currentPage');
|
||||
$requestId = $this->getRequest()->requestVar('ID');
|
||||
if(!$requestId) $requestId = $this->getRequest()->latestParam('ID');
|
||||
|
||||
if ( $requestId )
|
||||
return $this->getEditForm($requestId);
|
||||
|
||||
// $className can be null
|
||||
return $this->getEditForm($className);
|
||||
|
||||
return new DataObjectSet(SS_Report::get_reports('ReportAdmin'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,24 +79,35 @@ class ReportAdmin extends LeftAndMain {
|
||||
return $form = $this->EmptyForm();
|
||||
}
|
||||
|
||||
if (!class_exists($className)) {
|
||||
die("$className does not exist");
|
||||
}
|
||||
|
||||
Session::set('currentPage', $className);
|
||||
|
||||
$obj = new $className();
|
||||
if(!$obj->canView()) return Security::permissionFailure($this);
|
||||
$fields = new FieldSet();
|
||||
$actions = new FieldSet();
|
||||
|
||||
$fields = $obj->getCMSFields();
|
||||
$reports = SS_Report::get_reports('ReportAdmin');
|
||||
if(!isset($reports[$className])) return false;
|
||||
|
||||
$report = $reports[$className];
|
||||
if(!$report || !$report->canView()) return Security::permissionFailure($this);
|
||||
|
||||
$fields = $report->getCMSFields();
|
||||
$actions = $report->getCMSActions();
|
||||
|
||||
$idField = new HiddenField('ID');
|
||||
$idField->setValue($className);
|
||||
$idField->setValue($id);
|
||||
$fields->push($idField);
|
||||
|
||||
$actions = $obj->getCMSActions();
|
||||
|
||||
$form = new Form($this, 'EditForm', $fields, $actions);
|
||||
|
||||
// Include search criteria in the form action so that pagination works
|
||||
$filteredCriteria = array_merge($_GET, $_POST);
|
||||
foreach(array('ID','url','ajax','ctf','update','action_updatereport','SecurityID') as $notAParam) {
|
||||
unset($filteredCriteria[$notAParam]);
|
||||
}
|
||||
|
||||
$formLink = $this->Link() . '/EditForm';
|
||||
if($filteredCriteria) $formLink .= '?' . http_build_query($filteredCriteria);
|
||||
$form->setFormAction($formLink);
|
||||
$form->setTemplate('ReportAdminForm');
|
||||
$form->loadDataFrom($this->request->requestVars());
|
||||
|
||||
@ -182,13 +126,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(SS_Report::get_reports('ReportAdmin')) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
<% if EditForm %>
|
||||
$EditForm
|
||||
<% else %>
|
||||
<form id="Form_EditForm" action="admin/reports/EditForm" method="post" enctype="multipart/form-data">
|
||||
<p><% _t('WELCOME1','Welcome to the',50,'Followed by application name') %> $ApplicationName <% _t('WELCOME2','reporting section. Please choose a specific report from the left.',50) %></p>
|
||||
</form>
|
||||
<% end_if %>
|
||||
|
||||
<div class="notice-wrap"></div>
|
Loading…
Reference in New Issue
Block a user