2017-01-03 23:36:26 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
|
|
|
class RecoverMailTemplateController extends Controller {
|
|
|
|
const PATH = '/recover-mail-template';
|
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_3',
|
2017-01-04 00:35:46 +01:00
|
|
|
'requestData' => [
|
|
|
|
'templateType' => [
|
|
|
|
'validation' => DataValidator::length(4),
|
|
|
|
'error' => ERRORS::INVALID_TEMPLATE
|
|
|
|
],
|
|
|
|
'language' => [
|
|
|
|
'validation' => DataValidator::length(2, 2),
|
|
|
|
'error' => ERRORS::INVALID_LANGUAGE
|
|
|
|
],
|
|
|
|
]
|
2017-01-03 23:36:26 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
2017-01-04 00:35:46 +01:00
|
|
|
$type = Controller::request('templateType');
|
|
|
|
$language = Controller::request('language');
|
|
|
|
|
|
|
|
$mailTemplate = MailTemplate::findOne(' language = ? AND type = ?', [$language, $type]);
|
|
|
|
|
|
|
|
if($mailTemplate->isNull()) {
|
|
|
|
Response::respondError(ERRORS::INVALID_TEMPLATE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$defaultTemplates = InitialMails::retrieve();
|
|
|
|
|
|
|
|
$mailTemplate->body = $defaultTemplates[$type][$language]['body'] ;
|
|
|
|
$mailTemplate->subject = $defaultTemplates[$type][$language]['subject'] ;
|
|
|
|
|
|
|
|
$mailTemplate->store();
|
|
|
|
|
2017-01-03 23:36:26 +01:00
|
|
|
Response::respondSuccess();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|