2016-10-15 09:32:38 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
2017-04-17 04:59:11 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /ticket/change-priority Change priority
|
2018-09-20 22:19:47 +02:00
|
|
|
* @apiVersion 4.3.0
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
|
|
|
* @apiName Change priority
|
|
|
|
*
|
|
|
|
* @apiGroup Ticket
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiDescription This path changes the priority of a ticket.
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission staff1
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiParam {Number} ticketNumber The number of a ticket.
|
|
|
|
* @apiParam {String} priority The new priority of the ticket.
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiUse NO_PERMISSION
|
|
|
|
* @apiUse INVALID_TICKET
|
2018-07-17 07:04:00 +02:00
|
|
|
* @apiUse INVALID_PRIORITY
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
2018-07-17 07:04:00 +02:00
|
|
|
* @apiSuccess {Object} data Empty object
|
2017-04-17 04:59:11 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-15 09:32:38 +02:00
|
|
|
class ChangePriorityController extends Controller {
|
|
|
|
const PATH = '/change-priority';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-10-15 09:32:38 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_1',
|
|
|
|
'requestData' => [
|
|
|
|
'ticketNumber' => [
|
|
|
|
'validation' => DataValidator::validTicketNumber(),
|
|
|
|
'error' => ERRORS::INVALID_TICKET
|
|
|
|
],
|
|
|
|
'priority' => [
|
|
|
|
'validation' => DataValidator::in(['low', 'medium', 'high']),
|
|
|
|
'error' => ERRORS::INVALID_PRIORITY
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$ticketNumber = Controller::request('ticketNumber');
|
|
|
|
$priority = Controller::request('priority');
|
|
|
|
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
|
|
|
$user = Controller::getLoggedUser();
|
|
|
|
|
|
|
|
if($ticket->owner && $user->id === $ticket->owner->id) {
|
|
|
|
$ticket->priority = $priority;
|
2018-07-17 07:04:00 +02:00
|
|
|
$ticket->unread = !$ticket->isAuthor($user);
|
2016-11-20 02:54:08 +01:00
|
|
|
$event = Ticketevent::getEvent(Ticketevent::PRIORITY_CHANGED);
|
|
|
|
$event->setProperties(array(
|
2018-07-17 07:04:00 +02:00
|
|
|
'authorStaff' => Controller::getLoggedUser(),
|
2016-11-20 02:54:08 +01:00
|
|
|
'content' => $ticket->priority,
|
|
|
|
'date' => Date::getCurrentDate()
|
|
|
|
));
|
|
|
|
$ticket->addEvent($event);
|
2016-10-15 09:32:38 +02:00
|
|
|
$ticket->store();
|
2016-12-29 21:25:45 +01:00
|
|
|
|
2017-01-05 22:01:56 +01:00
|
|
|
Log::createLog('PRIORITY_CHANGED', $ticket->ticketNumber);
|
2016-10-15 09:32:38 +02:00
|
|
|
Response::respondSuccess();
|
|
|
|
} else {
|
|
|
|
Response::respondError(ERRORS::NO_PERMISSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|