From e00e3b90970831ed71feb3845ad647b96c63a16a Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Thu, 16 Dec 2021 20:25:42 +0200 Subject: [PATCH] Support: Fix answers evaluating Now it works --- Web/Models/Entities/TicketComment.php | 22 +++++++--------- Web/Presenters/SupportPresenter.php | 12 ++++----- Web/Presenters/templates/Support/View.xml | 32 ++++++++++++++--------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index 1acf4c50..0801c39f 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -2,7 +2,7 @@ namespace openvk\Web\Models\Entities; use openvk\Web\Util\DateTime; use openvk\Web\Models\RowModel; -use openvk\Web\Models\Repositories\{Users, SupportAliases}; +use openvk\Web\Models\Repositories\{Users, SupportAliases, Tickets}; class TicketComment extends RowModel { @@ -29,6 +29,11 @@ class TicketComment extends RowModel { return (new Users)->get($this->getRecord()->user_id); } + + function getTicket(): Ticket + { + return (new Tickets)->get($this->getRecord()->ticket_id); + } function getAuthorName(): string { @@ -116,17 +121,10 @@ class TicketComment extends RowModel function isLikedByUser(): ?bool { $mark = $this->getMark(); - switch ($mark) { - case 0: - return false; - break; - case 1: - return true; - break; - default: - return NULL; - break; - } + if(is_null($mark)) + return NULL; + else + return $mark === 1; } use Traits\TRichText; diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 6ecd9150..e34eecab 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -31,12 +31,11 @@ final class SupportPresenter extends OpenVKPresenter $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(); - + $ticket = new Ticket; $ticket->setType(0); $ticket->setUser_id($this->user->id); @@ -230,18 +229,19 @@ final class SupportPresenter extends OpenVKPresenter { $this->willExecuteWriteAction(); $this->assertUserLoggedIn(); + $this->assertNoCSRF(); $comment = $this->comments->get($id); - if($this->user->id !== $this->tickets->get($comment->getTicketId())->getUser()->getId()) + if($this->user->id !== $comment->getTicket()->getUser()->getId()) exit(header("HTTP/1.1 403 Forbidden")); - if($mark === 1 || $mark === 2) - header("HTTP/1.1 200 OK"); - else + if($mark !== 1 && $mark !== 2) exit(header("HTTP/1.1 400 Bad Request")); $comment->setMark($mark); $comment->save(); + + exit(header("HTTP/1.1 200 OK")); } } \ No newline at end of file diff --git a/Web/Presenters/templates/Support/View.xml b/Web/Presenters/templates/Support/View.xml index 8dc13960..4647a8eb 100644 --- a/Web/Presenters/templates/Support/View.xml +++ b/Web/Presenters/templates/Support/View.xml @@ -8,7 +8,7 @@ {block content}