2016-09-25 06:16:10 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
|
|
|
|
class GetStaffController extends Controller {
|
|
|
|
const PATH = '/get';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-09-25 06:16:10 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_1',
|
|
|
|
'requestData' => []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$user = Controller::getLoggedUser();
|
2016-12-06 05:32:00 +01:00
|
|
|
|
2016-12-08 07:21:37 +01:00
|
|
|
$userId = Controller::request('staffId');
|
|
|
|
$userRow = Staff::getDataStore($userId);
|
2016-12-06 05:32:00 +01:00
|
|
|
|
|
|
|
if($user->level == 3 && !$userRow->isNull()) {
|
2016-12-08 07:21:37 +01:00
|
|
|
$user = $userRow;
|
2016-12-06 05:32:00 +01:00
|
|
|
}
|
|
|
|
|
2016-09-25 06:16:10 +02:00
|
|
|
$parsedDepartmentList = [];
|
|
|
|
$departmentList = $user->sharedDepartmentList;
|
|
|
|
|
|
|
|
foreach($departmentList as $department) {
|
|
|
|
$parsedDepartmentList[] = [
|
|
|
|
'id' => $department->id,
|
|
|
|
'name' => $department->name
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
Response::respondSuccess([
|
|
|
|
'name' => $user->name,
|
|
|
|
'email' => $user->email,
|
|
|
|
'profilePic' => $user->profilePic,
|
|
|
|
'level' => $user->level,
|
|
|
|
'staff' => true,
|
2016-12-12 05:46:50 +01:00
|
|
|
'departments' => $parsedDepartmentList,
|
|
|
|
'tickets' => $user->sharedTicketList->toArray()
|
2016-09-25 06:16:10 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|