2016-10-15 10:03:56 +02:00
|
|
|
<?php
|
2017-03-04 06:57:51 +01:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
2016-10-15 10:03:56 +02:00
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
2017-04-18 06:39:55 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /staff/get-new-tickets Get new tickets
|
2020-06-17 02:26:04 +02:00
|
|
|
* @apiVersion 4.7.0
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
* @apiName Get new tickets
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiGroup Staff
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiDescription This path retrieves the new tickets of the departments the staff has assigned.
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission staff1
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
2018-11-16 00:33:08 +01:00
|
|
|
* @apiParam {Number} page The page number.
|
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiUse NO_PERMISSION
|
2018-11-16 00:33:08 +01:00
|
|
|
* @apiUse INVALID_PAGE
|
2018-07-18 04:18:51 +02:00
|
|
|
*
|
2018-11-16 00:33:08 +01:00
|
|
|
* @apiSuccess {Object} data Information about a tickets and quantity of pages.
|
|
|
|
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of new tickets of the current page.
|
|
|
|
* @apiSuccess {Number} data.page Number of current page.
|
|
|
|
* @apiSuccess {Number} data.pages Quantity of pages.
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-18 04:19:04 +02:00
|
|
|
class GetNewTicketsStaffController extends Controller {
|
2016-10-15 10:03:56 +02:00
|
|
|
const PATH = '/get-new-tickets';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-10-15 10:03:56 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return[
|
|
|
|
'permission' => 'staff_1',
|
2018-11-16 00:33:08 +01:00
|
|
|
'requestData' => [
|
|
|
|
'page' => [
|
|
|
|
'validation' => DataValidator::numeric(),
|
|
|
|
'error' => ERRORS::INVALID_PAGE
|
|
|
|
]
|
|
|
|
]
|
2016-10-15 10:03:56 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
public function handler() {
|
2018-11-29 04:31:00 +01:00
|
|
|
$page = Controller::request('page');
|
2019-07-26 12:49:43 +02:00
|
|
|
$departmentId = Controller::request('departmentId');
|
2018-11-29 04:31:00 +01:00
|
|
|
|
2017-03-29 23:46:26 +02:00
|
|
|
if (Ticket::isTableEmpty()) {
|
2018-11-29 04:31:00 +01:00
|
|
|
Response::respondSuccess([
|
|
|
|
'tickets' => [],
|
|
|
|
'page' => $page,
|
|
|
|
'pages' => 0
|
|
|
|
]);
|
2017-03-29 23:46:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-18 04:19:04 +02:00
|
|
|
$user = Controller::getLoggedUser();
|
2018-11-16 00:33:08 +01:00
|
|
|
|
2016-10-18 04:19:04 +02:00
|
|
|
$query = ' (';
|
|
|
|
foreach ($user->sharedDepartmentList as $department) {
|
|
|
|
$query .= 'department_id=' . $department->id . ' OR ';
|
|
|
|
}
|
2018-07-18 04:18:51 +02:00
|
|
|
|
2017-03-04 06:57:51 +01:00
|
|
|
$ownerExists = RedBean::exec('SHOW COLUMNS FROM ticket LIKE \'owner_id\'');
|
|
|
|
|
|
|
|
if($ownerExists != 0) {
|
2018-11-16 00:33:08 +01:00
|
|
|
$query .= 'FALSE) AND closed = 0 AND owner_id IS NULL';
|
2017-03-04 06:57:51 +01:00
|
|
|
} else {
|
2018-11-16 00:33:08 +01:00
|
|
|
$query .= 'FALSE) AND closed = 0';
|
2017-03-04 06:57:51 +01:00
|
|
|
}
|
|
|
|
|
2019-07-26 12:49:43 +02:00
|
|
|
if($departmentId) {
|
|
|
|
$query .= ' AND department_id=' . $departmentId;
|
|
|
|
}
|
|
|
|
|
2018-11-16 00:33:08 +01:00
|
|
|
$countTotal = Ticket::count($query);
|
|
|
|
|
|
|
|
$query .= ' ORDER BY unread_staff DESC';
|
|
|
|
$query .= ' LIMIT 10 OFFSET ' . ($page-1)*10;
|
|
|
|
|
2016-10-18 04:19:04 +02:00
|
|
|
$ticketList = Ticket::find($query);
|
2017-03-04 06:57:51 +01:00
|
|
|
|
2018-11-16 00:33:08 +01:00
|
|
|
Response::respondSuccess([
|
|
|
|
'tickets' => $ticketList->toArray(true),
|
|
|
|
'page' => $page,
|
|
|
|
'pages' => ceil($countTotal / 10)
|
|
|
|
]);
|
2016-10-15 10:03:56 +02:00
|
|
|
}
|
2017-03-04 06:57:51 +01:00
|
|
|
}
|