opensupports/server/controllers/staff/get.php

77 lines
2.4 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-18 06:39:55 +02:00
/**
* @api {post} /staff/get Get staff
* @apiVersion 4.7.0
2017-04-18 06:39:55 +02:00
*
* @apiName Get staff
2017-04-18 06:39:55 +02:00
*
* @apiGroup Staff
2017-04-18 06:39:55 +02:00
*
* @apiDescription This path retrieves information about a staff member.
2017-04-18 06:39:55 +02:00
*
* @apiPermission staff1
2017-04-18 06:39:55 +02:00
*
* @apiParam {Number} staffId The id of the staff member to be searched.
2018-11-16 00:51:44 +01:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
2017-04-18 06:39:55 +02:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {Object} data Information about a staff member
* @apiSuccess {String} data.name Name of the staff member
* @apiSuccess {String} data.email Elmail of the staff member
* @apiSuccess {String} data.profilePic Profile pic filename of staff member
* @apiSuccess {Number} data.level Level of staff member
* @apiSuccess {Boolean} data.staff Indicates that it is a staff (always true)
2017-04-22 03:33:17 +02:00
* @apiSuccess {[Department](#api-Data_Structures-ObjectDepartment)[]} data.departments Array of departments that has assigned.
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of tickets that has assigned.
* @apiSuccess {Boolean} data.sendEmailOnNewTicket Indicates if this member receives a mail when a ticket is created.
2017-04-18 06:39:55 +02:00
*
*/
class GetStaffController extends Controller {
const PATH = '/get';
const METHOD = 'POST';
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
}
$parsedDepartmentList = [];
$departmentList = $user->sharedDepartmentList;
foreach($departmentList as $department) {
$parsedDepartmentList[] = [
'id' => $department->id,
2018-11-16 00:51:44 +01:00
'name' => $department->name,
'private' => $department->private
];
}
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'profilePic' => $user->profilePic,
'level' => $user->level,
'staff' => true,
'departments' => $parsedDepartmentList,
2019-02-03 20:47:29 +01:00
'tickets' => $user->sharedTicketList->toArray(true),
'sendEmailOnNewTicket' => $user->sendEmailOnNewTicket
]);
}
2018-11-16 00:51:44 +01:00
}