From 6bad1949034f8e68126f1ccd1b7f791720b78ef8 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Wed, 7 Dec 2016 19:30:31 -0300 Subject: [PATCH] Guillermo - staff/edit[skip ci] --- server/controllers/staff.php | 2 + server/controllers/staff/delete.php | 9 ++-- server/controllers/staff/edit.php | 66 +++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 server/controllers/staff/edit.php diff --git a/server/controllers/staff.php b/server/controllers/staff.php index f1cfb954..fff73e65 100644 --- a/server/controllers/staff.php +++ b/server/controllers/staff.php @@ -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(); \ No newline at end of file diff --git a/server/controllers/staff/delete.php b/server/controllers/staff/delete.php index 17fb8042..1b315abe 100644 --- a/server/controllers/staff/delete.php +++ b/server/controllers/staff/delete.php @@ -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(); diff --git a/server/controllers/staff/edit.php b/server/controllers/staff/edit.php new file mode 100644 index 00000000..4d675b99 --- /dev/null +++ b/server/controllers/staff/edit.php @@ -0,0 +1,66 @@ + '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; + } +} \ No newline at end of file