2014-02-14 02:49:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-11-02 00:27:42 +01:00
|
|
|
* CMSPageEditController extension to receive the additional action button from
|
2014-02-14 02:49:43 +01:00
|
|
|
* SiteTreeContentReview::updateCMSActions()
|
|
|
|
*/
|
2015-11-02 00:27:42 +01:00
|
|
|
class ContentReviewCMSExtension extends LeftAndMainExtension
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* @throws SS_HTTPResponse_Exception
|
|
|
|
*/
|
|
|
|
public function reviewed($data, Form $form)
|
|
|
|
{
|
|
|
|
if (!isset($data["ID"])) {
|
2015-10-30 05:30:18 +01:00
|
|
|
throw new SS_HTTPResponse_Exception("No record ID", 404);
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$id = (int) $data["ID"];
|
|
|
|
$record = SiteTree::get()->byID($id);
|
|
|
|
|
|
|
|
if (!$record || !$record->ID) {
|
|
|
|
throw new SS_HTTPResponse_Exception("Bad record ID #{$id}", 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$record->canEdit()) {
|
|
|
|
return Security::permissionFailure($this->owner);
|
|
|
|
}
|
|
|
|
|
2015-10-30 05:30:18 +01:00
|
|
|
$reviewNotes = TextareaField::create("ReviewNotes", _t("ContentReview.REVIEWNOTES", "Review notes"));
|
|
|
|
$reviewNotes->setDescription(_t("ContentReview.REVIEWNOTESDESCRIPTION ", "Add comments for the content of this page."));
|
|
|
|
$fields = new FieldList();
|
2015-11-02 00:27:42 +01:00
|
|
|
$fields->push(HiddenField::create("ID", "ID", $id));
|
2015-10-30 05:30:18 +01:00
|
|
|
$fields->push($reviewNotes);
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$actions = new FieldList(
|
2015-10-30 05:30:18 +01:00
|
|
|
FormAction::create("save_review", _t("ContentReview.SAVE", "Save"))
|
2015-11-02 00:27:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @throws SS_HTTPResponse_Exception
|
|
|
|
*/
|
|
|
|
public function save_review($data, Form $form)
|
|
|
|
{
|
|
|
|
if (!isset($data["ID"])) {
|
|
|
|
throw new SS_HTTPResponse_Exception("No record ID", 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = (int) $data["ID"];
|
|
|
|
$page = SiteTree::get()->byID($id);
|
|
|
|
|
|
|
|
if ($page && !$page->canEdit()) {
|
|
|
|
return Security::permissionFailure();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$page || !$page->ID) {
|
|
|
|
throw new SS_HTTPResponse_Exception("Bad record ID #{$id}", 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
}
|