mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
3.0 compatibility
This commit is contained in:
parent
b32da03dfc
commit
7257fa52ce
@ -12,12 +12,14 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parameterFields() {
|
function parameterFields() {
|
||||||
$params = new FieldSet();
|
$params = new FieldList();
|
||||||
|
|
||||||
// We need to be a bit fancier when subsites is enabled
|
// We need to be a bit fancier when subsites is enabled
|
||||||
if(class_exists('Subsite') && $subsites = DataObject::get('Subsite')) {
|
if(class_exists('Subsite') && $subsites = DataObject::get('Subsite')) {
|
||||||
|
|
||||||
// javascript for subsite specific owner dropdown
|
// javascript for subsite specific owner dropdown
|
||||||
Requirements::javascript('contentreview/javascript/PagesDueForReviewReport.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
|
||||||
|
Requirements::javascript('contentreview/javascript/PagesDueForReview.js');
|
||||||
|
|
||||||
// Remember current subsite
|
// Remember current subsite
|
||||||
$existingSubsite = Subsite::currentSubsiteID();
|
$existingSubsite = Subsite::currentSubsiteID();
|
||||||
@ -31,7 +33,7 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
|
|
||||||
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
||||||
// Key-preserving merge
|
// Key-preserving merge
|
||||||
foreach($cmsUsers->toDropdownMap('ID', 'Title') as $k => $v) {
|
foreach($cmsUsers->map('ID', 'Title') as $k => $v) {
|
||||||
$map[$k] = $v;
|
$map[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,16 +46,20 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
Subsite::changeSubsite($existingSubsite);
|
Subsite::changeSubsite($existingSubsite);
|
||||||
} else {
|
} else {
|
||||||
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
||||||
$map = $cmsUsers->map('ID', 'Title', '(no owner)');
|
$map = $cmsUsers->map('ID', 'Title', '(no owner)')->toArray();
|
||||||
unset($map['']);
|
unset($map['']);
|
||||||
$map = array('' => 'Any', '-1' => '(no owner)') + $map;
|
$map = array('' => 'Any', '-1' => '(no owner)') + $map;
|
||||||
$params->push(new DropdownField("OwnerID", 'Page 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(
|
||||||
$params->push($endDate = new CalendarDateField('ReviewDateBefore', 'Review date before or on (DD/MM/YYYY)', date('d/m/Y', strtotime('midnight'))));
|
DateField::create('ReviewDateAfter', 'Review date after or on')
|
||||||
$endDate->mustBeAfter($startDate->Name());
|
->setConfig('showcalendar', true)
|
||||||
$startDate->mustBeBefore($endDate->Name());
|
);
|
||||||
|
$params->push(
|
||||||
|
DateField::create('ReviewDateBefore', 'Review date before or on', date('d/m/Y', strtotime('midnight')))
|
||||||
|
->setConfig('showcalendar', true)
|
||||||
|
);
|
||||||
|
|
||||||
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
|
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
|
||||||
|
|
||||||
@ -61,10 +67,11 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function columns() {
|
function columns() {
|
||||||
|
$linkBase = singleton('CMSPageEditController')->Link('show') . '/';
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'Title' => array(
|
'Title' => array(
|
||||||
'title' => 'Page name',
|
'title' => 'Page name',
|
||||||
'formatting' => '<a href=\"admin/show/$ID\" title=\"Edit page\">$value</a>'
|
'formatting' => '<a href=\"' . $linkBase . '/$ID\" title=\"Edit page\">$value</a>'
|
||||||
),
|
),
|
||||||
'NextReviewDate' => array(
|
'NextReviewDate' => array(
|
||||||
'title' => 'Review Date',
|
'title' => 'Review Date',
|
||||||
@ -76,7 +83,15 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
'LastEditedByName' => 'Last edited by',
|
'LastEditedByName' => 'Last edited by',
|
||||||
'AbsoluteLink' => array(
|
'AbsoluteLink' => array(
|
||||||
'title' => 'URL',
|
'title' => 'URL',
|
||||||
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
|
'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)'
|
||||||
|
);
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -84,52 +99,49 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sourceRecords($params, $sort, $limit) {
|
function sourceRecords($params, $sort, $limit) {
|
||||||
|
$records = SiteTree::get();
|
||||||
|
|
||||||
$wheres = array();
|
$wheres = array();
|
||||||
|
|
||||||
if(empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
|
if(empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
|
||||||
// If there's no review dates set, default to all pages due for review now
|
// If there's no review dates set, default to all pages due for review now
|
||||||
$reviewDate = new Zend_Date(SS_Datetime::now()->getValue());
|
$reviewDate = new Zend_Date(SS_Datetime::now()->Format('U'));
|
||||||
$reviewDate->add(1, Zend_Date::DAY);
|
$reviewDate->add(1, Zend_Date::DAY);
|
||||||
$wheres[] = sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
$records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
||||||
} else {
|
} else {
|
||||||
// Review date before
|
// Review date before
|
||||||
if(!empty($params['ReviewDateBefore'])) {
|
if(!empty($params['ReviewDateBefore'])) {
|
||||||
list($day, $month, $year) = explode('/', $params['ReviewDateBefore']);
|
// TODO Get value from DateField->dataValue() once we have access to form elements here
|
||||||
$reviewDate = new Zend_Date("$year-$month-$day");
|
$reviewDate = new Zend_Date($params['ReviewDateBefore'], i18n::get_date_format());
|
||||||
$reviewDate->add(1, Zend_Date::DAY);
|
$reviewDate->add(1, Zend_Date::DAY);
|
||||||
$wheres[] = sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
$records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Review date after
|
// Review date after
|
||||||
if(!empty($params['ReviewDateAfter'])) {
|
if(!empty($params['ReviewDateAfter'])) {
|
||||||
list($day, $month, $year) = explode('/', $params['ReviewDateAfter']);
|
// TODO Get value from DateField->dataValue() once we have access to form elements here
|
||||||
$reviewDate = new Zend_Date("$year-$month-$day");
|
$reviewDate = new Zend_Date($params['ReviewDateAfter'], i18n::get_date_format());
|
||||||
$wheres[] = sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
$records->where(sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show virtual pages?
|
// Show virtual pages?
|
||||||
if(empty($params['ShowVirtualPages'])) {
|
if(empty($params['ShowVirtualPages'])) {
|
||||||
$virtualPageClasses = ClassInfo::subclassesFor('VirtualPage');
|
$virtualPageClasses = ClassInfo::subclassesFor('VirtualPage');
|
||||||
$wheres[] = sprintf(
|
$records->where(sprintf(
|
||||||
'"SiteTree"."ClassName" NOT IN (\'%s\')',
|
'"SiteTree"."ClassName" NOT IN (\'%s\')',
|
||||||
implode("','", array_values($virtualPageClasses))
|
implode("','", array_values($virtualPageClasses))
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use different dropdown depending on the subsite
|
|
||||||
$ownerIdParam = 'OwnerID';
|
|
||||||
|
|
||||||
// Owner dropdown
|
// Owner dropdown
|
||||||
if(!empty($params[$ownerIdParam])) {
|
if(!empty($params['OwnerID'])) {
|
||||||
$ownerID = (int)$params[$ownerIdParam];
|
$ownerID = (int)$params['OwnerID'];
|
||||||
// We use -1 here to distinguish between No Owner and Any
|
// We use -1 here to distinguish between No Owner and Any
|
||||||
if($ownerID == -1) $ownerID = 0;
|
if($ownerID == -1) $ownerID = 0;
|
||||||
$wheres[] = '"OwnerID" = ' . $ownerID;
|
$records->addFilter(array('OwnerID' => $ownerID));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = singleton("SiteTree")->extendedSQL(join(' AND ', $wheres));
|
|
||||||
|
|
||||||
// Turn a query into records
|
// Turn a query into records
|
||||||
if($sort) {
|
if($sort) {
|
||||||
$parts = explode(' ', $sort);
|
$parts = explode(' ', $sort);
|
||||||
@ -139,23 +151,16 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
if($field == 'AbsoluteLink') {
|
if($field == 'AbsoluteLink') {
|
||||||
$sort = '"URLSegment" ' . $direction;
|
$sort = '"URLSegment" ' . $direction;
|
||||||
} elseif($field == 'Subsite.Title') {
|
} elseif($field == 'Subsite.Title') {
|
||||||
$query->from[] = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
$records->leftJoin("Subsite", '"Subsite"."ID" = "SiteTree"."SubsiteID"');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field != "LastEditedByName") {
|
if($field != "LastEditedByName") {
|
||||||
$query->orderby = $sort;
|
$records->sort($sort);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$records = singleton('SiteTree')->buildDataObjectSet($query->execute(), 'DataObjectSet', $query);
|
if($limit) $records->limit($limit['start'], $limit['limit']);
|
||||||
|
|
||||||
if($records) {
|
|
||||||
|
|
||||||
if($sort && $field != "LastEditedByName") $records->sort($sort);
|
|
||||||
|
|
||||||
// Apply limit after that filtering.
|
|
||||||
if($limit) return $records->getRange($limit['start'], $limit['limit']);
|
|
||||||
else return $records;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $records;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,22 +5,19 @@
|
|||||||
*
|
*
|
||||||
* @package contentreview
|
* @package contentreview
|
||||||
*/
|
*/
|
||||||
class SiteTreeContentReview extends DataObjectDecorator implements PermissionProvider {
|
class SiteTreeContentReview extends DataExtension implements PermissionProvider {
|
||||||
|
|
||||||
function extraStatics() {
|
static $db = array(
|
||||||
return array(
|
|
||||||
'db' => array(
|
|
||||||
"ReviewPeriodDays" => "Int",
|
"ReviewPeriodDays" => "Int",
|
||||||
"NextReviewDate" => "Date",
|
"NextReviewDate" => "Date",
|
||||||
'ReviewNotes' => 'Text',
|
'ReviewNotes' => 'Text',
|
||||||
'LastEditedByName' => 'Varchar(255)',
|
'LastEditedByName' => 'Varchar(255)',
|
||||||
'OwnerNames' => 'Varchar(255)'
|
'OwnerNames' => 'Varchar(255)'
|
||||||
),
|
|
||||||
'has_one' => array(
|
|
||||||
'Owner' => 'Member',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
static $has_one = array(
|
||||||
|
'Owner' => 'Member',
|
||||||
|
);
|
||||||
|
|
||||||
function getOwnerName() {
|
function getOwnerName() {
|
||||||
if($this->owner->OwnerID && $this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
|
if($this->owner->OwnerID && $this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
|
||||||
@ -33,7 +30,7 @@ class SiteTreeContentReview extends DataObjectDecorator implements PermissionPro
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateCMSFields(&$fields) {
|
public function updateCMSFields(FieldList $fields) {
|
||||||
if(Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
|
if(Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
|
||||||
|
|
||||||
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
||||||
@ -42,8 +39,10 @@ class SiteTreeContentReview extends DataObjectDecorator implements PermissionPro
|
|||||||
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
|
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
|
||||||
new DropdownField("OwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER",
|
new DropdownField("OwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER",
|
||||||
"Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')),
|
"Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')),
|
||||||
new CalendarDateField("NextReviewDate", _t("SiteTreeCMSWorkflow.NEXTREVIEWDATE",
|
DateField::create(
|
||||||
"Next review date (leave blank for no review)")),
|
"NextReviewDate",
|
||||||
|
_t("SiteTreeCMSWorkflow.NEXTREVIEWDATE", "Next review date (leave blank for no review)")
|
||||||
|
)->setConfig('showcalendar', true),
|
||||||
new DropdownField("ReviewPeriodDays", _t("SiteTreeCMSWorkflow.REVIEWFREQUENCY",
|
new DropdownField("ReviewPeriodDays", _t("SiteTreeCMSWorkflow.REVIEWFREQUENCY",
|
||||||
"Review frequency (the review date will be set to this far in the future whenever the page is published.)"), array(
|
"Review frequency (the review date will be set to this far in the future whenever the page is published.)"), array(
|
||||||
0 => "No automatic review date",
|
0 => "No automatic review date",
|
||||||
|
Loading…
Reference in New Issue
Block a user