2016-10-14 21:12:54 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
|
|
|
|
class UnAssignStaffController extends Controller {
|
|
|
|
const PATH = '/un-assign-ticket';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-10-14 21:12:54 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_1',
|
|
|
|
'requestData' => [
|
|
|
|
'ticketNumber' => [
|
|
|
|
'validation' => DataValidator::validTicketNumber(),
|
|
|
|
'error' => ERRORS::INVALID_TICKET
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$ticketNumber = Controller::request('ticketNumber');
|
|
|
|
$user = Controller::getLoggedUser();
|
|
|
|
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
|
|
|
|
2016-10-14 21:32:32 +02:00
|
|
|
if($ticket->owner && $ticket->owner->id == $user->id) {
|
2016-10-14 21:12:54 +02:00
|
|
|
$user->sharedTicketList->remove($ticket);
|
|
|
|
$user->store();
|
2016-12-14 00:19:17 +01:00
|
|
|
|
2016-10-14 21:12:54 +02:00
|
|
|
$ticket->owner = null;
|
2016-10-21 21:38:08 +02:00
|
|
|
$ticket->unread = true;
|
2016-12-14 00:19:17 +01:00
|
|
|
|
2016-11-20 02:54:08 +01:00
|
|
|
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
|
|
|
|
$event->setProperties(array(
|
2016-12-14 00:19:17 +01:00
|
|
|
'authorStaff' => $user,
|
2016-11-20 02:54:08 +01:00
|
|
|
'date' => Date::getCurrentDate()
|
|
|
|
));
|
|
|
|
|
|
|
|
$ticket->addEvent($event);
|
2016-10-14 21:12:54 +02:00
|
|
|
$ticket->store();
|
|
|
|
Response::respondSuccess();
|
|
|
|
} else {
|
|
|
|
Response::respondError(ERRORS::NO_PERMISSION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|