Move to sane directory structure. Don't make 'cms' the top level of the silverstripe...
[silverstripe-elijah.git] / silverstripe-gsoc / cms / code / SideReport.php
blob87d7a4367e903b44317e42701a4572df27190e44
1 <?php
3 abstract class SideReport extends Object {
4 abstract function records();
5 abstract function fieldsToShow();
6 abstract function title();
8 function getHTML() {
9 $records = $this->records();
10 $fieldsToShow = $this->fieldsToShow();
12 if($records) {
13 $result = "<ul class=\"$this->class\">\n";
15 foreach($records as $record) {
16 $result .= "<li>\n";
17 foreach($fieldsToShow as $fieldTitle => $fieldSource) {
18 $fieldName = ereg_replace('[^A-Za-z0-9]+','',$fieldTitle);
19 if(is_string($fieldSource)) {
20 $val = $record->$fieldSource;
21 } else {
22 $val = $record->val($fieldSource[0], $fieldSource[1]);
25 $result .= "<a class=\"$fieldName\" href=\"admin/show/$record->ID\">$val</a>";
27 $result .= "\n</li>\n";
29 $result .= "</ul>\n";
30 } else {
31 $result = 'The '.$this->title().' report is empty.';
33 return $result;
37 class SideReport_EmptyPages extends SideReport {
38 function title() {
39 return "Empty pages";
41 function records() {
42 return DataObject::get("SiteTree", "Content = '' OR Content IS NULL OR Content LIKE '<p></p>' OR Content LIKE '<p>&nbsp;</p>'", "Title");
44 function fieldsToShow() {
45 return array(
46 "Title" => array("NestedTitle", array("2")),
51 class SideReport_RecentlyEdited extends SideReport {
52 function title() {
53 return "Pages edited in the last 2 weeks";
55 function records() {
56 return DataObject::get("SiteTree", "`SiteTree`.LastEdited > NOW() - INTERVAL 14 DAY", "`SiteTree`.`LastEdited` DESC");
58 function fieldsToShow() {
59 return array(
60 "Title" => array("NestedTitle", array("2")),