Guillermo - staff/edit[skip ci]
This commit is contained in:
parent
d57baa6cd8
commit
6bad194903
|
@ -9,6 +9,7 @@ require_once 'staff/search-tickets.php';
|
|||
require_once 'staff/add.php';
|
||||
require_once 'staff/get-all.php';
|
||||
require_once 'staff/delete.php';
|
||||
require_once 'staff/edit.php';
|
||||
|
||||
$systemControllerGroup = new ControllerGroup();
|
||||
$systemControllerGroup->setGroupPath('/staff');
|
||||
|
@ -23,5 +24,6 @@ $systemControllerGroup->addController(new SearchTicketStaffController);
|
|||
$systemControllerGroup->addController(new AddStaffController);
|
||||
$systemControllerGroup->addController(new GetAllStaffController);
|
||||
$systemControllerGroup->addController(new DeleteStaffController);
|
||||
$systemControllerGroup->addController(new EditStaffController);
|
||||
|
||||
$systemControllerGroup->finalize();
|
|
@ -9,10 +9,7 @@ class DeleteStaffController extends Controller {
|
|||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => [
|
||||
'staffId' => [
|
||||
'validation' => DataValidator::dataStoreId('staff'),
|
||||
'error' => ERRORS::INVALID_STAFF
|
||||
]
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -23,8 +20,8 @@ class DeleteStaffController extends Controller {
|
|||
|
||||
foreach($staff->sharedTicketList as $ticket) {
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = true;
|
||||
$ticket->store();
|
||||
$ticket->true = true;
|
||||
$ticket->store()
|
||||
}
|
||||
|
||||
$staff->delete();
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class EditStaffController extends Controller {
|
||||
const PATH = '/edit';
|
||||
|
||||
private $staffRow;
|
||||
private $staffId;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_3',
|
||||
'requestData' => [
|
||||
'staffId' =>[
|
||||
'validation' => DataValidator::dataStoreId('staff'),
|
||||
'error' => ERRORS::INVALID_STAFF
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$this->staffId = Controller::request('staffId');
|
||||
|
||||
if(!$this->staffId) {
|
||||
$this->staffRow = Controller::getLoggedUser();
|
||||
} else {
|
||||
$this->staffRow = Staff::getDataStore($this->staffId,'id');
|
||||
}
|
||||
|
||||
$this->editInformation();
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
||||
public function editInformation() {
|
||||
|
||||
if(Controller::request('email')) {
|
||||
$this->staffRow->email = Controller::request('email');
|
||||
}
|
||||
|
||||
if(Controller::request('password')) {
|
||||
$this->staffRow->password = Controller::request('password');
|
||||
}
|
||||
if(Controller::request('level')) {
|
||||
$this->staffRow->level = Controller::request('level');
|
||||
}
|
||||
if(Controller::request('departments')) {
|
||||
$this->staffRow->sharedDepartmentList = $this->getDepartmentList();
|
||||
}
|
||||
|
||||
$this->staffRow->store();
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentList() {
|
||||
$listDepartments = new DataStoreList();
|
||||
$departmentIds = json_decode(Controller::request('departments'));
|
||||
|
||||
foreach($departmentIds as $id) {
|
||||
$department = Department::getDataStore($id);
|
||||
$listDepartments->add($department);
|
||||
}
|
||||
|
||||
return $listDepartments;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue