silverstripe-contentreview/code/extensions/ContentReviewCMSExtension.php

67 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
2015-11-02 00:27:42 +01:00
* CMSPageEditController extension to receive the additional action button from
* SiteTreeContentReview::updateCMSActions()
*/
2015-11-02 00:27:42 +01:00
class ContentReviewCMSExtension extends LeftAndMainExtension
{
/**
* @var array
*/
private static $allowed_actions = array(
2015-11-12 03:56:19 +01:00
"savereview"
2015-11-02 00:27:42 +01:00
);
/**
* Save the review notes and redirect back to the page edit form.
*
* @param array $data
* @param Form $form
*
* @return string
*
* @throws SS_HTTPResponse_Exception
*/
2015-11-12 03:56:19 +01:00
public function savereview($data, Form $form)
2015-11-02 00:27:42 +01:00
{
2015-11-03 04:57:07 +01:00
$page = $this->findRecord($data);
if (!$page->canEdit()) {
return Security::permissionFailure($this->owner);
2015-11-02 00:27:42 +01:00
}
2015-11-12 03:56:19 +01:00
$notes = (!empty($data["ReviewNotes"]) ? $data["ReviewNotes"] : _t("ContentReview.NOCOMMENTS", "(no comments)"));
$page->addReviewNote(Member::currentUser(), $notes);
2015-11-03 04:57:07 +01:00
$page->advanceReviewDate();
2015-11-12 03:56:19 +01:00
$this->owner->getResponse()->addHeader("X-Status", _t("ContentReview.REVIEWSUCCESSFUL", "Content reviewed successfully"));
return $this->owner->redirectBack();
2015-11-03 04:57:07 +01:00
}
2015-11-12 03:56:19 +01:00
2015-11-03 04:57:07 +01:00
/**
* Find the page this form is updating
*
* @param array $data Form data
* @return SiteTree Record
* @throws SS_HTTPResponse_Exception
*/
protected function findRecord($data)
{
if (empty($data["ID"])) {
throw new SS_HTTPResponse_Exception("No record ID", 404);
}
2015-11-02 00:27:42 +01:00
2015-11-03 04:57:07 +01:00
$page = null;
$id = $data["ID"];
if (is_numeric($id)) {
$page = SiteTree::get()->byID($id);
2015-11-02 00:27:42 +01:00
}
if (!$page || !$page->ID) {
throw new SS_HTTPResponse_Exception("Bad record ID #{$id}", 404);
}
2015-11-03 04:57:07 +01:00
return $page;
2015-11-02 00:27:42 +01:00
}
}