opensupports/server/controllers/ticket/comment.php

67 lines
2.0 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class CommentController extends Controller {
const PATH = '/comment';
private $ticket;
private $content;
public function validations() {
return [
'permission' => 'user',
'requestData' => [
'content' => [
'validation' => DataValidator::length(20, 5000),
'error' => ERRORS::INVALID_CONTENT
],
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$session = Session::getInstance();
$this->requestData();
if ($session->isLoggedWithId($this->ticket->author->id) || Controller::isStaffLogged()) {
$this->storeComment();
2016-12-29 21:25:45 +01:00
Log::createLog('COMMENT_TICKET', $this->ticket);
Response::respondSuccess();
} else {
Response::respondError(ERRORS::NO_PERMISSION);
}
}
private function requestData() {
$ticketNumber = Controller::request('ticketNumber');
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
$this->content = Controller::request('content');
}
private function storeComment() {
2016-09-29 19:34:20 +02:00
$comment = Ticketevent::getEvent(Ticketevent::COMMENT);
$comment->setProperties(array(
'content' => $this->content,
'date' => Date::getCurrentDate()
));
2016-09-29 19:34:20 +02:00
if(Controller::isStaffLogged()) {
2016-10-21 21:12:17 +02:00
$this->ticket->unread = true;
$comment->authorStaff = Controller::getLoggedUser();
2016-09-29 19:34:20 +02:00
} else {
2016-10-21 21:12:17 +02:00
$this->ticket->unreadStaff = true;
$comment->authorUser = Controller::getLoggedUser();
2016-09-29 19:34:20 +02:00
}
$this->ticket->addEvent($comment);
$this->ticket->store();
}
}