2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2008-10-01 11:54:39 +02:00
|
|
|
* Reports section of the CMS.
|
|
|
|
*
|
2008-10-07 07:59:03 +02:00
|
|
|
* All reports that should show in the ReportAdmin section
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
* of the CMS need to subclass {@link SS_Report}, and implement
|
2008-10-09 07:54:55 +02:00
|
|
|
* the appropriate methods and variables that are required.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
* @see SS_Report
|
2008-10-01 11:54:39 +02:00
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package cms
|
|
|
|
* @subpackage reports
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
class ReportAdmin extends LeftAndMain {
|
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
static $url_segment = 'reports';
|
|
|
|
|
|
|
|
static $url_rule = '/$Action/$ID';
|
|
|
|
|
|
|
|
static $menu_title = 'Reports';
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
static $template_path = null; // defaults to (project)/templates/email
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2008-10-07 07:59:03 +02:00
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_left.js');
|
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_right.js');
|
|
|
|
|
|
|
|
Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2009-05-18 02:23:52 +02:00
|
|
|
// Set custom options for TinyMCE specific to ReportAdmin
|
|
|
|
HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
|
|
|
|
HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
|
2009-05-15 02:13:11 +02:00
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
// Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
|
|
|
|
Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2009-06-25 07:14:25 +02:00
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
$baseClass = 'SS_Report';
|
2009-06-25 07:14:25 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
/**
|
|
|
|
* Does the parent permission checks, but also
|
|
|
|
* makes sure that instantiatable subclasses of
|
|
|
|
* {@link Report} exist. By default, the CMS doesn't
|
|
|
|
* include any Reports, so there's no point in showing
|
|
|
|
*
|
|
|
|
* @param Member $member
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function canView($member = null) {
|
|
|
|
if(!$member && $member !== FALSE) {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!parent::canView($member)) return false;
|
|
|
|
|
|
|
|
$hasViewableSubclasses = false;
|
2009-06-25 07:14:25 +02:00
|
|
|
$subClasses = array_values( $this->getReportClassNames() );
|
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
foreach($subClasses as $subclass) {
|
2009-06-25 07:14:25 +02:00
|
|
|
|
|
|
|
if(singleton($subclass)->canView()) {
|
|
|
|
$hasViewableSubclasses = true;
|
|
|
|
}
|
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
}
|
|
|
|
return $hasViewableSubclasses;
|
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
* Return a DataObjectSet of SS_Report subclasses
|
2008-10-01 06:49:08 +02:00
|
|
|
* that are available for use.
|
|
|
|
*
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
public function Reports() {
|
|
|
|
$processedReports = array();
|
2009-06-25 07:14:25 +02:00
|
|
|
$subClasses = $this->getReportClassNames();
|
2008-10-01 06:49:08 +02:00
|
|
|
|
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
2009-06-25 07:14:25 +02:00
|
|
|
$processedReports[] = new $subClass();
|
2008-10-01 06:49:08 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$reports = new DataObjectSet($processedReports);
|
2008-10-01 06:49:08 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $reports;
|
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* Show a report based on the URL query string.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
* @param SS_HTTPRequest $request The HTTP request object
|
2008-10-01 06:49:08 +02:00
|
|
|
*/
|
|
|
|
public function show($request) {
|
|
|
|
$params = $request->allParams();
|
|
|
|
|
|
|
|
return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* @TODO What does this do?
|
|
|
|
*
|
|
|
|
* @param unknown_type $params
|
|
|
|
* @param unknown_type $editForm
|
|
|
|
* @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']);
|
|
|
|
|
2008-03-11 01:39:15 +01:00
|
|
|
if(Director::is_ajax()) {
|
2007-07-19 12:40:05 +02:00
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
2008-10-01 06:49:08 +02:00
|
|
|
|
2009-11-21 04:16:26 +01:00
|
|
|
return $form->formHtmlContent();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-07 07:59:03 +02:00
|
|
|
|
|
|
|
return array();
|
2008-10-01 06:49:08 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For the current report that the user is viewing,
|
|
|
|
* return a Form instance with the fields for that
|
|
|
|
* report.
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function EditForm() {
|
2008-10-01 06:49:08 +02:00
|
|
|
$ids = array();
|
2008-10-01 11:54:39 +02:00
|
|
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
2009-06-25 07:14:25 +02:00
|
|
|
$subClasses = $this->getReportClassNames();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
2009-06-25 07:14:25 +02:00
|
|
|
$obj = new $subClass();
|
|
|
|
$ids[] = $obj->ID();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
|
|
|
else return false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* Return a Form instance with fields for the
|
|
|
|
* particular report currently viewed.
|
|
|
|
*
|
|
|
|
* @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);
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
$reportClass = is_object($page) ? 'SS_Report_' . $page->ClassName : $id;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 11:54:39 +02:00
|
|
|
$obj = new $reportClass();
|
|
|
|
if($obj) $fields = $obj->getCMSFields();
|
2008-10-01 06:49:08 +02:00
|
|
|
|
|
|
|
$idField = new HiddenField('ID');
|
2007-07-19 12:40:05 +02:00
|
|
|
$idField->setValue($id);
|
2008-10-01 06:49:08 +02:00
|
|
|
$fields->push($idField);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $form;
|
|
|
|
}
|
2008-04-05 05:43:58 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-01 06:49:08 +02:00
|
|
|
* 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
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
|
|
|
* "SS_Report" that exists.
|
2008-04-05 05:43:58 +02:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function has_reports() {
|
2009-06-25 07:14:25 +02:00
|
|
|
$subClasses = $this->getReportClassNames();
|
2008-10-01 06:49:08 +02:00
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
2009-06-25 07:14:25 +02:00
|
|
|
return true;
|
2008-04-05 05:43:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2009-03-10 23:26:22 +01:00
|
|
|
?>
|