From 4cc6f450a6bce8565b612b59571d200e1268c55b Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Wed, 19 Feb 2014 15:58:19 +1300 Subject: [PATCH] Adding report for pages without a content review scheduled --- .../{ => reports}/PagesDueForReviewReport.php | 0 .../PagesWithoutReviewScheduleReport.php | 113 ++++++++++++++++++ 2 files changed, 113 insertions(+) rename code/{ => reports}/PagesDueForReviewReport.php (100%) create mode 100644 code/reports/PagesWithoutReviewScheduleReport.php diff --git a/code/PagesDueForReviewReport.php b/code/reports/PagesDueForReviewReport.php similarity index 100% rename from code/PagesDueForReviewReport.php rename to code/reports/PagesDueForReviewReport.php diff --git a/code/reports/PagesWithoutReviewScheduleReport.php b/code/reports/PagesWithoutReviewScheduleReport.php new file mode 100644 index 0000000..a366c28 --- /dev/null +++ b/code/reports/PagesWithoutReviewScheduleReport.php @@ -0,0 +1,113 @@ +count()) { + die('No subsite support yet!'); + } + $params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages')); + return $params; + } + + /** + * + * @return array + */ + public function columns() { + $linkBase = singleton('CMSPageEditController')->Link('show') . '/'; + $fields = array( + 'Title' => array( + 'title' => 'Page name', + 'formatting' => '$value' + ), + 'NextReviewDate' => array( + 'title' => 'Review Date', + 'casting' => 'Date->Full' + ), + 'OwnerNames' => array( + 'title' => 'Owner' + ), + 'LastEditedByName' => 'Last edited by', + 'AbsoluteLink' => array( + 'title' => 'URL', + 'formatting' => function($value, $item) { + $liveLink = $item->AbsoluteLiveLink; + $stageLink = $item->AbsoluteLink(); + return sprintf('%s %s', + $stageLink, + $liveLink ? $liveLink : $stageLink . '?stage=Stage', + $liveLink ? '(live)' : '(draft)' + ); + } + ) + ); + + return $fields; + } + + /** + * + * @param array $params + * @param string $sort + * @param array $limit + * @return DataList + */ + public function sourceRecords($params, $sort, $limit) { + $records = SiteTree::get(); + + // If there's no review dates set, default to all pages due for review now + $records = $records->where('"NextReviewDate" IS NULL OR "OwnerNames" IS NULL OR "OwnerNames" = \'\''); + + // Show virtual pages? + if(empty($params['ShowVirtualPages'])) { + $virtualPageClasses = ClassInfo::subclassesFor('VirtualPage'); + $records = $records->where(sprintf( + '"SiteTree"."ClassName" NOT IN (\'%s\')', + implode("','", array_values($virtualPageClasses)) + )); + } + + // Turn a query into records + if($sort) { + $parts = explode(' ', $sort); + $field = $parts[0]; + $direction = $parts[1]; + + if($field == 'AbsoluteLink') { + $sort = '"URLSegment" ' . $direction; + } elseif($field == 'Subsite.Title') { + $records = $records->leftJoin("Subsite", '"Subsite"."ID" = "SiteTree"."SubsiteID"'); + } + + if($field != "LastEditedByName") { + $records = $records->sort($sort); + } + + if($limit) $records = $records->limit($limit['limit'], $limit['start']); + } + + return $records; + } +} \ No newline at end of file