opensupports/server/controllers/user/get-user.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2016-11-30 18:13:57 +01:00
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2016-11-30 21:30:00 +01:00
class GetUserByIdController extends Controller {
2016-11-30 18:13:57 +01:00
const PATH = '/get-user';
const METHOD = 'POST';
2016-11-30 18:13:57 +01:00
public function validations() {
return [
'permission' => 'staff_1',
2016-11-30 18:13:57 +01:00
'requestData' => [
'userId' => [
'validation' => DataValidator::dataStoreId('user'),
'error' => ERRORS::INVALID_USER
]
]
];
}
public function handler() {
if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
}
2016-11-30 18:13:57 +01:00
$userId = Controller::request('userId');
$user = User::getDataStore($userId);
$staff = Controller::getLoggedUser();
$tickets = new DataStoreList();
foreach($user->sharedTicketList as $ticket) {
if($staff->sharedDepartmentList->includesId($ticket->department->id)) {
$tickets->add($ticket);
}
}
2016-11-30 18:13:57 +01:00
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'signupDate' => $user->signupDate,
'tickets' => $tickets->toArray(),
'verified' => !$user->verificationToken
2016-11-30 18:13:57 +01:00
]);
}
}