mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-04 15:18:29 +02:00
BUGFIX Fixed ReportAdmin breakages - changes to HTTPRequest required that show($params) be changes to show($request) and then check $request->allParams() for the URL parameters - this caused major breakages as this code was not updated to reflect the new URL handling changes.
ENHANCEMENT Better URL handling. Instead of "admin/showreport/something", we do "admin/report/show/something", which is more consistent with the rest of the CMS. MINOR Documentation and TODO for ReportAdmin methods git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63452 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
456c9a7cfd
commit
8c3bbdcf27
@ -5,7 +5,6 @@
|
|||||||
* @subpackage reports
|
* @subpackage reports
|
||||||
*/
|
*/
|
||||||
class ReportAdmin extends LeftAndMain {
|
class ReportAdmin extends LeftAndMain {
|
||||||
static $subitem_class = "GrantObject";
|
|
||||||
|
|
||||||
static $template_path = null; // defaults to (project)/templates/email
|
static $template_path = null; // defaults to (project)/templates/email
|
||||||
|
|
||||||
@ -58,89 +57,142 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
return "admin/reports/$action";
|
return "admin/reports/$action";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Reports(){
|
/**
|
||||||
$allReports= ClassInfo::subclassesFor("Report");
|
* Return a DataObjectSet of Report subclasses
|
||||||
foreach($allReports as $report) {
|
* that are available for use.
|
||||||
if($report != 'Report') $processedReports[] = new $report();
|
*
|
||||||
|
* @return DataObjectSet
|
||||||
|
*/
|
||||||
|
public function Reports() {
|
||||||
|
$processedReports = array();
|
||||||
|
$subClasses = ClassInfo::subclassesFor('Report');
|
||||||
|
|
||||||
|
if($subClasses) {
|
||||||
|
foreach($subClasses as $subClass) {
|
||||||
|
if($subClass != 'Report') $processedReports[] = new $subClass();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$reports = new DataObjectSet($processedReports);
|
$reports = new DataObjectSet($processedReports);
|
||||||
|
|
||||||
return $reports;
|
return $reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showreport($params) {
|
/**
|
||||||
return $this->showWithEditForm( $params, $this->getReportEditForm( $params['ID'] ) );
|
* Show a report based on the URL query string.
|
||||||
|
*
|
||||||
|
* @param HTTPRequest $request The HTTP request object
|
||||||
|
*/
|
||||||
|
public function show($request) {
|
||||||
|
$params = $request->allParams();
|
||||||
|
|
||||||
|
return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function showWithEditForm( $params, $editForm ) {
|
/**
|
||||||
if(isset($params['ID'])) {
|
* @TODO What does this do?
|
||||||
Session::set('currentPage', $params['ID']);
|
*
|
||||||
}
|
* @param unknown_type $params
|
||||||
if(isset($params['OtherID'])) {
|
* @param unknown_type $editForm
|
||||||
Session::set('currentOtherID', $params['OtherID']);
|
* @return unknown
|
||||||
}
|
*/
|
||||||
|
protected function showWithEditForm($params, $editForm) {
|
||||||
|
if(isset($params['ID'])) Session::set('currentPage', $params['ID']);
|
||||||
|
if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']);
|
||||||
|
|
||||||
if(Director::is_ajax()) {
|
if(Director::is_ajax()) {
|
||||||
SSViewer::setOption('rewriteHashlinks', false);
|
SSViewer::setOption('rewriteHashlinks', false);
|
||||||
$result = $this->customise( array( 'EditForm' => $editForm ) )->renderWith($this->getTemplatesWithSuffix("_right"));
|
|
||||||
|
$result = $this->customise(
|
||||||
|
array(
|
||||||
|
'EditForm' => $editForm
|
||||||
|
)
|
||||||
|
)->renderWith($this->getTemplatesWithSuffix('_right'));
|
||||||
|
|
||||||
return $this->getLastFormIn($result);
|
return $this->getLastFormIn($result);
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the current report that the user is viewing,
|
||||||
|
* return a Form instance with the fields for that
|
||||||
|
* report.
|
||||||
|
*
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
public function EditForm() {
|
public function EditForm() {
|
||||||
$id = (isset($_REQUEST['ID'])) ? $_REQUEST['ID'] : Session::get('currentPage');
|
$ids = array();
|
||||||
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
||||||
|
$subClasses = ClassInfo::subclassesFor('Report');
|
||||||
|
|
||||||
$subclasses = ClassInfo::subclassesFor('Report');
|
if($subClasses) {
|
||||||
|
foreach($subClasses as $subClass) {
|
||||||
foreach($subclasses as $class){
|
if($subClass != 'Report') {
|
||||||
if($class != 'Report') {
|
$obj = new $subClass();
|
||||||
$obj = new $class();
|
$ids[] = $obj->getOwnerID();
|
||||||
$ids[] = $obj->getOwnerID();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bdc: do we have any subclasses?
|
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
||||||
if(sizeof($ids) > 0){
|
else return false;
|
||||||
if($id && in_array($id, $ids)) return $this->getReportEditForm($id);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getReportEditForm($id){
|
/**
|
||||||
if(is_numeric($id))
|
* Return a Form instance with fields for the
|
||||||
$page = DataObject::get_by_id("SiteTree", $id);
|
* particular report currently viewed.
|
||||||
$reportClass = (isset($page)) ? "Report_".$page->ClassName : $id;
|
*
|
||||||
|
* @TODO Dealing with multiple data types for the
|
||||||
|
* $id parameter is confusing. Ideally, it should
|
||||||
|
* deal with only one.
|
||||||
|
*
|
||||||
|
* @param id|string $id The ID of the report, or class name
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
|
public function reportEditFormFor($id) {
|
||||||
|
$page = false;
|
||||||
|
$fields = new FieldSet();
|
||||||
|
$actions = new FieldSet();
|
||||||
|
|
||||||
|
if(is_numeric($id)) $page = DataObject::get_by_id('SiteTree', $id);
|
||||||
|
$reportClass = is_object($page) ? 'Report_' . $page->ClassName : $id;
|
||||||
|
|
||||||
$obj = new $reportClass();
|
$obj = new $reportClass();
|
||||||
$fields = $obj->getCMSFields();
|
if($obj) $fields = $obj->getCMSFields();
|
||||||
|
|
||||||
$fields->push($idField = new HiddenField("ID"));
|
|
||||||
$idField->setValue($id);
|
|
||||||
|
|
||||||
//$actions = new FieldSet(new FormAction('exporttocsv', 'Export to CVS'));
|
$idField = new HiddenField('ID');
|
||||||
$actions = new FieldSet();
|
$idField->setValue($id);
|
||||||
$form = new Form($this, "EditForm", $fields, $actions);
|
$fields->push($idField);
|
||||||
|
|
||||||
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we have reports and need to display the Reports main menu item
|
* Determine if we have reports and need
|
||||||
|
* to display the "Reports" main menu item
|
||||||
|
* in the CMS.
|
||||||
|
*
|
||||||
|
* The test for an existance of a report
|
||||||
|
* is done by checking for a subclass of
|
||||||
|
* "Report" that exists.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function has_reports() {
|
public static function has_reports() {
|
||||||
$subclasses = ClassInfo::subclassesFor('Report');
|
$subClasses = ClassInfo::subclassesFor('Report');
|
||||||
foreach($subclasses as $class){
|
|
||||||
if($class != 'Report') {
|
if($subClasses) {
|
||||||
return true;
|
foreach($subClasses as $subClass) {
|
||||||
|
if($subClass != 'Report') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user