opensupports/server/controllers/ticket/re-open.php

48 lines
1.5 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
class ReOpenController extends Controller {
const PATH = '/re-open';
public function validations() {
return [
'permission' => 'user',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$ticket = Ticket::getByTicketNumber($ticketNumber);
$user = Controller::getLoggedUser();
if(!Controller::isStaffLogged() && $ticket->author->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
if(Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
2016-10-21 21:12:17 +02:00
if(Controller::isStaffLogged()) {
$ticket->unread = true;
} else {
$ticket->unreadStaff = true;
}
$event = Ticketevent::getEvent(Ticketevent::RE_OPEN);
$event->setProperties(array(
'authorUser' => Controller::getLoggedUser(),
'date' => Date::getCurrentDate()
));
$ticket->addEvent($event);
$ticket->closed = false;
$ticket->store();
Response::respondSuccess();
}
}