2018-11-14 16:28:01 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @api {post} /system/get-mail-template Get mail template
|
2021-10-19 03:06:20 +02:00
|
|
|
* @apiVersion 4.10.0
|
2018-11-14 16:28:01 +01:00
|
|
|
*
|
|
|
|
* @apiName Get mail template
|
|
|
|
*
|
|
|
|
* @apiGroup System
|
|
|
|
*
|
|
|
|
* @apiDescription This path retrieves the data of one of the mail templates.
|
|
|
|
*
|
|
|
|
* @apiPermission staff3
|
|
|
|
*
|
|
|
|
* @apiParam {String} template The type of template to retrieve.
|
|
|
|
* @apiParam {String} language The language of the template to retrieve.
|
|
|
|
*
|
|
|
|
* @apiUse NO_PERMISSION
|
|
|
|
*
|
2018-11-14 23:58:32 +01:00
|
|
|
* @apiSuccess {[MailTemplate](#api-Data_Structures-ObjectMailtemplate)} data Data of the mail template
|
2018-11-14 16:28:01 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class GetMailTemplateController extends Controller {
|
|
|
|
const PATH = '/get-mail-template';
|
|
|
|
const METHOD = 'POST';
|
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_3',
|
|
|
|
'requestData' => [
|
|
|
|
'template' => [
|
2021-11-11 21:17:39 +01:00
|
|
|
'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE),
|
2018-11-14 16:28:01 +01:00
|
|
|
'error' => ERRORS::INVALID_TEMPLATE
|
|
|
|
],
|
|
|
|
'language' => [
|
2021-11-11 21:17:39 +01:00
|
|
|
'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()),
|
2018-11-14 16:28:01 +01:00
|
|
|
'error' => ERRORS::INVALID_LANGUAGE
|
|
|
|
],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$type = Controller::request('template');
|
|
|
|
$language = Controller::request('language');
|
|
|
|
|
|
|
|
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $type]);
|
|
|
|
|
|
|
|
if($mailTemplate->isNull()) {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::INVALID_TEMPLATE);
|
2018-11-14 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Response::respondSuccess($mailTemplate->toArray());
|
|
|
|
}
|
|
|
|
}
|