2010-02-17 00:22:49 +01:00
|
|
|
<?php
|
2010-05-24 07:12:43 +02:00
|
|
|
require_once 'Zend/Date.php';
|
2010-02-17 00:22:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show all pages that need to be reviewed
|
|
|
|
*
|
|
|
|
* @package contentreview
|
|
|
|
*/
|
|
|
|
class PagesDueForReviewReport extends SS_Report {
|
2014-02-13 02:07:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function title() {
|
2010-02-17 00:22:49 +01:00
|
|
|
return _t('PagesDueForReviewReport.TITLE', 'Pages due for review');
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return \FieldList
|
|
|
|
*/
|
|
|
|
public function parameterFields() {
|
2012-07-10 18:36:05 +02:00
|
|
|
$params = new FieldList();
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// We need to be a bit fancier when subsites is enabled
|
|
|
|
if(class_exists('Subsite') && $subsites = DataObject::get('Subsite')) {
|
2014-02-24 01:38:16 +01:00
|
|
|
|
|
|
|
throw new Exception('feature missing, check with subsites');
|
2010-02-17 00:22:49 +01:00
|
|
|
// javascript for subsite specific owner dropdown
|
2012-07-10 18:36:05 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
|
|
|
|
Requirements::javascript('contentreview/javascript/PagesDueForReview.js');
|
2010-02-17 00:22:49 +01:00
|
|
|
|
|
|
|
// Remember current subsite
|
|
|
|
$existingSubsite = Subsite::currentSubsiteID();
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
$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
|
2012-07-10 18:36:05 +02:00
|
|
|
foreach($cmsUsers->map('ID', 'Title') as $k => $v) {
|
2010-02-17 00:22:49 +01:00
|
|
|
$map[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
$map = $map + array('' => 'Any', '-1' => '(no owner)');
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2013-03-18 03:20:51 +01:00
|
|
|
$params->push(new DropdownField("ContentReviewOwnerID", 'Page owner', $map));
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// Restore current subsite
|
|
|
|
Subsite::changeSubsite($existingSubsite);
|
|
|
|
} else {
|
|
|
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
2012-07-10 18:36:05 +02:00
|
|
|
$map = $cmsUsers->map('ID', 'Title', '(no owner)')->toArray();
|
2010-02-17 00:22:49 +01:00
|
|
|
unset($map['']);
|
|
|
|
$map = array('' => 'Any', '-1' => '(no owner)') + $map;
|
2013-03-18 03:20:51 +01:00
|
|
|
$params->push(new DropdownField("ContentReviewOwnerID", 'Page owner', $map));
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2012-07-10 18:36:05 +02:00
|
|
|
$params->push(
|
|
|
|
DateField::create('ReviewDateAfter', 'Review date after or on')
|
|
|
|
->setConfig('showcalendar', true)
|
|
|
|
);
|
|
|
|
$params->push(
|
|
|
|
DateField::create('ReviewDateBefore', 'Review date before or on', date('d/m/Y', strtotime('midnight')))
|
|
|
|
->setConfig('showcalendar', true)
|
|
|
|
);
|
2010-02-17 00:22:49 +01:00
|
|
|
|
|
|
|
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
return $params;
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function columns() {
|
2012-07-10 18:36:05 +02:00
|
|
|
$linkBase = singleton('CMSPageEditController')->Link('show') . '/';
|
2010-02-17 00:22:49 +01:00
|
|
|
$fields = array(
|
|
|
|
'Title' => array(
|
|
|
|
'title' => 'Page name',
|
2012-07-10 18:36:05 +02:00
|
|
|
'formatting' => '<a href=\"' . $linkBase . '/$ID\" title=\"Edit page\">$value</a>'
|
2010-02-17 00:22:49 +01:00
|
|
|
),
|
2014-02-24 01:38:16 +01:00
|
|
|
'ContentReviewType' => array(
|
|
|
|
'title' => 'Settings are',
|
|
|
|
'formatting' => function($value, $item) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
),
|
2010-02-17 00:22:49 +01:00
|
|
|
'NextReviewDate' => array(
|
|
|
|
'title' => 'Review Date',
|
2014-02-24 01:38:16 +01:00
|
|
|
'casting' => 'Date->Full',
|
|
|
|
'formatting' => function($value, $item) {
|
|
|
|
if($item->ContentReviewType == 'Disabled') {
|
|
|
|
return 'disabled';
|
|
|
|
}
|
|
|
|
if($item->ContentReviewType == 'Inherit') {
|
2014-02-24 09:10:10 +01:00
|
|
|
$setting = SiteTreeContentReview::getOptions($item);
|
2014-02-24 01:38:16 +01:00
|
|
|
if(!$setting) {
|
|
|
|
return 'disabled';
|
|
|
|
}
|
2014-02-24 08:19:44 +01:00
|
|
|
return $item->get_next_review_date($setting, $item)->Full();
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
2010-02-17 00:22:49 +01:00
|
|
|
),
|
|
|
|
'OwnerNames' => array(
|
2014-02-24 01:38:16 +01:00
|
|
|
'title' => 'Owner',
|
|
|
|
'formatting' => function($value, $item) {
|
|
|
|
if($item->ContentReviewType == 'Disabled') {
|
|
|
|
return 'disabled';
|
|
|
|
}
|
|
|
|
if($item->ContentReviewType == 'Inherit') {
|
2014-02-24 09:10:10 +01:00
|
|
|
$setting = SiteTreeContentReview::getOptions($item);
|
2014-02-24 01:38:16 +01:00
|
|
|
if(!$setting) {
|
|
|
|
return 'disabled';
|
|
|
|
}
|
|
|
|
return $setting->getOwnerNames();
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
2010-02-17 00:22:49 +01:00
|
|
|
),
|
|
|
|
'LastEditedByName' => 'Last edited by',
|
|
|
|
'AbsoluteLink' => array(
|
|
|
|
'title' => 'URL',
|
2012-07-10 18:36:05 +02:00
|
|
|
'formatting' => function($value, $item) {
|
|
|
|
$liveLink = $item->AbsoluteLiveLink;
|
|
|
|
$stageLink = $item->AbsoluteLink();
|
|
|
|
return sprintf('%s <a href="%s">%s</a>',
|
|
|
|
$stageLink,
|
|
|
|
$liveLink ? $liveLink : $stageLink . '?stage=Stage',
|
|
|
|
$liveLink ? '(live)' : '(draft)'
|
|
|
|
);
|
|
|
|
}
|
2010-02-17 00:22:49 +01:00
|
|
|
)
|
|
|
|
);
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
return $fields;
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
* @param string $sort
|
|
|
|
* @param array $limit
|
|
|
|
* @return DataList
|
|
|
|
*/
|
|
|
|
public function sourceRecords($params, $sort, $limit) {
|
2012-07-10 18:36:05 +02:00
|
|
|
$records = SiteTree::get();
|
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
if(empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
|
|
|
|
// If there's no review dates set, default to all pages due for review now
|
2012-07-10 18:36:05 +02:00
|
|
|
$reviewDate = new Zend_Date(SS_Datetime::now()->Format('U'));
|
2010-05-24 07:12:43 +02:00
|
|
|
$reviewDate->add(1, Zend_Date::DAY);
|
2014-02-24 09:10:10 +01:00
|
|
|
$records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
2010-02-17 00:22:49 +01:00
|
|
|
} else {
|
|
|
|
// Review date before
|
|
|
|
if(!empty($params['ReviewDateBefore'])) {
|
2012-07-10 18:36:05 +02:00
|
|
|
// TODO Get value from DateField->dataValue() once we have access to form elements here
|
|
|
|
$reviewDate = new Zend_Date($params['ReviewDateBefore'], i18n::get_date_format());
|
2010-05-24 07:12:43 +02:00
|
|
|
$reviewDate->add(1, Zend_Date::DAY);
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// Review date after
|
|
|
|
if(!empty($params['ReviewDateAfter'])) {
|
2012-07-10 18:36:05 +02:00
|
|
|
// TODO Get value from DateField->dataValue() once we have access to form elements here
|
|
|
|
$reviewDate = new Zend_Date($params['ReviewDateAfter'], i18n::get_date_format());
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->where(sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// Show virtual pages?
|
|
|
|
if(empty($params['ShowVirtualPages'])) {
|
2011-09-12 14:02:36 +02:00
|
|
|
$virtualPageClasses = ClassInfo::subclassesFor('VirtualPage');
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->where(sprintf(
|
2011-09-12 14:02:36 +02:00
|
|
|
'"SiteTree"."ClassName" NOT IN (\'%s\')',
|
|
|
|
implode("','", array_values($virtualPageClasses))
|
2012-07-10 18:36:05 +02:00
|
|
|
));
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// Owner dropdown
|
2013-03-18 03:20:51 +01:00
|
|
|
if(!empty($params['ContentReviewOwnerID'])) {
|
|
|
|
$ownerID = (int)$params['ContentReviewOwnerID'];
|
2010-02-17 00:22:49 +01:00
|
|
|
// We use -1 here to distinguish between No Owner and Any
|
|
|
|
if($ownerID == -1) $ownerID = 0;
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->filter('ContentReviewOwnerID', $ownerID);
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
// Turn a query into records
|
|
|
|
if($sort) {
|
|
|
|
$parts = explode(' ', $sort);
|
|
|
|
$field = $parts[0];
|
|
|
|
$direction = $parts[1];
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
if($field == 'AbsoluteLink') {
|
2010-05-24 07:12:43 +02:00
|
|
|
$sort = '"URLSegment" ' . $direction;
|
2010-02-17 00:22:49 +01:00
|
|
|
} elseif($field == 'Subsite.Title') {
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->leftJoin("Subsite", '"Subsite"."ID" = "SiteTree"."SubsiteID"');
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2010-02-17 00:22:49 +01:00
|
|
|
if($field != "LastEditedByName") {
|
2013-09-25 14:35:38 +02:00
|
|
|
$records = $records->sort($sort);
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2011-09-12 14:02:10 +02:00
|
|
|
|
2013-09-25 14:35:38 +02:00
|
|
|
if($limit) $records = $records->limit($limit['limit'], $limit['start']);
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2012-07-10 18:36:05 +02:00
|
|
|
|
|
|
|
return $records;
|
2010-02-17 00:22:49 +01:00
|
|
|
}
|
2011-09-12 14:02:10 +02:00
|
|
|
}
|