diff --git a/_config.php b/_config.php index aa1fa5c2..9246eebb 100644 --- a/_config.php +++ b/_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 +SSReport::register("SideReport", "SideReport_ToDo"); +SSReport::register("SideReport", "SideReport_BrokenRedirectorPages"); +SSReport::register("SideReport", "SideReport_BrokenVirtualPages"); +SSReport::register("SideReport", "SideReport_BrokenFiles"); +SSReport::register("SideReport", "SideReport_BrokenLinks"); +SSReport::register("SideReport", "SideReport_RecentlyEdited"); +SSReport::register("SideReport", "SideReport_EmptyPages"); -?> +?> \ No newline at end of file diff --git a/code/CMSMain.php b/code/CMSMain.php index 9adc4ef2..0b5ed4e0 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -660,18 +660,18 @@ JS; Director::redirectBack(); } } + + function SideReports() { + return SSReport::get_reports('SideReport'); + } /* * Return a dropdown for selecting reports */ function ReportSelector() { - $reports = ClassInfo::subclassesFor("SideReport"); - // $options[""] = _t('CMSMain.CHOOSEREPORT',"(Choose a report)"); - 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->ID()] = $report->title(); } $finalOptions = array(); @@ -687,17 +687,15 @@ JS; return new GroupedDropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$finalOptions); } function ReportFormParameters() { - $reports = ClassInfo::subclassesFor("SideReport"); - $forms = array(); - foreach($reports as $report) { - if ($report != 'SideReport' && singleton($report)->canView()) { - if ($fieldset = singleton($report)->getParameterFields()) { + foreach($this->SideReports() as $report) { + if ($report->canView()) { + if ($fieldset = $report->parameterFields()) { $formHtml = ''; foreach($fieldset as $field) { $formHtml .= $field->FieldHolder(); } - $forms[$report] = $formHtml; + $forms[$report->ID()] = $formHtml; } } } @@ -713,10 +711,20 @@ JS; */ function sidereport() { $reportClass = $this->urlParams['ID']; - $report = ClassInfo::exists($reportClass) ? new $reportClass() : false; - $report->setParams($this->request->requestVars()); - return $report ? $report->getHTML() : false; + $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; + } + } } + + /** * Get the versions of the current page */ diff --git a/code/SideReport.php b/code/SideReport.php index 33b865b1..1b635480 100755 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -1,16 +1,17 @@ controller = $controller; + $this->report = $report; + parent::__construct(); + } function group() { return 'Other'; @@ -20,47 +21,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 = "
'", '"Title"'); } - function fieldsToShow() { + function columns() { return array( - "Title" => array("NestedTitle", array("2")), + "Title" => array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), ); } } @@ -120,7 +118,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"); } @@ -130,13 +128,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, + ), ); } } @@ -173,14 +174,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)."'"; @@ -189,12 +190,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') ); @@ -207,14 +211,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)."'"; @@ -223,52 +227,58 @@ 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') ); } } -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') ); } } -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"); @@ -276,14 +286,38 @@ 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') ); } -} \ No newline at end of file +} + +class SideReport_ToDo extends SS_Report { + function title() { + return _t('SideReport.TODO',"To do"); + } + function sourceRecords($params = null) { + return DataObject::get("SiteTree", "\"SiteTree\".\"ToDo\" IS NOT NULL AND \"SiteTree\".\"ToDo\" <> ''", "\"SiteTree\".\"LastEdited\" DESC"); + } + function columns() { + return array( + "Title" => array( + "title" => "Title", // todo: use NestedTitle(2) + "link" => true, + ), + "ToDo" => array( + "title" => "ToDo", + "newline" => true, + ), + ); + } +}