Ivan - Add CustomResponse model and paths [skip ci]
This commit is contained in:
parent
8747326fca
commit
84b33ea871
|
@ -89,8 +89,8 @@ class InitSettingsController extends Controller {
|
|||
'email' => 'staff@opensupports.com',
|
||||
'password' => Hashing::hashPassword('staff'),
|
||||
'profilePic' => 'http://i65.tinypic.com/9bep95.jpg',
|
||||
'level' => 1,
|
||||
'sharedDepartmentList' => Department::getAllDepartments(),
|
||||
'level' => 3,
|
||||
'sharedDepartmentList' => Department::getAll(),
|
||||
'sharedTicketList' => []
|
||||
]);
|
||||
$staff->store();
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
include 'ticket/create.php';
|
||||
include 'ticket/comment.php';
|
||||
include 'ticket/get.php';
|
||||
include 'ticket/add-custom-response.php';
|
||||
include 'ticket/edit-custom-response.php';
|
||||
include 'ticket/get-custom-responses.php';
|
||||
|
||||
$ticketControllers = new ControllerGroup();
|
||||
$ticketControllers->setGroupPath('/ticket');
|
||||
|
@ -9,5 +12,8 @@ $ticketControllers->setGroupPath('/ticket');
|
|||
$ticketControllers->addController(new CreateController);
|
||||
$ticketControllers->addController(new CommentController);
|
||||
$ticketControllers->addController(new TicketGetController);
|
||||
$ticketControllers->addController(new AddCustomResponseController);
|
||||
$ticketControllers->addController(new EditCustomResponseController);
|
||||
$ticketControllers->addController(new GetCustomResponsesController);
|
||||
|
||||
$ticketControllers->finalize();
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class AddCustomResponseController extends Controller {
|
||||
const PATH = '/add-custom-response';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_2',
|
||||
'requestData' => [
|
||||
'name' => [
|
||||
'validation' => DataValidator::length(5, 100),
|
||||
'error' => ERRORS::INVALID_NAME
|
||||
],
|
||||
'content' => [
|
||||
'validation' => DataValidator::length(20, 500),
|
||||
'error' => ERRORS::INVALID_CONTENT
|
||||
],
|
||||
'language' => [
|
||||
'validation' => DataValidator::validLanguage(),
|
||||
'error' => ERRORS::INVALID_LANGUAGE
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$customResponse = new CustomResponse();
|
||||
$customResponse->setProperties([
|
||||
'name' => Controller::request('name'),
|
||||
'content' => Controller::request('content'),
|
||||
'language' => Controller::request('language')
|
||||
]);
|
||||
$customResponse->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class EditCustomResponseController extends Controller {
|
||||
const PATH = '/edit-custom-response';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_2',
|
||||
'requestData' => [
|
||||
'id' => [
|
||||
'validation' => DataValidator::dataStoreId('customresponse'),
|
||||
'error' => ERRORS::INVALID_NAME
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$customResponse = CustomResponse::getDataStore(Controller::request('id'));
|
||||
|
||||
if (Controller::request('content')) {
|
||||
$customResponse->content = Controller::request('content');
|
||||
}
|
||||
|
||||
if (Controller::request('language')) {
|
||||
$customResponse->language = Controller::request('language');
|
||||
}
|
||||
|
||||
if (Controller::request('name')) {
|
||||
$customResponse->name = Controller::request('name');
|
||||
}
|
||||
|
||||
$customResponse->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class GetCustomResponsesController extends Controller {
|
||||
const PATH = '/get-custom-responses';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_1',
|
||||
'requestData' => []
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$customResponsesList = CustomResponse::getAll();
|
||||
|
||||
Response::respondSuccess($customResponsesList->toArray());
|
||||
}
|
||||
}
|
|
@ -16,4 +16,5 @@ class ERRORS {
|
|||
const INVALID_OLD_PASSWORD = 'Invalid old password';
|
||||
const INVALID_CAPTCHA = 'Invalid captcha';
|
||||
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
|
||||
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ spl_autoload_register(function ($class) {
|
|||
include_once 'libs/validations/dataStoreId.php';
|
||||
include_once 'libs/validations/userEmail.php';
|
||||
include_once 'libs/validations/captcha.php';
|
||||
include_once 'libs/validations/validLanguage.php';
|
||||
include_once 'libs/validations/validTicketNumber.php';
|
||||
|
||||
// LOAD CONTROLLERS
|
||||
|
|
|
@ -39,6 +39,17 @@ class DataStoreList implements IteratorAggregate {
|
|||
return $beanList;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [];
|
||||
|
||||
foreach($this->list as $item) {
|
||||
$item->updateBeanProperties();
|
||||
$array[] = $item->toArray();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function getIndexInListOf($dataStore) {
|
||||
foreach ($this->list as $itemIdInList => $item) {
|
||||
if ($item->id === $dataStore->id) {
|
||||
|
|
|
@ -28,6 +28,9 @@ class DataStoreId extends AbstractRule {
|
|||
case 'department':
|
||||
$dataStore = \Department::getDataStore($dataStoreId);
|
||||
break;
|
||||
case 'customresponse':
|
||||
$dataStore = \CustomResponse::getDataStore($dataStoreId);
|
||||
break;
|
||||
}
|
||||
|
||||
return !$dataStore->isNull();
|
||||
|
@ -37,7 +40,8 @@ class DataStoreId extends AbstractRule {
|
|||
return in_array($dataStoreName, [
|
||||
'user',
|
||||
'ticket',
|
||||
'department'
|
||||
'department',
|
||||
'customresponse'
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace CustomValidations;
|
||||
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
|
||||
class ValidLanguage extends AbstractRule {
|
||||
|
||||
private $languages = [
|
||||
'en',
|
||||
'es',
|
||||
'de',
|
||||
'cn',
|
||||
];
|
||||
|
||||
public function validate($ticketNumber) {
|
||||
return in_array($ticketNumber, $this->languages);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class CustomResponse extends DataStore {
|
||||
const TABLE = 'customresponse';
|
||||
|
||||
public static function getProps() {
|
||||
return [
|
||||
'name',
|
||||
'language',
|
||||
'content'
|
||||
];
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'language' => $this->language,
|
||||
'content' => $this->content,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -20,6 +20,17 @@ abstract class DataStore {
|
|||
return RedBean::count(static::TABLE);
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$beanList = RedBean::findAll(static::TABLE);
|
||||
$dataStoreList = new DataStoreList();
|
||||
|
||||
foreach($beanList as $bean) {
|
||||
$dataStoreList->add(new static($bean));
|
||||
}
|
||||
|
||||
return $dataStoreList;
|
||||
}
|
||||
|
||||
private static function validateProp($propToValidate) {
|
||||
$validProp = false;
|
||||
|
||||
|
|
|
@ -12,24 +12,13 @@ class Department extends DataStore {
|
|||
}
|
||||
|
||||
public static function getDepartmentNames() {
|
||||
$departmentsQuantity = RedBean::count(Department::TABLE);
|
||||
$departmentsList = RedBean::findAll(Department::TABLE);
|
||||
$departmentsNameList = [];
|
||||
|
||||
for ($departmentIndex = 1; $departmentIndex <= $departmentsQuantity; ++$departmentIndex) {
|
||||
$departmentsNameList[] = Department::getDataStore($departmentIndex)->name;
|
||||
foreach($departmentsList as $department) {
|
||||
$departmentsNameList[] = $department->name;
|
||||
}
|
||||
|
||||
return $departmentsNameList;
|
||||
}
|
||||
|
||||
public static function getAllDepartments() {
|
||||
$departmentsQuantity = RedBean::count(Department::TABLE);
|
||||
$departmentList = new DataStoreList();
|
||||
|
||||
for ($departmentIndex = 1; $departmentIndex <= $departmentsQuantity; ++$departmentIndex) {
|
||||
$departmentList->add(Department::getDataStore($departmentIndex));
|
||||
}
|
||||
|
||||
return $departmentList;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue