API CHANGE now using new reporting api, module now requires 2.4

This commit is contained in:
Tom Rix 2010-02-16 23:22:49 +00:00
parent 480a0cd45a
commit cda1cd9bd1
5 changed files with 203 additions and 78 deletions

View File

@ -5,7 +5,7 @@
<tom (at) silverstripe (dot) com>
## Requirements
* SilverStripe 2.3 or newer
* SilverStripe 2.4 or newer
## Installation

View File

@ -1,3 +1,10 @@
<?php
Object::add_extension('SiteTree', 'SiteTreeContentReview');
if(class_exists('Subsite')) {
SS_Report::register('ReportAdmin', 'SubsiteReportWrapper("PagesDueForReviewReport")',20);
} else {
SS_Report::register('ReportAdmin', 'PagesDueForReviewReport',20);
}

View File

@ -0,0 +1,163 @@
<?php
/**
* Show all pages that need to be reviewed
*
* @package contentreview
*/
class PagesDueForReviewReport extends SS_Report {
function title() {
return _t('PagesDueForReviewReport.TITLE', 'Pages due for review');
}
function parameterFields() {
$params = new FieldSet();
// We need to be a bit fancier when subsites is enabled
if(class_exists('Subsite') && $subsites = DataObject::get('Subsite')) {
// javascript for subsite specific owner dropdown
Requirements::javascript('contentreview/javascript/PagesDueForReviewReport.js');
// Remember current subsite
$existingSubsite = Subsite::currentSubsiteID();
$map = array();
// Create a map of all potential owners from all applicable sites
$sites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
foreach($sites as $site) {
Subsite::changeSubsite($site);
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
// Key-preserving merge
foreach($cmsUsers->toDropdownMap('ID', 'Title') as $k => $v) {
$map[$k] = $v;
}
}
$map = $map + array('' => 'Any', '-1' => '(no owner)');
$params->push(new DropdownField("OwnerID", 'Page owner', $map));
// Restore current subsite
Subsite::changeSubsite($existingSubsite);
} else {
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
$map = $cmsUsers->map('ID', 'Title', '(no owner)');
unset($map['']);
$map = array('' => 'Any', '-1' => '(no owner)') + $map;
$params->push(new DropdownField("OwnerID", 'Page owner', $map));
}
$params->push($startDate = new CalendarDateField('ReviewDateAfter', 'Review date after or on (DD/MM/YYYY)'));
$params->push($endDate = new CalendarDateField('ReviewDateBefore', 'Review date before or on (DD/MM/YYYY)', date('d/m/Y', strtotime('midnight'))));
$endDate->mustBeAfter($startDate->Name());
$startDate->mustBeBefore($endDate->Name());
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
return $params;
}
function columns() {
$fields = array(
'Title' => array(
'title' => 'Page name',
'formatting' => '<a href=\"admin/show/$ID\" title=\"Edit page\">$value</a>'
),
'NextReviewDate' => array(
'title' => 'Review Date',
'casting' => 'Date->Full'
),
'OwnerNames' => array(
'title' => 'Owner'
),
'LastEditedByName' => 'Last edited by',
'AbsoluteLink' => array(
'title' => 'URL',
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
)
);
return $fields;
}
function sourceRecords($params, $sort, $limit) {
$wheres = array();
if(empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
// If there's no review dates set, default to all pages due for review now
$wheres[] = 'NextReviewDate < \'' . SSDatetime::now()->URLDate() . '\' + INTERVAL 1 DAY';
} else {
// Review date before
if(!empty($params['ReviewDateBefore'])) {
list($day, $month, $year) = explode('/', $_REQUEST['ReviewDateBefore']);
$reviewDate = "$year-$month-$day";
$wheres[] = 'NextReviewDate < \'' . Convert::raw2sql($reviewDate) . '\' + INTERVAL 1 DAY';
}
// Review date after
if(!empty($params['ReviewDateAfter'])) {
list($day, $month, $year) = explode('/', $_REQUEST['ReviewDateAfter']);
$reviewDate = "$year-$month-$day";
$wheres[] = 'NextReviewDate >= \'' . Convert::raw2sql($reviewDate) . '\'';
}
}
// Show virtual pages?
if(empty($params['ShowVirtualPages'])) {
$wheres[] = '"SiteTree"."ClassName" != \'VirtualPage\' AND "SiteTree"."ClassName" != \'SubsitesVirtualPage\'';
}
// We use different dropdown depending on the subsite
$ownerIdParam = 'OwnerID';
// Owner dropdown
if(!empty($params[$ownerIdParam])) {
$ownerID = (int)$params[$ownerIdParam];
// We use -1 here to distinguish between No Owner and Any
if($ownerID == -1) $ownerID = 0;
$wheres[] = 'OwnerID = ' . $ownerID;
}
$query = singleton("SiteTree")->extendedSQL(join(' AND ', $wheres));
$query->select[] = Member::get_title_sql('Owner').' AS OwnerNames';
$query->from[] = 'LEFT JOIN "Member" AS "Owner" ON "SiteTree"."OwnerID" = "Owner"."ID"';
// 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') {
$query->from[] = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
}
if($field != "LastEditedByName") {
$query->orderby = $sort;
}
}
$records = singleton('SiteTree')->buildDataObjectSet($query->execute(), 'DataObjectSet', $query);
// var_dump($records);
if($records) {
foreach($records as $record) {
$record->LastEditedByName = $record->LastEditedBy()->Title;
}
if($sort && $field != "LastEditedByName") $records->sort($sort);
// Apply limit after that filtering.
if($limit) return $records->getRange($limit['start'], $limit['limit']);
else return $records;
}
}
}
?>

