opensupports/server/controllers/system/edit-mail-template.php

79 lines
2.4 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
2017-04-18 02:09:16 +02:00
/**
* @api {post} /system/edit-mail-template Edit mail template
2018-09-20 22:19:47 +02:00
* @apiVersion 4.3.0
2017-04-18 02:09:16 +02:00
*
* @apiName Edit mail template
*
* @apiGroup System
2017-04-18 02:09:16 +02:00
*
* @apiDescription This path edits a mail template.
2017-04-18 02:09:16 +02:00
*
* @apiPermission staff3
2017-04-18 02:09:16 +02:00
*
* @apiParam {String} template The template to edit.
* @apiParam {String} language The language of the template to edit.
2017-04-21 08:09:24 +02:00
* @apiParam {String} subject The new subject of the template.
* @apiParam {String} text1 The first paragraph template.
* @apiParam {String} text2 The second paragraph template.
* @apiParam {String} text3 The third paragraph template.
2017-04-21 08:09:24 +02:00
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TEMPLATE
* @apiUse INVALID_LANGUAGE
* @apiUse INVALID_SUBJECT
*
2018-10-26 17:02:07 +02:00
* @apiSuccess {Object} data Empty object
2017-04-18 02:09:16 +02:00
*
*/
class EditMailTemplateController extends Controller {
const PATH = '/edit-mail-template';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_3',
'requestData' => [
'template' => [
'validation' => DataValidator::length(4),
'error' => ERRORS::INVALID_TEMPLATE
],
'language' => [
'validation' => DataValidator::length(2, 2),
'error' => ERRORS::INVALID_LANGUAGE
],
'subject' => [
'validation' => DataValidator::length(4),
'error' => ERRORS::INVALID_SUBJECT
],
]
];
}
public function handler() {
$language = Controller::request('language');
$templateType = Controller::request('template');
$subject = Controller::request('subject', true);
$texts = [
Controller::request('text1'),
Controller::request('text2'),
Controller::request('text3'),
];
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $templateType]);
if($mailTemplate->isNull()) {
2018-10-26 17:02:07 +02:00
throw new Exception(ERRORS::INVALID_TEMPLATE);
}
$mailTemplate->subject = $subject;
$mailTemplate->text1 = $texts[0];
$mailTemplate->text2 = $texts[1];
$mailTemplate->text3 = $texts[2];
$mailTemplate->store();
Response::respondSuccess();
}
2018-10-26 17:02:07 +02:00
}