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
|
|
|
|
*/
|
2012-03-05 16:07:53 +01:00
|
|
|
class ReportAdmin extends LeftAndMain implements PermissionProvider {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_segment = 'reports';
|
2008-11-02 22:27:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_rule = '/$ReportClass/$Action';
|
2008-11-02 22:27:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $menu_title = 'Reports';
|
2008-11-02 22:27:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $tree_class = 'SS_Report';
|
2012-04-05 03:04:59 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_handlers = array(
|
2012-04-10 01:15:29 +02:00
|
|
|
'$ReportClass/$Action' => 'handleAction'
|
|
|
|
);
|
|
|
|
|
2012-04-05 03:04:59 +02:00
|
|
|
/**
|
|
|
|
* Variable that describes which report we are currently viewing based on the URL (gets set in init method)
|
|
|
|
* @var String
|
|
|
|
*/
|
|
|
|
protected $reportClass;
|
|
|
|
|
2016-07-14 17:25:22 +02:00
|
|
|
/**
|
|
|
|
* @var SS_Report
|
|
|
|
*/
|
2012-04-05 03:04:59 +02:00
|
|
|
protected $reportObject;
|
2011-04-19 08:44:23 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function init() {
|
2008-10-07 07:59:03 +02:00
|
|
|
|
2012-04-05 03:04:59 +02:00
|
|
|
//set the report we are currently viewing from the URL
|
2014-05-15 04:49:41 +02:00
|
|
|
$this->reportClass = (isset($this->urlParams['ReportClass']) && $this->urlParams['ReportClass'] !== 'index')
|
|
|
|
? $this->urlParams['ReportClass']
|
|
|
|
: null;
|
2012-04-05 03:04:59 +02:00
|
|
|
$allReports = SS_Report::get_reports();
|
|
|
|
$this->reportObject = (isset($allReports[$this->reportClass])) ? $allReports[$this->reportClass] : null;
|
|
|
|
|
2016-07-14 17:25:22 +02:00
|
|
|
parent::init();
|
|
|
|
|
2012-02-23 20:19:03 +01:00
|
|
|
Requirements::css(CMS_DIR . '/css/screen.css');
|
2011-03-01 06:05:26 +01: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());
|
2011-03-01 06:05:26 +01:00
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
// Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
|
2012-04-12 10:36:25 +02:00
|
|
|
Requirements::block(FRAMEWORK_DIR . '/javascript/HtmlEditorField.js');
|
2012-07-12 16:14:17 +02:00
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin.js');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2011-03-01 06:05:26 +01:00
|
|
|
|
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
|
2011-03-01 06:05:26 +01:00
|
|
|
*
|
2009-01-05 07:17:59 +01:00
|
|
|
* @param Member $member
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function canView($member = null) {
|
2010-02-04 05:48:04 +01:00
|
|
|
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
2011-03-01 06:05:26 +01:00
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
if(!parent::canView($member)) return false;
|
2011-03-01 06:05:26 +01:00
|
|
|
|
2016-07-14 17:25:22 +02:00
|
|
|
if ($this->reportObject) return $this->reportObject->canView($member);
|
|
|
|
|
2010-02-04 05:48:04 +01:00
|
|
|
foreach($this->Reports() as $report) {
|
|
|
|
if($report->canView($member)) return true;
|
2009-01-05 07:17:59 +01:00
|
|
|
}
|
2011-03-01 06:05:26 +01:00
|
|
|
|
2010-02-04 05:48:04 +01:00
|
|
|
return false;
|
2009-01-05 07:17:59 +01:00
|
|
|
}
|
2011-03-01 06:05:26 +01:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
2011-10-26 08:10:19 +02:00
|
|
|
* Return a SS_List of SS_Report subclasses
|
2008-10-01 06:49:08 +02:00
|
|
|
* that are available for use.
|
|
|
|
*
|
2011-10-26 08:10:19 +02:00
|
|
|
* @return SS_List
|
2008-10-01 06:49:08 +02:00
|
|
|
*/
|
|
|
|
public function Reports() {
|
2011-05-05 12:40:26 +02:00
|
|
|
$output = new ArrayList();
|
2012-04-04 07:58:16 +02:00
|
|
|
foreach(SS_Report::get_reports() as $report) {
|
2010-02-04 05:50:47 +01:00
|
|
|
if($report->canView()) $output->push($report);
|
|
|
|
}
|
|
|
|
return $output;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2011-03-01 06:05:26 +01:00
|
|
|
*
|
2008-10-01 06:49:08 +02:00
|
|
|
* 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
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
static public function has_reports() {
|
2012-04-04 07:58:16 +02:00
|
|
|
return sizeof(SS_Report::get_reports()) > 0;
|
2008-04-05 05:43:58 +02:00
|
|
|
}
|
2012-04-05 03:19:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Breadcrumbs for the ReportAdmin
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param bool $unlinked
|
2012-04-05 03:19:17 +02:00
|
|
|
* @return ArrayList
|
|
|
|
*/
|
2012-04-12 01:23:15 +02:00
|
|
|
public function Breadcrumbs($unlinked = false) {
|
|
|
|
$items = parent::Breadcrumbs($unlinked);
|
2012-04-10 04:49:19 +02:00
|
|
|
|
|
|
|
// The root element should explicitly point to the root node.
|
|
|
|
// Uses session state for current record otherwise.
|
|
|
|
$items[0]->Link = singleton('ReportAdmin')->Link();
|
2012-04-05 03:19:17 +02:00
|
|
|
|
|
|
|
if ($this->reportObject) {
|
|
|
|
//build breadcrumb trail to the current report
|
|
|
|
$items->push(new ArrayData(array(
|
|
|
|
'Title' => $this->reportObject->title(),
|
|
|
|
'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q'))))
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $items;
|
2010-02-04 05:37:19 +01:00
|
|
|
}
|
2012-03-05 16:07:53 +01:00
|
|
|
|
2012-04-10 01:15:29 +02:00
|
|
|
/**
|
|
|
|
* Returns the link to the report admin section, or the specific report that is currently displayed
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param string $action Action to link to.
|
2012-04-10 01:15:29 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function Link($action = null) {
|
2014-05-15 04:49:41 +02:00
|
|
|
if ($this->reportObject) {
|
|
|
|
$link = $this->reportObject->getLink($action);
|
|
|
|
} else {
|
|
|
|
$link = self::join_links(parent::Link('index'), $action);
|
|
|
|
}
|
2012-04-10 01:15:29 +02:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function providePermissions() {
|
2012-03-05 16:07:53 +01:00
|
|
|
$title = _t("ReportAdmin.MENUTITLE", LeftAndMain::menu_title_for_class($this->class));
|
|
|
|
return array(
|
|
|
|
"CMS_ACCESS_ReportAdmin" => array(
|
2012-05-01 21:43:43 +02:00
|
|
|
'name' => _t('CMSMain.ACCESS', "Access to '{title}' section", array('title' => $title)),
|
2012-03-05 16:07:53 +01:00
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-04-04 07:58:16 +02:00
|
|
|
|
|
|
|
public function getEditForm($id = null, $fields = null) {
|
2012-04-05 03:04:59 +02:00
|
|
|
$report = $this->reportObject;
|
2012-04-04 07:58:16 +02:00
|
|
|
if($report) {
|
2012-07-12 16:14:17 +02:00
|
|
|
$fields = $report->getCMSFields();
|
2012-04-04 07:58:16 +02:00
|
|
|
} else {
|
|
|
|
// List all reports
|
2012-07-12 16:14:17 +02:00
|
|
|
$fields = new FieldList();
|
2012-04-04 07:58:16 +02:00
|
|
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
|
|
|
new GridFieldToolbarHeader(),
|
|
|
|
new GridFieldSortableHeader(),
|
2012-04-11 02:44:11 +02:00
|
|
|
new GridFieldDataColumns(),
|
2012-04-12 06:13:24 +02:00
|
|
|
new GridFieldFooter()
|
2012-04-04 07:58:16 +02:00
|
|
|
);
|
2012-05-03 13:50:01 +02:00
|
|
|
$gridField = new GridField('Reports',false, $this->Reports(), $gridFieldConfig);
|
2012-04-19 01:53:46 +02:00
|
|
|
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
|
|
|
$columns->setDisplayFields(array(
|
2012-08-26 23:17:07 +02:00
|
|
|
'title' => _t('ReportAdmin.ReportTitle', 'Title'),
|
2012-04-04 07:58:16 +02:00
|
|
|
));
|
2012-04-19 01:53:46 +02:00
|
|
|
$columns->setFieldFormatting(array(
|
2013-09-24 12:11:13 +02:00
|
|
|
'title' => function($value, &$item) {
|
|
|
|
return sprintf(
|
2013-10-01 11:17:36 +02:00
|
|
|
'<a href="%s" class="cms-panel-link">%s</a>',
|
2013-09-24 12:11:13 +02:00
|
|
|
Convert::raw2xml($item->Link),
|
|
|
|
Convert::raw2xml($value)
|
|
|
|
);
|
|
|
|
}
|
2012-04-04 07:58:16 +02:00
|
|
|
));
|
2012-04-05 04:14:09 +02:00
|
|
|
$gridField->addExtraClass('all-reports-gridfield');
|
2012-04-04 07:58:16 +02:00
|
|
|
$fields->push($gridField);
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions = new FieldList();
|
2013-05-10 15:00:57 +02:00
|
|
|
$form = CMSForm::create(
|
|
|
|
$this, "EditForm", $fields, $actions
|
|
|
|
)->setHTMLID('Form_EditForm');
|
|
|
|
$form->setResponseNegotiator($this->getResponseNegotiator());
|
2012-04-04 07:58:16 +02:00
|
|
|
$form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
|
2012-07-12 16:14:17 +02:00
|
|
|
$form->loadDataFrom($this->request->getVars());
|
2012-04-04 07:58:16 +02:00
|
|
|
|
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|