Support: Make the code more similar to rest of code in the project

This commit is contained in:
Maxim Leshchenko 2021-12-10 18:36:50 +02:00
parent 2af7dcc4f4
commit 1b510ca6a3
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
3 changed files with 35 additions and 69 deletions

View file

@ -1,13 +1,8 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use openvk\Web\Util\DateTime;
use Nette\Database\Table\ActiveRow;
use openvk\Web\Models\RowModel;
use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Repositories\Users;
use Chandler\Database\DatabaseConnection as DB;
use Nette\InvalidStateException as ISE;
use Nette\Database\Table\Selection;
class Ticket extends RowModel
{
@ -22,14 +17,7 @@ class Ticket extends RowModel
function getStatus(): string
{
if ($this->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;

View file

@ -1,13 +1,8 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use openvk\Web\Util\DateTime;
use Nette\Database\Table\ActiveRow;
use openvk\Web\Models\RowModel;
use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Repositories\{Users, SupportAliases};
use Chandler\Database\DatabaseConnection as DB;
use Nette\InvalidStateException as ISE;
use Nette\Database\Table\Selection;
class TicketComment extends RowModel
{

View file

@ -2,10 +2,8 @@
namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\Ticket;
use openvk\Web\Models\Repositories\Tickets;
//
use openvk\Web\Models\Entities\TicketComment;
use openvk\Web\Models\Repositories\TicketComments;
// use openvk\Web\Models\Repositories\Users;
use openvk\Web\Models\RowModel;
use openvk\Web\Util\Telegram;
use Nette\Database\Table\ActiveRow;
@ -22,7 +20,7 @@ final class SupportPresenter extends OpenVKPresenter
function __construct(Tickets $tickets, TicketComments $ticketComments)
{
$this->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