Guillermo - path edit/recover-mail-templates [skip ci]
This commit is contained in:
parent
1a600f4c61
commit
51357c2cd8
|
@ -7,6 +7,8 @@ require_once 'system/edit-department.php';
|
|||
require_once 'system/delete-department.php';
|
||||
require_once 'system/get-logs.php';
|
||||
require_once 'system/get-mail-templates.php';
|
||||
require_once 'system/edit-mail-template.php';
|
||||
require_once 'system/recover-mail-template.php';
|
||||
|
||||
$systemControllerGroup = new ControllerGroup();
|
||||
$systemControllerGroup->setGroupPath('/system');
|
||||
|
@ -19,5 +21,7 @@ $systemControllerGroup->addController(new EditDepartmentController);
|
|||
$systemControllerGroup->addController(new DeleteDepartmentController);
|
||||
$systemControllerGroup->addController(new GetLogsController);
|
||||
$systemControllerGroup->addController(new GetMailTemplatesController);
|
||||
$systemControllerGroup->addController(new EditMailTemplateController);
|
||||
$systemControllerGroup->addController(new RecoverMailTemplateController);
|
||||
|
||||
$systemControllerGroup->finalize();
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class EditMailTemplateController extends Controller {
|
||||
const PATH = '/edit-mail-template';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => [
|
||||
'templateType' => [
|
||||
'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
|
||||
],
|
||||
'body' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_BODY
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$language = Controller::request('language');
|
||||
$templateType = Controller::request('templateType');
|
||||
$subject = Controller::request('subject');
|
||||
$body = Controller::request('body');
|
||||
|
||||
$mailTemplate = MailTemplate::findOne(' language = ? AND type = ?', [$language, $templateType]);
|
||||
if($mailTemplate->isNull()) {
|
||||
Response::respondError(ERRORS::INVALID_TEMPLATE);
|
||||
return;
|
||||
}
|
||||
$mailTemplate->subject = $subject;
|
||||
$mailTemplate->body = $body;
|
||||
$mailTemplate->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class EditMailController extends Controller {
|
||||
const PATH = '/edit-mail';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => []
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
Response::respondSuccess();
|
||||
|
||||
}
|
||||
}
|
|
@ -7,11 +7,36 @@ class RecoverMailTemplateController extends Controller {
|
|||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => []
|
||||
'requestData' => [
|
||||
'templateType' => [
|
||||
'validation' => DataValidator::length(4),
|
||||
'error' => ERRORS::INVALID_TEMPLATE
|
||||
],
|
||||
'language' => [
|
||||
'validation' => DataValidator::length(2, 2),
|
||||
'error' => ERRORS::INVALID_LANGUAGE
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$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();
|
||||
|
||||
Response::respondSuccess();
|
||||
|
||||
}
|
||||
|
|
|
@ -32,4 +32,7 @@ class ERRORS {
|
|||
const SAME_DEPARTMENT = 'SAME_DEPARTMENT';
|
||||
const INVALID_TOKEN = 'INVALID_TOKEN';
|
||||
const UNVERIFIED_USER = 'UNVERIFIED_USER';
|
||||
const INVALID_TEMPLATE = 'INVALID_TEMPLATE';
|
||||
const INVALID_SUBJECT = 'INVALID_SUBJECT';
|
||||
const INVALID_BODY = 'INVALID_BODY';
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ abstract class DataStore {
|
|||
|
||||
return DataStoreList::getList(ucfirst(static::TABLE), $beanList);
|
||||
}
|
||||
|
||||
public static function findOne($query = '', $matches = []) {
|
||||
$bean = RedBean::findOne(static::TABLE, $query, $matches);
|
||||
|
||||
return ($bean) ? new static($bean) : new NullDataStore();
|
||||
}
|
||||
|
||||
private static function validateProp($propToValidate) {
|
||||
$validProp = false;
|
||||
|
|
Loading…
Reference in New Issue