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 {
|
2010-07-20 05:51:15 +02:00
|
|
|
|
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(
|
2013-03-18 03:20:51 +01:00
|
|
|
'ContentReviewOwner' => 'Member',
|
2012-07-10 18:36:05 +02:00
|
|
|
);
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2009-11-02 05:02:57 +01:00
|
|
|
function getOwnerName() {
|
2013-03-18 03:20:51 +01:00
|
|
|
if($this->owner->ContentReviewOwnerID && $this->owner->ContentReviewOwner()) return $this->owner->ContentReviewOwner()->FirstName . ' ' . $this->owner->ContentReviewOwner()->Surname;
|
2009-11-02 05:02:57 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02: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")) {
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2009-11-02 05:02:57 +01:00
|
|
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
2010-07-20 05:51:15 +02:00
|
|
|
|
2009-11-02 05:02:57 +01:00
|
|
|
$fields->addFieldsToTab("Root.Review", array(
|
|
|
|
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
|
2013-03-18 03:20:51 +01:00
|
|
|
new DropdownField("ContentReviewOwnerID", _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)")
|
2012-07-17 03:27:24 +02:00
|
|
|
)->setConfig('showcalendar', true)->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('datavalueformat', 'yyyy-MM-dd'),
|
2010-07-20 05:51:15 +02:00
|
|
|
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')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
|
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'));
|
|
|
|
}
|
2010-07-20 05:51:15 +02:00
|
|
|
$this->owner->LastEditedByName=$this->owner->getEditorName();
|
|
|
|
$this->owner->OwnerNames = $this->owner->getOwnerName();
|
2009-11-02 05:02:57 +01:00
|
|
|
}
|
2010-07-20 05:51:15 +02: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
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|