2014-02-14 02:49:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CMSPageEditController extension to recieve the additonal action button from
|
|
|
|
* SiteTreeContentReview::updateCMSActions()
|
|
|
|
*
|
|
|
|
*/
|
2014-02-19 02:31:47 +01:00
|
|
|
class ContentReviewCMSExtension extends LeftAndMainExtension {
|
2014-02-14 02:49:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'reviewed',
|
|
|
|
'save_review',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a form with review notes
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
|
|
|
* @return SS_HTTPResponse
|
|
|
|
*/
|
|
|
|
public function reviewed($data, Form $form) {
|
|
|
|
if(!isset($data['ID'])) {
|
|
|
|
throw new SS_HTTPResponse_Exception("No record ID", 404);
|
|
|
|
}
|
2015-10-28 22:32:00 +01:00
|
|
|
$SQL_id = (int) $data['ID'];
|
2014-02-14 02:49:43 +01:00
|
|
|
$record = SiteTree::get()->byID($SQL_id);
|
2014-02-18 21:51:54 +01:00
|
|
|
|
2014-02-14 02:49:43 +01:00
|
|
|
if(!$record || !$record->ID) {
|
|
|
|
throw new SS_HTTPResponse_Exception("Bad record ID #$SQL_id", 404);
|
|
|
|
}
|
2014-02-18 21:51:54 +01:00
|
|
|
|
|
|
|
if(!$record->canEdit()) {
|
|
|
|
return Security::permissionFailure($this->owner);
|
|
|
|
}
|
2014-02-14 02:49:43 +01:00
|
|
|
|
|
|
|
$fields = new FieldList();
|
|
|
|
$fields->push(HiddenField::create('ID', 'ID', $SQL_id));
|
|
|
|
$fields->push(TextareaField::create('ReviewNotes', 'Review notes'));
|
|
|
|
|
|
|
|
$actions = new FieldList(
|
|
|
|
FormAction::create('save_review', 'Save')
|
|
|
|
);
|
|
|
|
|
|
|
|
$form = CMSForm::create($this->owner, "EditForm", $fields, $actions)->setHTMLID('Form_EditForm');
|
|
|
|
$form->setResponseNegotiator($this->owner->getResponseNegotiator());
|
|
|
|
$form->loadDataFrom($record);
|
|
|
|
$form->disableDefaultAction();
|
|
|
|
|
|
|
|
// TODO Can't merge $FormAttributes in template at the moment
|
|
|
|
$form->setTemplate($this->owner->getTemplatesWithSuffix('LeftAndMain_EditForm'));
|
|
|
|
return $form->forTemplate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the review notes and redirect back to the page edit form
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
|
|
|
* @return string - html
|
|
|
|
*/
|
|
|
|
public function save_review($data, Form $form) {
|
|
|
|
if(!isset($data['ID'])) {
|
|
|
|
throw new SS_HTTPResponse_Exception("No record ID", 404);
|
|
|
|
}
|
2015-10-28 22:32:00 +01:00
|
|
|
$SQL_id = (int) $data['ID'];
|
2014-02-18 03:39:13 +01:00
|
|
|
$page = SiteTree::get()->byID($SQL_id);
|
|
|
|
if($page && !$page->canEdit()) {
|
2015-09-23 00:32:23 +02:00
|
|
|
return Security::permissionFailure();
|
2014-02-14 02:49:43 +01:00
|
|
|
}
|
2014-02-18 03:39:13 +01:00
|
|
|
if(!$page || !$page->ID) {
|
2014-02-14 02:49:43 +01:00
|
|
|
throw new SS_HTTPResponse_Exception("Bad record ID #$SQL_id", 404);
|
|
|
|
}
|
|
|
|
|
2014-02-18 03:39:13 +01:00
|
|
|
$page->addReviewNote(Member::currentUser(), $data['ReviewNotes']);
|
|
|
|
$page->advanceReviewDate();
|
|
|
|
|
|
|
|
return $this->owner->redirect($this->owner->Link('show/'.$page->ID));
|
2014-02-14 02:49:43 +01:00
|
|
|
}
|
|
|
|
}
|