opensupports/server/controllers/staff/get-all.php

64 lines
1.6 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
2017-04-18 06:39:55 +02:00
/**
* @api {post} /staff/get-all Get all staffs
* @apiVersion 4.10.0
2017-04-18 06:39:55 +02:00
*
* @apiName Get all staffs
2017-04-18 06:39:55 +02:00
*
* @apiGroup Staff
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiDescription This path retrieves information about all the staff member.
2017-04-18 06:39:55 +02:00
*
* @apiPermission staff1
2018-07-28 01:36:35 +02: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 {[Staff](#api-Data_Structures-ObjectStaff)[]} data Array of staff members.
2017-04-18 06:39:55 +02:00
*
*/
class GetAllStaffController extends Controller {
const PATH ='/get-all';
const METHOD = 'POST';
public function validations() {
return [
2018-07-28 01:36:35 +02:00
'permission' => 'staff_1',
'requestData' => []
];
}
public function handler() {
$staffs = Staff::getAll();
$staffArray = [];
foreach($staffs as $staff) {
2016-12-08 07:21:37 +01:00
$assignedTickets = 0;
$closedTickets = 0;
foreach ($staff->sharedTicketList as $ticket) {
if(($ticket->closed) && ($ticket->owner_id == $staff->id)) $closedTickets++;
if($ticket->owner_id == $staff->id) $assignedTickets++;
2016-12-08 07:21:37 +01:00
}
$staffArray[] = [
2016-12-08 18:30:19 +01:00
'id' => $staff->id,
2016-12-08 07:21:37 +01:00
'name' => $staff->name,
'email' => $staff->email,
'profilePic' => $staff->profilePic,
'level' => $staff->level,
'departments' => $staff->sharedDepartmentList->toArray(),
'assignedTickets' => $assignedTickets,
'closedTickets' => $closedTickets,
'lastLogin' => $staff->lastLogin
2016-12-08 07:21:37 +01:00
];
}
Response::respondSuccess($staffArray);
2018-07-28 01:36:35 +02:00
}
2018-07-28 01:36:35 +02:00
}