2017-01-04 00:35:46 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
2017-04-18 02:09:16 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +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
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiGroup System
|
2017-04-18 02:09:16 +02:00
|
|
|
*
|
2018-11-14 16:28:01 +01:00
|
|
|
* @apiDescription This path edits a mail template.
|
2017-04-18 02:09:16 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission staff3
|
2017-04-18 02:09:16 +02:00
|
|
|
*
|
2018-11-14 16:28:01 +01: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.
|
2018-11-14 16:28:01 +01:00
|
|
|
* @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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-01-04 00:35:46 +01:00
|
|
|
class EditMailTemplateController extends Controller {
|
|
|
|
const PATH = '/edit-mail-template';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2017-01-04 00:35:46 +01:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_3',
|
|
|
|
'requestData' => [
|
2018-11-14 16:28:01 +01:00
|
|
|
'template' => [
|
2017-01-04 00:35:46 +01:00
|
|
|
'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');
|
2018-11-14 16:28:01 +01:00
|
|
|
$templateType = Controller::request('template');
|
2017-03-02 06:56:42 +01:00
|
|
|
$subject = Controller::request('subject', true);
|
2018-11-14 16:28:01 +01:00
|
|
|
$texts = [
|
|
|
|
Controller::request('text1'),
|
|
|
|
Controller::request('text2'),
|
|
|
|
Controller::request('text3'),
|
|
|
|
];
|
2017-01-04 00:35:46 +01:00
|
|
|
|
2018-11-14 16:28:01 +01:00
|
|
|
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $templateType]);
|
2017-01-04 00:35:46 +01:00
|
|
|
if($mailTemplate->isNull()) {
|
2018-10-26 17:02:07 +02:00
|
|
|
throw new Exception(ERRORS::INVALID_TEMPLATE);
|
2017-01-04 00:35:46 +01:00
|
|
|
}
|
|
|
|
$mailTemplate->subject = $subject;
|
2018-11-14 16:28:01 +01:00
|
|
|
$mailTemplate->text1 = $texts[0];
|
|
|
|
$mailTemplate->text2 = $texts[1];
|
|
|
|
$mailTemplate->text3 = $texts[2];
|
2017-01-04 00:35:46 +01:00
|
|
|
$mailTemplate->store();
|
|
|
|
|
|
|
|
Response::respondSuccess();
|
|
|
|
}
|
2018-10-26 17:02:07 +02:00
|
|
|
}
|