silverstripe-contentreview/code/SiteTreeContentReview.php

82 lines
2.5 KiB
PHP
Raw Normal View History

2009-11-02 05:02:57 +01:00
<?php
/**
* Set dates at which content needs to be reviewed and provide
* a report and emails to alert to content needing review
*
* @package contentreview
*/
2012-07-10 18:36:05 +02:00
class SiteTreeContentReview extends DataExtension implements PermissionProvider {
2012-07-10 18:36:05 +02:00
static $db = array(
"ReviewPeriodDays" => "Int",
"NextReviewDate" => "Date",
'ReviewNotes' => 'Text',
'LastEditedByName' => 'Varchar(255)',
'OwnerNames' => 'Varchar(255)'
);
static $has_one = array(
'Owner' => 'Member',
);
2009-11-02 05:02:57 +01:00
function getOwnerName() {
if($this->owner->OwnerID && $this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
2009-11-02 05:02:57 +01:00
}
function getEditorName() {
if( $member = Member::currentUser() ) {
return $member->FirstName .' '. $member->Surname;
}
return NULL;
}
2012-07-10 18:36:05 +02:00
public function updateCMSFields(FieldList $fields) {
2009-11-02 05:02:57 +01:00
if(Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
2009-11-02 05:02:57 +01:00
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
2009-11-02 05:02:57 +01:00
$fields->addFieldsToTab("Root.Review", array(
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
new DropdownField("OwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER",
2009-11-02 05:02:57 +01:00
"Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')),
2012-07-12 11:31:52 +02:00
DateField::create(
"NextReviewDate",
_t("SiteTreeCMSWorkflow.NEXTREVIEWDATE", "Next review date (leave blank for no review)")
)->setConfig('showcalendar', true),
new DropdownField("ReviewPeriodDays", _t("SiteTreeCMSWorkflow.REVIEWFREQUENCY",
2009-11-02 05:02:57 +01:00
"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",
1 => "1 day",
7 => "1 week",
30 => "1 month",
60 => "2 months",
91 => "3 months",
121 => "4 months",
152 => "5 months",
183 => "6 months",
365 => "12 months",
)),
new TextareaField('ReviewNotes', 'Review Notes')
));
}
}
2009-11-02 05:02:57 +01:00
function onBeforeWrite() {
if($this->owner->ReviewPeriodDays && !$this->owner->NextReviewDate) {
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
}
$this->owner->LastEditedByName=$this->owner->getEditorName();
$this->owner->OwnerNames = $this->owner->getOwnerName();
2009-11-02 05:02:57 +01:00
}
2009-11-02 05:02:57 +01:00
function providePermissions() {
return array(
"EDIT_CONTENT_REVIEW_FIELDS" => array(
'name' => "Set content owners and review dates",
'category' => _t('Permissions.CONTENT_CATEGORY', 'Content permissions'),
'sort' => 50
)
);
}
}