diff --git a/Web/Models/Repositories/Tickets.php b/Web/Models/Repositories/Tickets.php index d98e9c11..62ae4286 100644 --- a/Web/Models/Repositories/Tickets.php +++ b/Web/Models/Repositories/Tickets.php @@ -22,8 +22,8 @@ class Tickets function getTickets(int $state = 0, int $page = 1): \Traversable { - foreach($this->tickets->where(["deleted" => 0, "type" => $state])->order("created DESC")->page($page, OPENVK_DEFAULT_PER_PAGE) as $t) - yield new Ticket($t); + foreach($this->tickets->where(["deleted" => 0, "type" => $state])->order("created DESC")->page($page, OPENVK_DEFAULT_PER_PAGE) as $ticket) + yield new Ticket($ticket); } function getTicketCount(int $state = 0): int @@ -31,21 +31,20 @@ class Tickets return sizeof($this->tickets->where(["deleted" => 0, "type" => $state])); } - function getTicketsByuId(int $user_id): \Traversable + function getTicketsByUserId(int $userId, int $page = 1): \Traversable { - foreach($this->tickets->where(['user_id' => $user_id, 'deleted' => 0])->order("created DESC") as $ticket) yield new Ticket($ticket); + foreach($this->tickets->where(["user_id" => $userId, "deleted" => 0])->order("created DESC")->page($page, OPENVK_DEFAULT_PER_PAGE) as $ticket) yield new Ticket($ticket); } - function getTicketsCountByuId(int $user_id, int $type = 0): int + function getTicketsCountByUserId(int $userId, int $type = 0): int { - return sizeof($this->tickets->where(['user_id' => $user_id, 'deleted' => 0, 'type' => $type])); + return sizeof($this->tickets->where(["user_id" => $userId, "deleted" => 0, "type" => $type])); } - function getRequestById(int $req_id): ?Ticket + function getRequestById(int $requestId): ?Ticket { - $requests = $this->tickets->where(['id' => $req_id])->fetch(); + $requests = $this->tickets->where(["id" => $requestId])->fetch(); if(!is_null($requests)) - return new Req($requests); else return null; diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 48d6a9af..17e36e8a 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -220,7 +220,7 @@ abstract class OpenVKPresenter extends SimplePresenter $this->user->identity->save(); } - $this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByuId($this->user->id, 1); + $this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByUserId($this->user->id, 1); if($user->can("write")->model("openvk\Web\Models\Entities\TicketReply")->whichBelongsTo(0)) $this->template->helpdeskTicketNotAnsweredCount = (new Tickets)->getTicketCount(0); } diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 9fc4defc..52a2f635 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -28,18 +28,19 @@ final class SupportPresenter extends OpenVKPresenter $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; + $this->template->count = $this->tickets->getTicketsCountByUserId($this->user->id); + if($this->template->mode === "list") { + $this->template->page = (int) ($this->queryParam("p") ?? 1); + $this->template->tickets = $this->tickets->getTicketsByUserId($this->user->id, $this->template->page); + } 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); + $ticket->setUser_Id($this->user->id); $ticket->setName($this->postParam("name")); $ticket->setText($this->postParam("text")); $ticket->setcreated(time()); @@ -136,8 +137,7 @@ final class SupportPresenter extends OpenVKPresenter if(!empty($this->postParam("text"))) { $ticket->setType(0); $ticket->save(); - - $this->assertNoCSRF(); + $this->willExecuteWriteAction(); $comment = new TicketComment; diff --git a/Web/Presenters/templates/Support/Index.xml b/Web/Presenters/templates/Support/Index.xml index c0f71b8a..dd1791c2 100644 --- a/Web/Presenters/templates/Support/Index.xml +++ b/Web/Presenters/templates/Support/Index.xml @@ -69,5 +69,15 @@ + +