mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
ENHANCEMENT: made module independed from cmsworkflow module
This commit is contained in:
parent
68bdc33843
commit
cbaa488c84
@ -10,10 +10,10 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
function title() {
|
function title() {
|
||||||
return _t('PagesDueForReviewReport.TITLE', 'Pages due for review');
|
return _t('PagesDueForReviewReport.TITLE', 'Pages due for review');
|
||||||
}
|
}
|
||||||
|
|
||||||
function parameterFields() {
|
function parameterFields() {
|
||||||
$params = new FieldSet();
|
$params = new FieldSet();
|
||||||
|
|
||||||
// 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
|
||||||
@ -21,7 +21,7 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
|
|
||||||
// Remember current subsite
|
// Remember current subsite
|
||||||
$existingSubsite = Subsite::currentSubsiteID();
|
$existingSubsite = Subsite::currentSubsiteID();
|
||||||
|
|
||||||
$map = array();
|
$map = array();
|
||||||
|
|
||||||
// Create a map of all potential owners from all applicable sites
|
// Create a map of all potential owners from all applicable sites
|
||||||
@ -35,11 +35,11 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
$map[$k] = $v;
|
$map[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$map = $map + array('' => 'Any', '-1' => '(no owner)');
|
$map = $map + array('' => 'Any', '-1' => '(no owner)');
|
||||||
|
|
||||||
$params->push(new DropdownField("OwnerID", 'Page owner', $map));
|
$params->push(new DropdownField("OwnerID", 'Page owner', $map));
|
||||||
|
|
||||||
// Restore current subsite
|
// Restore current subsite
|
||||||
Subsite::changeSubsite($existingSubsite);
|
Subsite::changeSubsite($existingSubsite);
|
||||||
} else {
|
} else {
|
||||||
@ -49,17 +49,17 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
$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($startDate = new CalendarDateField('ReviewDateAfter', 'Review date after or on (DD/MM/YYYY)'));
|
||||||
$params->push($endDate = new CalendarDateField('ReviewDateBefore', 'Review date before or on (DD/MM/YYYY)', date('d/m/Y', strtotime('midnight'))));
|
$params->push($endDate = new CalendarDateField('ReviewDateBefore', 'Review date before or on (DD/MM/YYYY)', date('d/m/Y', strtotime('midnight'))));
|
||||||
$endDate->mustBeAfter($startDate->Name());
|
$endDate->mustBeAfter($startDate->Name());
|
||||||
$startDate->mustBeBefore($endDate->Name());
|
$startDate->mustBeBefore($endDate->Name());
|
||||||
|
|
||||||
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
|
$params->push(new CheckboxField('ShowVirtualPages', 'Show Virtual Pages'));
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
function columns() {
|
function columns() {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'Title' => array(
|
'Title' => array(
|
||||||
@ -79,14 +79,14 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
|
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sourceRecords($params, $sort, $limit) {
|
function sourceRecords($params, $sort, $limit) {
|
||||||
$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()->getValue());
|
||||||
@ -100,7 +100,7 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
$reviewDate->add(1, Zend_Date::DAY);
|
$reviewDate->add(1, Zend_Date::DAY);
|
||||||
$wheres[] = sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
$wheres[] = 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']);
|
list($day, $month, $year) = explode('/', $params['ReviewDateAfter']);
|
||||||
@ -108,16 +108,16 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
$wheres[] = sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
$wheres[] = sprintf('"NextReviewDate" >= \'%s\'', $reviewDate->toString('YYYY-MM-dd'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show virtual pages?
|
// Show virtual pages?
|
||||||
if(empty($params['ShowVirtualPages'])) {
|
if(empty($params['ShowVirtualPages'])) {
|
||||||
$wheres[] = '"SiteTree"."ClassName" != \'VirtualPage\' AND "SiteTree"."ClassName" != \'SubsitesVirtualPage\'';
|
$wheres[] = '"SiteTree"."ClassName" != \'VirtualPage\' AND "SiteTree"."ClassName" != \'SubsitesVirtualPage\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use different dropdown depending on the subsite
|
// We use different dropdown depending on the subsite
|
||||||
$ownerIdParam = 'OwnerID';
|
$ownerIdParam = 'OwnerID';
|
||||||
|
|
||||||
|
|
||||||
// Owner dropdown
|
// Owner dropdown
|
||||||
if(!empty($params[$ownerIdParam])) {
|
if(!empty($params[$ownerIdParam])) {
|
||||||
$ownerID = (int)$params[$ownerIdParam];
|
$ownerID = (int)$params[$ownerIdParam];
|
||||||
@ -125,24 +125,26 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
if($ownerID == -1) $ownerID = 0;
|
if($ownerID == -1) $ownerID = 0;
|
||||||
$wheres[] = '"OwnerID" = ' . $ownerID;
|
$wheres[] = '"OwnerID" = ' . $ownerID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = singleton("SiteTree")->extendedSQL(join(' AND ', $wheres));
|
$query = singleton("SiteTree")->extendedSQL(join(' AND ', $wheres));
|
||||||
|
|
||||||
$query->select[] = Member::get_title_sql('Owner').' AS OwnerNames';
|
//$query->select[] = Member::get_title_sql('Owner').' AS OwnerNames';
|
||||||
$query->from[] = 'LEFT JOIN "Member" AS "Owner" ON "SiteTree"."OwnerID" = "Owner"."ID"';
|
//// $query->select[] = '"Owner"."Surname" AS OwnerLastNames';
|
||||||
|
//// $query->select[] = '"Owner"."FirstName" AS OwnerNames';
|
||||||
|
//// $query->from[] = 'LEFT JOIN "Member" AS "Owner" ON "SiteTree"."OwnerID" = "Owner"."ID"';
|
||||||
|
|
||||||
// Turn a query into records
|
// Turn a query into records
|
||||||
if($sort) {
|
if($sort) {
|
||||||
$parts = explode(' ', $sort);
|
$parts = explode(' ', $sort);
|
||||||
$field = $parts[0];
|
$field = $parts[0];
|
||||||
$direction = $parts[1];
|
$direction = $parts[1];
|
||||||
|
|
||||||
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"';
|
$query->from[] = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field != "LastEditedByName") {
|
if($field != "LastEditedByName") {
|
||||||
$query->orderby = $sort;
|
$query->orderby = $sort;
|
||||||
}
|
}
|
||||||
@ -151,12 +153,12 @@ class PagesDueForReviewReport extends SS_Report {
|
|||||||
$records = singleton('SiteTree')->buildDataObjectSet($query->execute(), 'DataObjectSet', $query);
|
$records = singleton('SiteTree')->buildDataObjectSet($query->execute(), 'DataObjectSet', $query);
|
||||||
// var_dump($records);
|
// var_dump($records);
|
||||||
if($records) {
|
if($records) {
|
||||||
foreach($records as $record) {
|
////////foreach($records as $record) {
|
||||||
$record->LastEditedByName = $record->LastEditedBy() ? $record->LastEditedBy()->Title : null;
|
//////// $record->OwnerNames = $record->OwnerNames .' '. $record->OwnerLastNames;
|
||||||
}
|
////////}
|
||||||
|
|
||||||
if($sort && $field != "LastEditedByName") $records->sort($sort);
|
if($sort && $field != "LastEditedByName") $records->sort($sort);
|
||||||
|
|
||||||
// Apply limit after that filtering.
|
// Apply limit after that filtering.
|
||||||
if($limit) return $records->getRange($limit['start'], $limit['limit']);
|
if($limit) return $records->getRange($limit['start'], $limit['limit']);
|
||||||
else return $records;
|
else return $records;
|
||||||
|
@ -6,36 +6,45 @@
|
|||||||
* @package contentreview
|
* @package contentreview
|
||||||
*/
|
*/
|
||||||
class SiteTreeContentReview extends DataObjectDecorator implements PermissionProvider {
|
class SiteTreeContentReview extends DataObjectDecorator implements PermissionProvider {
|
||||||
|
|
||||||
function extraStatics() {
|
function extraStatics() {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
"ReviewPeriodDays" => "Int",
|
"ReviewPeriodDays" => "Int",
|
||||||
"NextReviewDate" => "Date",
|
"NextReviewDate" => "Date",
|
||||||
'ReviewNotes' => 'Text'
|
'ReviewNotes' => 'Text',
|
||||||
|
'LastEditedByName' => 'Varchar(255)',
|
||||||
|
'OwnerNames' => 'Varchar(255)'
|
||||||
),
|
),
|
||||||
'has_one' => array(
|
'has_one' => array(
|
||||||
'Owner' => 'Member'
|
'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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEditorName() {
|
||||||
|
if( $member = Member::currentUser() ) {
|
||||||
|
return $member->FirstName .' '. $member->Surname;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
public function updateCMSFields(&$fields) {
|
public function updateCMSFields(&$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"));
|
||||||
|
|
||||||
$fields->addFieldsToTab("Root.Review", array(
|
$fields->addFieldsToTab("Root.Review", array(
|
||||||
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",
|
new CalendarDateField("NextReviewDate", _t("SiteTreeCMSWorkflow.NEXTREVIEWDATE",
|
||||||
"Next review date (leave blank for no review)")),
|
"Next review date (leave blank for no review)")),
|
||||||
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",
|
||||||
1 => "1 day",
|
1 => "1 day",
|
||||||
@ -52,13 +61,15 @@ class SiteTreeContentReview extends DataObjectDecorator implements PermissionPro
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBeforeWrite() {
|
function onBeforeWrite() {
|
||||||
if($this->owner->ReviewPeriodDays && !$this->owner->NextReviewDate) {
|
if($this->owner->ReviewPeriodDays && !$this->owner->NextReviewDate) {
|
||||||
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
|
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
|
||||||
}
|
}
|
||||||
|
$this->owner->LastEditedByName=$this->owner->getEditorName();
|
||||||
|
$this->owner->OwnerNames = $this->owner->getOwnerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
function providePermissions() {
|
function providePermissions() {
|
||||||
return array(
|
return array(
|
||||||
"EDIT_CONTENT_REVIEW_FIELDS" => array(
|
"EDIT_CONTENT_REVIEW_FIELDS" => array(
|
||||||
|
Loading…
Reference in New Issue
Block a user