2016-10-20 23:34:06 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
|
|
|
class SeenController extends Controller {
|
|
|
|
const PATH = '/seen';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-10-20 23:34:06 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'user',
|
|
|
|
'requestData' => [
|
|
|
|
'ticketNumber' => [
|
|
|
|
'validation' => DataValidator::validTicketNumber(),
|
|
|
|
'error' => ERRORS::INVALID_TICKET
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$ticketnumber = Controller::request('ticketNumber');
|
2016-10-21 06:08:06 +02:00
|
|
|
$user = Controller::getLoggedUser();
|
|
|
|
$ticket = Ticket::getByTicketNumber($ticketnumber);
|
|
|
|
|
2016-10-21 21:12:17 +02:00
|
|
|
if (Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id === $user->id) {
|
2016-10-21 06:08:06 +02:00
|
|
|
$ticket->unreadStaff = false;
|
|
|
|
$ticket->store();
|
|
|
|
Response::respondSuccess();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-21 21:12:17 +02:00
|
|
|
if (!Controller::isStaffLogged() && $ticket->author && $user->id === $ticket->author->id) {
|
2016-10-21 06:08:06 +02:00
|
|
|
$ticket->unread = false;
|
|
|
|
$ticket->store();
|
|
|
|
Response::respondSuccess();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Response::respondError(ERRORS::NO_PERMISSION);
|
|
|
|
|
2016-10-20 23:34:06 +02:00
|
|
|
}
|
|
|
|
}
|