mirror of
https://github.com/openvk/openvk
synced 2024-11-13 10:39:24 +03:00
Support: Use pagination in the user's ticket list
This commit is contained in:
parent
f7fbda1e3c
commit
02e41e19b4
4 changed files with 26 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -69,5 +69,15 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div style="padding: 8px;">
|
||||
{include "../components/paginator.xml", conf => (object) [
|
||||
"page" => $page,
|
||||
"count" => $count,
|
||||
"amount" => sizeof($tickets),
|
||||
"perPage" => OPENVK_DEFAULT_PER_PAGE,
|
||||
"atBottom" => true,
|
||||
]}
|
||||
</div>
|
||||
{/if}
|
||||
{/block}
|
||||
|
|
Loading…
Reference in a new issue