opensupports/server/controllers/staff/get-new-tickets.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2016-10-15 10:03:56 +02:00
<?php
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-04-21 08:09:24 +02:00
* @api {post} /staff/get-new-tickets Retrieve new tickets.
2017-04-18 06:39:55 +02:00
*
* @apiName Get new tickets
*
* @apiGroup staff
*
2017-04-21 08:09:24 +02:00
* @apiDescription This path retrieves new tickets.
2017-04-18 06:39:55 +02:00
*
* @apiPermission Staff level 1
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data Array of new tickets
2017-04-18 06:39:55 +02:00
*
*/
class GetNewTicketsStaffController extends Controller {
2016-10-15 10:03:56 +02:00
const PATH = '/get-new-tickets';
const METHOD = 'POST';
2016-10-15 10:03:56 +02:00
public function validations() {
return[
'permission' => 'staff_1',
'requestData' => []
];
}
public function handler() {
if (Ticket::isTableEmpty()) {
Response::respondSuccess([]);
return;
}
$user = Controller::getLoggedUser();
$query = ' (';
foreach ($user->sharedDepartmentList as $department) {
$query .= 'department_id=' . $department->id . ' OR ';
}
$query = substr($query,0,-3);
$ownerExists = RedBean::exec('SHOW COLUMNS FROM ticket LIKE \'owner_id\'');
if($ownerExists != 0) {
$query .= ') AND owner_id IS NULL';
} else {
$query .= ')';
}
$ticketList = Ticket::find($query);
Response::respondSuccess($ticketList->toArray());
2016-10-15 10:03:56 +02:00
}
}