mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API CHANGE: Removed SideReport class, use SSReport as the base-class for them instead.
API CHANGE: Use SSReport::register(SideReport) to explicitly register reports on the LHS of the content view. BUGFIX: Updated all cms side reports to use SSReport as the base class. (from r95884) (from r98176) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105827 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d3a26e5c16
commit
0389e784b2
10
_config.php
10
_config.php
@ -50,5 +50,13 @@ HtmlEditorConfig::get('cms')->insertButtonsAfter ('advcode', 'fullscreen', 'sepa
|
||||
HtmlEditorConfig::get('cms')->removeButtons('tablecontrols');
|
||||
HtmlEditorConfig::get('cms')->addButtonsToLine(3, 'tablecontrols');
|
||||
|
||||
// Register default side reports
|
||||
SS_Report::register("SideReport", "SideReport_ToDo");
|
||||
SS_Report::register("SideReport", "SideReport_BrokenRedirectorPages");
|
||||
SS_Report::register("SideReport", "SideReport_BrokenVirtualPages");
|
||||
SS_Report::register("SideReport", "SideReport_BrokenFiles");
|
||||
SS_Report::register("SideReport", "SideReport_BrokenLinks");
|
||||
SS_Report::register("SideReport", "SideReport_RecentlyEdited");
|
||||
SS_Report::register("SideReport", "SideReport_EmptyPages");
|
||||
|
||||
?>
|
||||
?>
|
@ -635,19 +635,25 @@ JS;
|
||||
}
|
||||
}
|
||||
|
||||
function sidereports() {
|
||||
return new SideReportsHandler($this, 'sidereports');
|
||||
/**
|
||||
* @return Array
|
||||
*/
|
||||
function SideReports() {
|
||||
return SSReport::get_reports('SideReport');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
function SideReportsForm() {
|
||||
$record = $this->currentPage();
|
||||
$reports = $this->sidereports()->getReportClasses();
|
||||
$options = array();
|
||||
foreach($reports as $report) {
|
||||
if($report != 'SideReport' && singleton($report)->canView()) {
|
||||
$options[singleton($report)->group()][singleton($report)->sort()][$report] = singleton($report)->title();
|
||||
|
||||
foreach($this->SideReports() as $report) {
|
||||
if($report->canView()) {
|
||||
$options[$report->group()][$report->sort()][$report->ID()] = $report->title();
|
||||
}
|
||||
}
|
||||
|
||||
$finalOptions = array();
|
||||
foreach($options as $group => $weights) {
|
||||
ksort($weights);
|
||||
@ -657,11 +663,8 @@ JS;
|
||||
}
|
||||
}
|
||||
}
|
||||
$selectorField = new GroupedDropdownField(
|
||||
"ReportClass",
|
||||
false,
|
||||
$finalOptions
|
||||
);
|
||||
|
||||
$selectorField = new GroupedDropdownField("ReportClass", _t('CMSMain.REPORT', 'Report'),$finalOptions);
|
||||
|
||||
$form = new Form(
|
||||
$this,
|
||||
@ -684,11 +687,21 @@ JS;
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
function doShowSideReport($data, $form) {
|
||||
$form = $this->sidereports()->getForm($data['ReportClass'], $data);
|
||||
return $form->forTemplate();
|
||||
function doShowSideReport() {
|
||||
$reportClass = $this->urlParams['ID'];
|
||||
$reports = $this->SideReports();
|
||||
if(isset($reports[$reportClass])) {
|
||||
$report = $reports[$reportClass];
|
||||
if($report) {
|
||||
$view = new SideReportView($this, $report);
|
||||
$view->setParameters($this->request->requestVars());
|
||||
return $view->forTemplate();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base class for the small reports that appear in the left hand site of the Site Content section of the CMS.
|
||||
* Create subclasses of this class to build new reports.
|
||||
@ -6,12 +7,15 @@
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
abstract class SideReport extends Object {
|
||||
protected $params = array();
|
||||
class SideReportView extends ViewableData {
|
||||
protected $controller, $report;
|
||||
protected $parameters;
|
||||
|
||||
abstract function records();
|
||||
abstract function fieldsToShow();
|
||||
abstract function title();
|
||||
function __construct($controller, $report) {
|
||||
$this->controller = $controller;
|
||||
$this->report = $report;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function group() {
|
||||
return 'Other';
|
||||
@ -21,47 +25,22 @@ abstract class SideReport extends Object {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getHTML() {
|
||||
$records = $this->records();
|
||||
$fieldsToShow = $this->fieldsToShow();
|
||||
function setParameters($parameters) {
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
function forTemplate() {
|
||||
$records = $this->report->records($this->parameters);
|
||||
$columns = $this->report->columns();
|
||||
|
||||
if($records && count($records)) {
|
||||
if($records && $records->Count()) {
|
||||
$result = "<ul class=\"$this->class\">\n";
|
||||
|
||||
foreach($records as $record) {
|
||||
$result .= "<li>\n";
|
||||
foreach($fieldsToShow as $fieldTitle => $fieldInfo) {
|
||||
if(isset($fieldInfo['source'])) {
|
||||
$fieldSource = $fieldInfo['source'];
|
||||
|
||||
// Legacy format for the input data
|
||||
} else {
|
||||
$fieldSource = $fieldInfo;
|
||||
$fieldInfo = array(
|
||||
'link' => true,
|
||||
'newline' => false,
|
||||
);
|
||||
}
|
||||
|
||||
$val = isset($fieldInfo['prefix']) ? $fieldInfo['prefix'] : '';
|
||||
|
||||
$fieldName = ereg_replace('[^A-Za-z0-9]+','',$fieldTitle);
|
||||
if(is_string($fieldSource)) {
|
||||
$val .= Convert::raw2xml($record->$fieldSource);
|
||||
} else {
|
||||
$val .= $record->XML_val($fieldSource[0], $fieldSource[1]);
|
||||
}
|
||||
|
||||
if(isset($fieldInfo['newline']) && $fieldInfo['newline']) $result .= "<br>";
|
||||
|
||||
if(isset($fieldInfo['link']) && $fieldInfo['link']) {
|
||||
$link = ($fieldInfo['link'] === true) ? "admin/show/$record->ID" : $fieldInfo['link'];
|
||||
$result .= "<a class=\"$fieldName\" href=\"$link\">$val</a>";
|
||||
} else {
|
||||
$result .= "<span class=\"$fieldName\">$val</span>";
|
||||
}
|
||||
|
||||
$val .= isset($fieldInfo['suffix']) ? $fieldInfo['suffix'] : '';
|
||||
foreach($columns as $source => $info) {
|
||||
if(is_string($info)) $info = array('title' => $info);
|
||||
$result .= $this->formatValue($record, $source, $info);
|
||||
}
|
||||
$result .= "\n</li>\n";
|
||||
}
|
||||
@ -70,49 +49,71 @@ abstract class SideReport extends Object {
|
||||
$result = "<p class=\"message notice\">" .
|
||||
sprintf(
|
||||
_t('SideReport.REPEMPTY','The %s report is empty.',PR_MEDIUM,'%s is a report title'),
|
||||
$this->title()
|
||||
$this->report->title()
|
||||
)
|
||||
. "</p>";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function setParams($params) {
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
// if your batchaction has parameters, return a fieldset here
|
||||
function getParameterFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function canView() {
|
||||
return true;
|
||||
protected function formatValue($record, $source, $info) {
|
||||
// Field sources
|
||||
//if(is_string($source)) {
|
||||
$val = Convert::raw2xml($record->$source);
|
||||
//} else {
|
||||
// $val = $record->val($source[0], $source[1]);
|
||||
//}
|
||||
|
||||
// Formatting, a la TableListField
|
||||
if(!empty($info['formatting'])) {
|
||||
$format = str_replace('$value', "__VAL__", $info['formatting']);
|
||||
$format = preg_replace('/\$([A-Za-z0-9-_]+)/','$record->$1', $format);
|
||||
$format = str_replace('__VAL__', '$val', $format);
|
||||
$val = eval('return "' . $format . '";');
|
||||
}
|
||||
|
||||
$prefix = empty($info['newline']) ? "" : "<br>";
|
||||
|
||||
|
||||
$cssClass = ereg_replace('[^A-Za-z0-9]+','',$info['title']);
|
||||
if(isset($info['link']) && $info['link']) {
|
||||
$link = ($info['link'] === true) ? "admin/show/$record->ID" : $info['link'];
|
||||
return $prefix . "<a class=\"$cssClass\" href=\"$link\">$val</a>";
|
||||
} else {
|
||||
return $prefix . "<span class=\"$cssClass\">$val</span>";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Content side-report listing empty pages
|
||||
*
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_EmptyPages extends SideReport {
|
||||
class SideReport_EmptyPages extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.EMPTYPAGES',"Pages with no content");
|
||||
}
|
||||
|
||||
function group() {
|
||||
return "Content reports";
|
||||
}
|
||||
function sort() {
|
||||
return 100;
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p> </p>'", '"Title"');
|
||||
}
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -123,7 +124,7 @@ class SideReport_EmptyPages extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_RecentlyEdited extends SideReport {
|
||||
class SideReport_RecentlyEdited extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks");
|
||||
}
|
||||
@ -133,13 +134,16 @@ class SideReport_RecentlyEdited extends SideReport {
|
||||
function sort() {
|
||||
return 200;
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
$threshold = strtotime('-14 days', SS_Datetime::now()->Format('U'));
|
||||
return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC");
|
||||
}
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -148,7 +152,7 @@ class SideReport_RecentlyEdited extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_ToDo extends SideReport {
|
||||
class SideReport_ToDo extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.TODO',"Pages with To Do items");
|
||||
}
|
||||
@ -181,14 +185,14 @@ class SideReport_ToDo extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_BrokenLinks extends SideReport {
|
||||
class SideReport_BrokenLinks extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.BROKENLINKS',"Pages with broken links");
|
||||
}
|
||||
function group() {
|
||||
return "Broken links reports";
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
// Get class names for page types that are not virtual pages or redirector pages
|
||||
$classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage'));
|
||||
$classNames = "'".join("','", $classes)."'";
|
||||
@ -197,12 +201,15 @@ class SideReport_BrokenLinks extends SideReport {
|
||||
else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenLink = 1");
|
||||
return $ret;
|
||||
}
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
function getParameterFields() {
|
||||
function parameterFields() {
|
||||
return new FieldSet(
|
||||
new CheckboxField('OnLive', 'Check live site')
|
||||
);
|
||||
@ -216,14 +223,14 @@ class SideReport_BrokenLinks extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_BrokenFiles extends SideReport {
|
||||
class SideReport_BrokenFiles extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.BROKENFILES',"Pages with broken files");
|
||||
}
|
||||
function group() {
|
||||
return "Broken links reports";
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
// Get class names for page types that are not virtual pages or redirector pages
|
||||
$classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage'));
|
||||
$classNames = "'".join("','", $classes)."'";
|
||||
@ -232,12 +239,15 @@ class SideReport_BrokenFiles extends SideReport {
|
||||
else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenFile = 1");
|
||||
return $ret;
|
||||
}
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
function getParameterFields() {
|
||||
function parameterFields() {
|
||||
return new FieldSet(
|
||||
new CheckboxField('OnLive', 'Check live site')
|
||||
);
|
||||
@ -248,26 +258,29 @@ class SideReport_BrokenFiles extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_BrokenVirtualPages extends SideReport {
|
||||
class SideReport_BrokenVirtualPages extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.BROKENVIRTUALPAGES', 'VirtualPages pointing to deleted pages');
|
||||
}
|
||||
function group() {
|
||||
return "Broken links reports";
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
$classNames = "'".join("','", ClassInfo::subclassesFor('VirtualPage'))."'";
|
||||
if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenLink = 1");
|
||||
else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenLink = 1");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
function getParameterFields() {
|
||||
function parameterFields() {
|
||||
return new FieldSet(
|
||||
new CheckboxField('OnLive', 'Check live site')
|
||||
);
|
||||
@ -278,14 +291,14 @@ class SideReport_BrokenVirtualPages extends SideReport {
|
||||
* @package cms
|
||||
* @subpackage content
|
||||
*/
|
||||
class SideReport_BrokenRedirectorPages extends SideReport {
|
||||
class SideReport_BrokenRedirectorPages extends SS_Report {
|
||||
function title() {
|
||||
return _t('SideReport.BROKENREDIRECTORPAGES', 'RedirectorPages pointing to deleted pages');
|
||||
}
|
||||
function group() {
|
||||
return "Broken links reports";
|
||||
}
|
||||
function records($params = null) {
|
||||
function sourceRecords($params = null) {
|
||||
$classNames = "'".join("','", ClassInfo::subclassesFor('RedirectorPage'))."'";
|
||||
|
||||
if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenLink = 1");
|
||||
@ -293,12 +306,15 @@ class SideReport_BrokenRedirectorPages extends SideReport {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function fieldsToShow() {
|
||||
function columns() {
|
||||
return array(
|
||||
"Title" => array("NestedTitle", array("2")),
|
||||
"Title" => array(
|
||||
"title" => "Title", // todo: use NestedTitle(2)
|
||||
"link" => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
function getParameterFields() {
|
||||
function parameterFields() {
|
||||
return new FieldSet(
|
||||
new CheckboxField('OnLive', 'Check live site')
|
||||
);
|
||||
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage reports
|
||||
*/
|
||||
class SideReportsHandler extends RequestHandler {
|
||||
static $url_handlers = array(
|
||||
'$Action' => 'handleAction'
|
||||
);
|
||||
|
||||
protected $parentController;
|
||||
|
||||
/**
|
||||
* @var String
|
||||
*/
|
||||
protected $urlSegment;
|
||||
|
||||
/**
|
||||
* @param string $parentController
|
||||
* @param string $urlSegment
|
||||
* @param string $recordClass
|
||||
*/
|
||||
function __construct($parentController, $urlSegment, $recordClass = null) {
|
||||
$this->parentController = $parentController;
|
||||
$this->urlSegment = $urlSegment;
|
||||
if($recordClass) $this->recordClass = $recordClass;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function Link() {
|
||||
return Controller::join_links($this->parentController->Link(), $this->urlSegment);
|
||||
}
|
||||
|
||||
function handleAction($request) {
|
||||
// This method can't be called without ajax.
|
||||
if(!Director::is_ajax()) return Director::redirectBack();
|
||||
|
||||
$form = $this->getForm($request->requestVar("ReportClass"), $request->requestVars());
|
||||
// TODO Accept custom actions
|
||||
return $form->forTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $reportClass
|
||||
* @param Array $data
|
||||
* @return Form
|
||||
*/
|
||||
function getForm($reportClass, $data) {
|
||||
$report = new $reportClass();
|
||||
|
||||
$fields = $report->getParameterFields();
|
||||
if(!$fields) $fields = new FieldSet();
|
||||
$fields->push(new LiteralField('ReportHtml', $report->getHTML()));
|
||||
$fields->push(new HiddenField('ReportClass', null, $reportClass));
|
||||
$fields->push(new HiddenField('ID', false, (isset($data['ID'])) ? $data['ID'] : null));
|
||||
$fields->push(new HiddenField('Locale', false, (isset($data['Locale'])) ? $data['Locale'] : null));
|
||||
|
||||
$form = new Form(
|
||||
$this,
|
||||
'ReportForm',
|
||||
$fields,
|
||||
new FieldSet(
|
||||
new FormAction('sidereport', _t('CMSMain_left.ss.REFRESH','Refresh'))
|
||||
)
|
||||
);
|
||||
$form->setFormAction($this->Link());
|
||||
$form->unsetValidator();
|
||||
$form->setFormMethod('GET');
|
||||
$form->loadDataFrom($data);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all viewable subclasses of {@link SideReport}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getReportClasses() {
|
||||
$classes = ClassInfo::subclassesFor("SideReport");
|
||||
foreach($classes as $i => $class) {
|
||||
if($class != 'SideReport') $report = singleton($class);
|
||||
if(
|
||||
$class == 'SideReport'
|
||||
|| ($report && !$report->canView())
|
||||
) {
|
||||
unset($classes[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user