View File

@ -1,76 +0,0 @@
<?php
/**
* Report to show pages that will be due for review soon
*
* @package contentreview
*/
class PagesDueForReviewSideReport extends SideReport {
function title() {
return _t('PagesDueForReviewSideReport.TITLE', 'Pages due for review');
}
function group() {
return "Content reports";
}
function sort() {
return -10;
}
function records() {
$where = array();
if(isset($this->params['ReviewDate']) && $this->params['ReviewDate']) {
$where[] = 'NextReviewDate <= \'' . Convert::raw2sql($this->params['ReviewDate']) . '\'';
} else {
$where[] = 'NextReviewDate <= \'' . SS_Datetime::now()->URLDate() . '\'';
}
if(isset($this->params['OwnerID'])) {
switch($this->params['OwnerID']) {
case 'any-owner':
break;
case 'no-owner':
$where[] = 'OwnerID = 0';
default:
$where[] = 'OwnerID = ' . (int) $this->params['OwnerID'];
break;
}
}
return DataObject::get('SiteTree', $where);
}
function fieldsToShow() {
return array(
"Title" => array(
"source" => array("NestedTitle", array("2")),
"link" => true,
),
"Date" => array(
"prefix" => 'Due for review on ',
"source" => "NextReviewDate",
),
"Owner" => array(
"prefix" => ', owned by ',
"source" => "OwnerName"
)
);
}
function getParameterFields() {
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
$options = array(
'any-owner' => 'Any owner',
'no-owner' => 'No owner'
);
$options = array_merge($options, $cmsUsers->map('ID', 'Title'));
return new FieldSet(
new DateField('ReviewDate', 'Review date (YYYY-MM-DD)'),
new DropdownField("OwnerID", 'Page owner', $options)
);
}
}
?>

View File

@ -0,0 +1,31 @@
(function($) {
// Hide all owner dropdowns except the one for the current subsite
function showCorrectSubsiteIDDropdown(value) {
var domid = 'OwnerID' + value;
var ownerIDDropdowns = $('div.subsiteSpecificOwnerID');
for(var i = 0; i < ownerIDDropdowns.length; i++) {
if(ownerIDDropdowns[i].id == domid)
$(ownerIDDropdowns[i]).show();
else
$(ownerIDDropdowns[i]).hide();
}
}
// Call method to show on report load
$('#Form_EditForm_SubsiteIDWithOwner').livequery(
function() {
showCorrectSubsiteIDDropdown(this.value);
}
);
// Call method to show on dropdown change
$('#Form_EditForm_SubsiteIDWithOwner').livequery('change',
function() {
showCorrectSubsiteIDDropdown(this.value);
}
);
})(jQuery);