2016-10-08 00:03:21 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
|
2017-04-18 06:39:55 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /staff/assign-ticket Assign ticket
|
2017-06-28 15:02:54 +02:00
|
|
|
* @apiVersion 4.1.0
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
* @apiName Assign ticket
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiGroup Staff
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
* @apiDescription This path assigns a ticket to a staff member.
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission staff1
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiParam {Number} ticketNumber The number of the ticket to assign.
|
|
|
|
*
|
|
|
|
* @apiUse NO_PERMISSION
|
|
|
|
* @apiUse INVALID_TICKET
|
|
|
|
* @apiUse TICKET_ALREADY_ASSIGNED
|
|
|
|
* @apiUse INVALID_DEPARTMENT
|
2018-02-28 06:43:34 +01:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiSuccess {Object} data Empty object
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-08 00:03:21 +02:00
|
|
|
class AssignStaffController extends Controller {
|
|
|
|
const PATH = '/assign-ticket';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
|
|
|
|
2016-10-08 00:03:21 +02:00
|
|
|
private $ticket;
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_1',
|
|
|
|
'requestData' => [
|
|
|
|
'ticketNumber' => [
|
|
|
|
'validation' => DataValidator::validTicketNumber(),
|
|
|
|
'error' => ERRORS::INVALID_TICKET
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$ticketNumber = Controller::request('ticketNumber');
|
|
|
|
$this->user = Controller::getLoggedUser();
|
|
|
|
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
|
|
|
|
|
|
|
|
if($this->ticket->owner) {
|
2018-03-09 19:17:28 +01:00
|
|
|
throw new Exception(ERRORS::TICKET_ALREADY_ASSIGNED);
|
2016-10-08 00:03:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$this->ticketHasStaffDepartment()) {
|
2018-03-09 19:17:28 +01:00
|
|
|
throw new Exception(ERRORS::INVALID_DEPARTMENT);
|
2016-10-08 00:03:21 +02:00
|
|
|
} else {
|
|
|
|
$this->user->sharedTicketList->add($this->ticket);
|
|
|
|
$this->ticket->owner = $this->user;
|
2016-10-21 21:12:17 +02:00
|
|
|
$this->ticket->unread = true;
|
2016-11-20 02:54:08 +01:00
|
|
|
$event = Ticketevent::getEvent(Ticketevent::ASSIGN);
|
|
|
|
$event->setProperties(array(
|
|
|
|
'authorStaff' => Controller::getLoggedUser(),
|
|
|
|
'date' => Date::getCurrentDate()
|
|
|
|
));
|
|
|
|
$this->ticket->addEvent($event);
|
|
|
|
|
2016-10-08 00:03:21 +02:00
|
|
|
$this->ticket->store();
|
|
|
|
$this->user->store();
|
2016-11-20 02:54:08 +01:00
|
|
|
|
2016-10-08 00:03:21 +02:00
|
|
|
Response::respondSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ticketHasStaffDepartment() {
|
|
|
|
$departmentMatch = false;
|
|
|
|
|
|
|
|
foreach ($this->user->sharedDepartmentList as $department) {
|
|
|
|
if($this->ticket->department->id === $department->id) {
|
|
|
|
$departmentMatch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $departmentMatch;
|
|
|
|
}
|
|
|
|
}
|