mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
Added content review module
This commit is contained in:
commit
9bc51d9ce9
20
README.md
Normal file
20
README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Content Review module
|
||||||
|
|
||||||
|
## Maintainer Contact
|
||||||
|
* Tom Rix (Nickname: trix)
|
||||||
|
<tom (at) silverstripe (dot) com>
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
* SilverStripe 2.3 or newer
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Drop it into your installation folder, and refresh your database schema
|
||||||
|
through `http://<your-host>/dev/build`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
When you open a page in the CMS, there will now be a Review tab.
|
||||||
|
|
||||||
|
|
3
_config.php
Normal file
3
_config.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
Object::add_extension('SiteTree', 'SiteTreeContentReview');
|
52
code/ContentReviewEmails.php
Normal file
52
code/ContentReviewEmails.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daily task to send emails to the owners of content items
|
||||||
|
* when the review date rolls around
|
||||||
|
*
|
||||||
|
* @package contentreview
|
||||||
|
*/
|
||||||
|
class ContentReviewEmails extends DailyTask {
|
||||||
|
function run($req) { $this->process(); }
|
||||||
|
function process() {
|
||||||
|
// Disable subsite filter (if installed)
|
||||||
|
if (ClassInfo::exists('Subsite')) {
|
||||||
|
$oldSubsiteState = Subsite::$disable_subsite_filter;
|
||||||
|
Subsite::$disable_subsite_filter = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pages = DataObject::get('Page', "NextReviewDate = '".date('Y-m-d')."' AND OwnerID != 0");
|
||||||
|
if ($pages && $pages->Count()) {
|
||||||
|
foreach($pages as $page) {
|
||||||
|
$owner = $page->Owner();
|
||||||
|
if ($owner) {
|
||||||
|
$sender = Security::findAnAdministrator();
|
||||||
|
$recipient = $owner;
|
||||||
|
|
||||||
|
$subject = sprintf(_t('ContentReviewEmails.SUBJECT', 'Page %s due for content review'), $page->Title);
|
||||||
|
|
||||||
|
$email = new Email();
|
||||||
|
$email->setTo($recipient->Email);
|
||||||
|
$email->setFrom(($sender->Email) ? $sender->Email : Email::getAdminEmail());
|
||||||
|
$email->setTemplate('ContentReviewEmails');
|
||||||
|
$email->setSubject($subject);
|
||||||
|
$email->populateTemplate(array(
|
||||||
|
"PageCMSLink" => "admin/show/".$page->ID,
|
||||||
|
"Recipient" => $recipient,
|
||||||
|
"Sender" => $sender,
|
||||||
|
"Page" => $page,
|
||||||
|
"StageSiteLink" => $page->Link()."?stage=stage",
|
||||||
|
"LiveSiteLink" => $page->Link()."?stage=live",
|
||||||
|
));
|
||||||
|
|
||||||
|
return $email->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revert subsite filter (if installed)
|
||||||
|
if (ClassInfo::exists('Subsite')) {
|
||||||
|
Subsite::$disable_subsite_filter = $oldSubsiteState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
code/PagesDueForReviewSideReport.php
Normal file
76
code/PagesDueForReviewSideReport.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
71
code/SiteTreeContentReview.php
Normal file
71
code/SiteTreeContentReview.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Set dates at which content needs to be reviewed and provide
|
||||||
|
* a report and emails to alert to content needing review
|
||||||
|
*
|
||||||
|
* @package contentreview
|
||||||
|
*/
|
||||||
|
class SiteTreeCMSWorkflow extends DataObjectDecorator implements PermissionProvider {
|
||||||
|
|
||||||
|
function extraStatics() {
|
||||||
|
return array(
|
||||||
|
'db' => array(
|
||||||
|
"ReviewPeriodDays" => "Int",
|
||||||
|
"NextReviewDate" => "Date",
|
||||||
|
'ReviewNotes' => 'Text'
|
||||||
|
),
|
||||||
|
'has_one' => array(
|
||||||
|
'Owner' => 'Member'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOwnerName() {
|
||||||
|
if($this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCMSFields(&$fields) {
|
||||||
|
if(Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
|
||||||
|
|
||||||
|
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
||||||
|
|
||||||
|
$fields->addFieldsToTab("Root.Review", array(
|
||||||
|
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
|
||||||
|
new DropdownField("OwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER",
|
||||||
|
"Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')),
|
||||||
|
new CalendarDateField("NextReviewDate", _t("SiteTreeCMSWorkflow.NEXTREVIEWDATE",
|
||||||
|
"Next review date (leave blank for no review)")),
|
||||||
|
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(
|
||||||
|
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')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBeforeWrite() {
|
||||||
|
if($this->owner->ReviewPeriodDays && !$this->owner->NextReviewDate) {
|
||||||
|
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user