mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Support: Make the code more similar to rest of code in the project
This commit is contained in:
parent
2af7dcc4f4
commit
1b510ca6a3
3 changed files with 35 additions and 69 deletions
|
@ -1,13 +1,8 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Entities;
|
namespace openvk\Web\Models\Entities;
|
||||||
use openvk\Web\Util\DateTime;
|
use openvk\Web\Util\DateTime;
|
||||||
use Nette\Database\Table\ActiveRow;
|
|
||||||
use openvk\Web\Models\RowModel;
|
use openvk\Web\Models\RowModel;
|
||||||
use Chandler\Database\DatabaseConnection;
|
|
||||||
use openvk\Web\Models\Repositories\Users;
|
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
|
class Ticket extends RowModel
|
||||||
{
|
{
|
||||||
|
@ -22,14 +17,7 @@ class Ticket extends RowModel
|
||||||
|
|
||||||
function getStatus(): string
|
function getStatus(): string
|
||||||
{
|
{
|
||||||
if ($this->getRecord()->type === 0)
|
return tr("support_status_" . $this->getRecord()->type);
|
||||||
{
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getType(): int
|
function getType(): int
|
||||||
|
@ -58,17 +46,7 @@ class Ticket extends RowModel
|
||||||
|
|
||||||
function isDeleted(): bool
|
function isDeleted(): bool
|
||||||
{
|
{
|
||||||
if ($this->getRecord()->deleted === 0)
|
return (bool) $this->getRecord()->deleted;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
} elseif ($this->getRecord()->deleted === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function authorId(): int
|
|
||||||
{
|
|
||||||
return $this->getRecord()->user_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUser(): user
|
function getUser(): user
|
||||||
|
@ -76,6 +54,11 @@ class Ticket extends RowModel
|
||||||
return (new Users)->get($this->getRecord()->user_id);
|
return (new Users)->get($this->getRecord()->user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUserId(): int
|
||||||
|
{
|
||||||
|
return $this->getRecord()->user_id;
|
||||||
|
}
|
||||||
|
|
||||||
function isAd(): bool /* Эх, костыли... */
|
function isAd(): bool /* Эх, костыли... */
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Entities;
|
namespace openvk\Web\Models\Entities;
|
||||||
use openvk\Web\Util\DateTime;
|
use openvk\Web\Util\DateTime;
|
||||||
use Nette\Database\Table\ActiveRow;
|
|
||||||
use openvk\Web\Models\RowModel;
|
use openvk\Web\Models\RowModel;
|
||||||
use Chandler\Database\DatabaseConnection;
|
|
||||||
use openvk\Web\Models\Repositories\{Users, SupportAliases};
|
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
|
class TicketComment extends RowModel
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
namespace openvk\Web\Presenters;
|
namespace openvk\Web\Presenters;
|
||||||
use openvk\Web\Models\Entities\Ticket;
|
use openvk\Web\Models\Entities\Ticket;
|
||||||
use openvk\Web\Models\Repositories\Tickets;
|
use openvk\Web\Models\Repositories\Tickets;
|
||||||
//
|
|
||||||
use openvk\Web\Models\Entities\TicketComment;
|
use openvk\Web\Models\Entities\TicketComment;
|
||||||
use openvk\Web\Models\Repositories\TicketComments;
|
use openvk\Web\Models\Repositories\TicketComments;
|
||||||
// use openvk\Web\Models\Repositories\Users;
|
|
||||||
use openvk\Web\Models\RowModel;
|
use openvk\Web\Models\RowModel;
|
||||||
use openvk\Web\Util\Telegram;
|
use openvk\Web\Util\Telegram;
|
||||||
use Nette\Database\Table\ActiveRow;
|
use Nette\Database\Table\ActiveRow;
|
||||||
|
@ -34,15 +32,11 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
$this->template->mode = in_array($this->queryParam("act"), ["faq", "new", "list"]) ? $this->queryParam("act") : "faq";
|
$this->template->mode = in_array($this->queryParam("act"), ["faq", "new", "list"]) ? $this->queryParam("act") : "faq";
|
||||||
|
|
||||||
$tickets = $this->tickets->getTicketsByuId($this->user->id);
|
$tickets = $this->tickets->getTicketsByuId($this->user->id);
|
||||||
if ($tickets) {
|
if($tickets)
|
||||||
$this->template->tickets = $tickets;
|
$this->template->tickets = $tickets;
|
||||||
}
|
|
||||||
|
|
||||||
|
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
if($_SERVER["REQUEST_METHOD"] === "POST")
|
if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) {
|
||||||
{
|
|
||||||
if(!empty($this->postParam("name")) && !empty($this->postParam("text")))
|
|
||||||
{
|
|
||||||
$this->assertNoCSRF();
|
$this->assertNoCSRF();
|
||||||
$this->willExecuteWriteAction();
|
$this->willExecuteWriteAction();
|
||||||
|
|
||||||
|
@ -70,7 +64,6 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
} else {
|
} else {
|
||||||
$this->flashFail("err", "Ошибка", "Вы не ввели имя или текст");
|
$this->flashFail("err", "Ошибка", "Вы не ввели имя или текст");
|
||||||
}
|
}
|
||||||
// $this->template->test = 'cool post';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +95,12 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
{
|
{
|
||||||
$this->assertUserLoggedIn();
|
$this->assertUserLoggedIn();
|
||||||
$ticket = $this->tickets->get($id);
|
$ticket = $this->tickets->get($id);
|
||||||
$ticketComments1 = $this->comments->getCommentsById($id);
|
$ticketComments = $this->comments->getCommentsById($id);
|
||||||
if(!$ticket || $ticket->isDeleted() != 0 || $ticket->authorId() !== $this->user->id) {
|
if(!$ticket || $ticket->isDeleted() != 0 || $ticket->getUserId() !== $this->user->id) {
|
||||||
$this->notFound();
|
$this->notFound();
|
||||||
} else {
|
} else {
|
||||||
$this->template->ticket = $ticket;
|
$this->template->ticket = $ticket;
|
||||||
$this->template->comments = $ticketComments1;
|
$this->template->comments = $ticketComments;
|
||||||
$this->template->id = $id;
|
$this->template->id = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,11 +112,11 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
if(!empty($id)) {
|
if(!empty($id)) {
|
||||||
$ticket = $this->tickets->get($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();
|
$this->notFound();
|
||||||
} else {
|
} else {
|
||||||
header("HTTP/1.1 302 Found");
|
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");
|
header("Location: /support/tickets");
|
||||||
else
|
else
|
||||||
header("Location: /support");
|
header("Location: /support");
|
||||||
|
@ -136,16 +129,14 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
{
|
{
|
||||||
$ticket = $this->tickets->get($id);
|
$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("HTTP/1.1 403 Forbidden");
|
||||||
header("Location: /support/view/" . $id);
|
header("Location: /support/view/" . $id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($_SERVER["REQUEST_METHOD"] === "POST")
|
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
{
|
if(!empty($this->postParam("text"))) {
|
||||||
if(!empty($this->postParam("text")))
|
|
||||||
{
|
|
||||||
$ticket->setType(0);
|
$ticket->setType(0);
|
||||||
$ticket->save();
|
$ticket->save();
|
||||||
|
|
||||||
|
@ -188,12 +179,10 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
$ticket = $this->tickets->get($id);
|
$ticket = $this->tickets->get($id);
|
||||||
|
|
||||||
if($_SERVER["REQUEST_METHOD"] === "POST")
|
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
{
|
|
||||||
$this->willExecuteWriteAction();
|
$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->setType($this->postParam("status"));
|
||||||
$ticket->save();
|
$ticket->save();
|
||||||
|
|
||||||
|
@ -212,7 +201,6 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
$this->flashFail("succ", "Тикет изменён", "Изменения вступят силу через несколько секунд.");
|
$this->flashFail("succ", "Тикет изменён", "Изменения вступят силу через несколько секунд.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderKnowledgeBaseArticle(string $name): void
|
function renderKnowledgeBaseArticle(string $name): void
|
||||||
|
|
Loading…
Reference in a new issue