From e30c434d9483192d2b2821c0d9c517cc3b0a8b49 Mon Sep 17 00:00:00 2001 From: n1rwana <93197434+n1rwana@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:36:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D1=82?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/Repositories/BugtrackerReports.php | 18 ++++++++++++------ Web/Presenters/BugtrackerPresenter.php | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Web/Models/Repositories/BugtrackerReports.php b/Web/Models/Repositories/BugtrackerReports.php index 0eae1a4d..22170d5d 100644 --- a/Web/Models/Repositories/BugtrackerReports.php +++ b/Web/Models/Repositories/BugtrackerReports.php @@ -32,17 +32,23 @@ class BugtrackerReports yield new BugReport($report); } - function getReports(int $product_id = 0, int $page = 1): \Traversable + function getReports(int $product_id = 0, int $priority = 0, int $page = 1): \Traversable { - foreach($this->reports->where(["deleted" => NULL, "product_id" => $product_id])->order("created DESC")->page($page, 5) as $report) + $filter = ["deleted" => NULL]; + $product_id && $filter["product_id"] = $product_id; + $priority && $filter["priority"] = $priority; + + foreach($this->reports->where($filter)->order("created DESC")->page($page, 5) as $report) yield new BugReport($report); } - function getReportsCount(int $product_id): int + function getReportsCount(int $product_id = 0, int $priority = 0): int { - return $product_id - ? sizeof($this->reports->where(["deleted" => NULL, "product_id" => $product_id])) - : sizeof($this->reports->where(["deleted" => NULL])); + $filter = ["deleted" => NULL]; + $product_id && $filter["product_id"] = $product_id; + $priority && $filter["priority"] = $priority; + + return sizeof($this->reports->where($filter)); } function getByReporter(int $reporter_id, int $page = 1): \Traversable diff --git a/Web/Presenters/BugtrackerPresenter.php b/Web/Presenters/BugtrackerPresenter.php index 627a9095..72b7d4b2 100644 --- a/Web/Presenters/BugtrackerPresenter.php +++ b/Web/Presenters/BugtrackerPresenter.php @@ -48,9 +48,9 @@ final class BugtrackerPresenter extends OpenVKPresenter break; default: - $this->template->count = $this->reports->getReportsCount((int) $this->queryParam("product")); + $this->template->count = $this->reports->getReportsCount((int) $this->queryParam("product"), (int) $this->queryParam("priority")); $this->template->iterator = $this->queryParam("product") - ? $this->reports->getReports((int) $this->queryParam("product"), $this->template->page) + ? $this->reports->getReports((int) $this->queryParam("product"), (int) $this->queryParam("priority"), $this->template->page) : $this->reports->getAllReports($this->template->page); break; }