diff --git a/Web/Models/Entities/Ticket.php b/Web/Models/Entities/Ticket.php index 89f18b62..31690ce3 100644 --- a/Web/Models/Entities/Ticket.php +++ b/Web/Models/Entities/Ticket.php @@ -1,13 +1,8 @@ getRecord()->type === 0) - { - return tr("support_status_0"); - } elseif ($this->getRecord()->type === 1) { - return tr("support_status_1"); - } elseif ($this->getRecord()->type === 2) { - return tr("support_status_2"); - } + return tr("support_status_" . $this->getRecord()->type); } function getType(): int @@ -58,17 +46,7 @@ class Ticket extends RowModel function isDeleted(): bool { - if ($this->getRecord()->deleted === 0) - { - return false; - } elseif ($this->getRecord()->deleted === 1) { - return true; - } - } - - function authorId(): int - { - return $this->getRecord()->user_id; + return (bool) $this->getRecord()->deleted; } function getUser(): user @@ -76,6 +54,11 @@ class Ticket extends RowModel return (new Users)->get($this->getRecord()->user_id); } + function getUserId(): int + { + return $this->getRecord()->user_id; + } + function isAd(): bool /* Эх, костыли... */ { return false; diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index ae724831..472177d1 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -1,13 +1,8 @@ tickets = $tickets; + $this->tickets = $tickets; $this->comments = $ticketComments; parent::__construct(); @@ -30,19 +28,15 @@ final class SupportPresenter extends OpenVKPresenter function renderIndex(): void { - $this->assertUserLoggedIn(); - $this->template->mode = in_array($this->queryParam("act"), ["faq", "new", "list"]) ? $this->queryParam("act") : "faq"; - - $tickets = $this->tickets->getTicketsByuId($this->user->id); - if ($tickets) { - $this->template->tickets = $tickets; - } - - - if($_SERVER["REQUEST_METHOD"] === "POST") - { - if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) - { + $this->assertUserLoggedIn(); + $this->template->mode = in_array($this->queryParam("act"), ["faq", "new", "list"]) ? $this->queryParam("act") : "faq"; + + $tickets = $this->tickets->getTicketsByuId($this->user->id); + if($tickets) + $this->template->tickets = $tickets; + + if($_SERVER["REQUEST_METHOD"] === "POST") { + if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) { $this->assertNoCSRF(); $this->willExecuteWriteAction(); @@ -68,9 +62,8 @@ final class SupportPresenter extends OpenVKPresenter header("HTTP/1.1 302 Found"); header("Location: /support/view/" . $ticket->getId()); } else { - $this->flashFail("err", "Ошибка", "Вы не ввели имя или текст "); + $this->flashFail("err", "Ошибка", "Вы не ввели имя или текст"); } - // $this->template->test = 'cool post'; } } @@ -101,14 +94,14 @@ final class SupportPresenter extends OpenVKPresenter function renderView(int $id): void { $this->assertUserLoggedIn(); - $ticket = $this->tickets->get($id); - $ticketComments1 = $this->comments->getCommentsById($id); - if(!$ticket || $ticket->isDeleted() != 0 || $ticket->authorId() !== $this->user->id) { + $ticket = $this->tickets->get($id); + $ticketComments = $this->comments->getCommentsById($id); + if(!$ticket || $ticket->isDeleted() != 0 || $ticket->getUserId() !== $this->user->id) { $this->notFound(); } else { - $this->template->ticket = $ticket; - $this->template->comments = $ticketComments1; - $this->template->id = $id; + $this->template->ticket = $ticket; + $this->template->comments = $ticketComments; + $this->template->id = $id; } } @@ -119,11 +112,11 @@ final class SupportPresenter extends OpenVKPresenter if(!empty($id)) { $ticket = $this->tickets->get($id); - if(!$ticket || $ticket->isDeleted() != 0 || $ticket->authorId() !== $this->user->id && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) { + if(!$ticket || $ticket->isDeleted() != 0 || $ticket->getUserId() !== $this->user->id && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) { $this->notFound(); } else { header("HTTP/1.1 302 Found"); - if($ticket->authorId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) + if($ticket->getUserId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) header("Location: /support/tickets"); else header("Location: /support"); @@ -136,16 +129,14 @@ final class SupportPresenter extends OpenVKPresenter { $ticket = $this->tickets->get($id); - if($ticket->isDeleted() === 1 || $ticket->getType() === 2 || $ticket->authorId() !== $this->user->id) { + if($ticket->isDeleted() === 1 || $ticket->getType() === 2 || $ticket->getUserId() !== $this->user->id) { header("HTTP/1.1 403 Forbidden"); header("Location: /support/view/" . $id); exit; } - if($_SERVER["REQUEST_METHOD"] === "POST") - { - if(!empty($this->postParam("text"))) - { + if($_SERVER["REQUEST_METHOD"] === "POST") { + if(!empty($this->postParam("text"))) { $ticket->setType(0); $ticket->save(); @@ -177,9 +168,9 @@ final class SupportPresenter extends OpenVKPresenter $this->notFound(); $ticketComments = $this->comments->getCommentsById($id); - $this->template->ticket = $ticket; - $this->template->comments = $ticketComments; - $this->template->id = $id; + $this->template->ticket = $ticket; + $this->template->comments = $ticketComments; + $this->template->id = $id; } function renderAnswerTicketReply(int $id): void @@ -188,12 +179,10 @@ final class SupportPresenter extends OpenVKPresenter $ticket = $this->tickets->get($id); - if($_SERVER["REQUEST_METHOD"] === "POST") - { + if($_SERVER["REQUEST_METHOD"] === "POST") { $this->willExecuteWriteAction(); - if(!empty($this->postParam("text")) && !empty($this->postParam("status"))) - { + if(!empty($this->postParam("text")) && !empty($this->postParam("status"))) { $ticket->setType($this->postParam("status")); $ticket->save(); @@ -205,14 +194,13 @@ final class SupportPresenter extends OpenVKPresenter $comment->setTicket_id($id); $comment->setCreated(time()); $comment->save(); - } elseif (empty($this->postParam("text"))) { + } elseif(empty($this->postParam("text"))) { $ticket->setType($this->postParam("status")); $ticket->save(); } $this->flashFail("succ", "Тикет изменён", "Изменения вступят силу через несколько секунд."); } - } function renderKnowledgeBaseArticle(string $name): void