opensupports/server/controllers/ticket/seen.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2016-10-20 23:34:06 +02:00
<?php
use Respect\Validation\Validator as DataValidator;
2017-04-17 04:59:11 +02:00
/**
* @api {post} /ticket/seen See ticket
* @apiVersion 4.0.0
2017-04-17 04:59:11 +02:00
*
* @apiName See ticket
2017-04-17 04:59:11 +02:00
*
* @apiGroup Ticket
*
* @apiDescription This path sets "unread" value to false, so it does not appear highlighted.
2017-04-17 04:59:11 +02:00
*
* @apiPermission user
*
* @apiParam {Number} ticketNumber Number 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
2017-04-17 04:59:11 +02:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {Object} data Empty object
2017-04-17 04:59:11 +02:00
*
*/
2016-10-20 23:34:06 +02:00
class SeenController extends Controller {
const PATH = '/seen';
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
}
}