From 3dcfc5dd505cd1dbdf98fb3789e89991309fb30d Mon Sep 17 00:00:00 2001 From: n1rwana <93197434+n1rwana@users.noreply.github.com> Date: Mon, 22 Aug 2022 02:11:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D1=82=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/Entities/BugReport.php | 2 +- Web/Models/Entities/BugReportComment.php | 6 +++ Web/Models/Entities/BugtrackerProduct.php | 6 +++ Web/Models/Entities/User.php | 5 ++ .../Repositories/BugtrackerProducts.php | 13 +++-- Web/Models/Repositories/BugtrackerReports.php | 4 +- Web/Presenters/BugtrackerPresenter.php | 53 +++++++++++-------- Web/Presenters/templates/Bugtracker/Index.xml | 32 +++++++---- Web/Presenters/templates/Bugtracker/View.xml | 36 ++++++++----- Web/routes.yml | 2 + install/sqls/00030-bug-tracker.sql | 3 +- locales/en.strings | 4 +- locales/ru.strings | 2 +- 13 files changed, 114 insertions(+), 54 deletions(-) diff --git a/Web/Models/Entities/BugReport.php b/Web/Models/Entities/BugReport.php index 65976261..563b9baa 100644 --- a/Web/Models/Entities/BugReport.php +++ b/Web/Models/Entities/BugReport.php @@ -92,7 +92,7 @@ class BugReport extends RowModel return $this->getRecord()->reproduced; } - function getCreationDate(): DateTime + function getCreationTime(): DateTime { return new DateTime($this->getRecord()->created); } diff --git a/Web/Models/Entities/BugReportComment.php b/Web/Models/Entities/BugReportComment.php index 281cfcfc..da69a9eb 100644 --- a/Web/Models/Entities/BugReportComment.php +++ b/Web/Models/Entities/BugReportComment.php @@ -1,5 +1,6 @@ getRecord()->point_actions; } + + function getCreationTime(): DateTime + { + return new DateTime($this->getRecord()->created); + } } \ No newline at end of file diff --git a/Web/Models/Entities/BugtrackerProduct.php b/Web/Models/Entities/BugtrackerProduct.php index a89c8596..264b7f22 100644 --- a/Web/Models/Entities/BugtrackerProduct.php +++ b/Web/Models/Entities/BugtrackerProduct.php @@ -1,5 +1,6 @@ getRecord()->closed; } + + function getCreationTime(): DateTime + { + return new DateTime($this->getRecord()->created); + } } \ No newline at end of file diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 44db0cd9..2fcc3c64 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1017,6 +1017,11 @@ class User extends RowModel { return (bool) $this->getRecord()->activated; } + + function isBtModerator(): bool + { + return $this->getChandlerUser()->can("admin")->model('openvk\Web\Models\Repositories\BugtrackerReports')->whichBelongsTo(NULL); + } use Traits\TSubscribable; } diff --git a/Web/Models/Repositories/BugtrackerProducts.php b/Web/Models/Repositories/BugtrackerProducts.php index 1803880a..0bcebd5a 100644 --- a/Web/Models/Repositories/BugtrackerProducts.php +++ b/Web/Models/Repositories/BugtrackerProducts.php @@ -25,15 +25,20 @@ class BugtrackerProducts return $this->toProduct($this->products->get($id)); } - function getAll(): \Traversable + function getAll(int $page = 1): \Traversable { - foreach($this->products->order("id ASC") as $product) + foreach($this->products->order("id ASC")->page($page, 5) as $product) yield new BugtrackerProduct($product); } - function getOpen(): \Traversable + function getOpen(int $page = 1): \Traversable { - foreach($this->products->where(["closed" => 0])->order("id ASC") as $product) + foreach($this->products->where(["closed" => 0])->order("id ASC")->page($page, 5) as $product) yield new BugtrackerProduct($product); } + + function getCount(): ?int + { + return sizeof($this->products->where(["closed" => 0])); + } } \ No newline at end of file diff --git a/Web/Models/Repositories/BugtrackerReports.php b/Web/Models/Repositories/BugtrackerReports.php index d5465a38..0eae1a4d 100644 --- a/Web/Models/Repositories/BugtrackerReports.php +++ b/Web/Models/Repositories/BugtrackerReports.php @@ -51,12 +51,12 @@ class BugtrackerReports yield new BugReport($report); } - function getCountByReporter(int $reporter_id) + function getCountByReporter(int $reporter_id): ?int { return sizeof($this->reports->where(["deleted" => NULL, "reporter" => $reporter_id])); } - function getSuccCountByReporter(int $reporter_id) + function getSuccCountByReporter(int $reporter_id): ?int { return sizeof($this->reports->where(["deleted" => NULL, "reporter" => $reporter_id, "status" => "<= 4"])); } diff --git a/Web/Presenters/BugtrackerPresenter.php b/Web/Presenters/BugtrackerPresenter.php index 3f7501ba..627a9095 100644 --- a/Web/Presenters/BugtrackerPresenter.php +++ b/Web/Presenters/BugtrackerPresenter.php @@ -23,29 +23,39 @@ final class BugtrackerPresenter extends OpenVKPresenter function renderIndex(): void { $this->assertUserLoggedIn(); - $this->template->mode = in_array($this->queryParam("act"), ["list", "show", "products", "new_product", "reporter", "new"]) ? $this->queryParam("act") : "list"; + $this->template->mode = in_array($this->queryParam("act"), ["list", "products", "new_product", "reporter", "new"]) ? $this->queryParam("act") : "list"; + + if($this->queryParam("act") === "show") + $this->redirect("/bug" . $this->queryParam("id")); $this->template->user = $this->user; - - $this->template->all_products = $this->products->getAll(); + $this->template->page = (int) ($this->queryParam("p") ?? 1); + $this->template->open_products = $this->products->getOpen(); - if($this->template->mode === "reporter") { - $this->template->reporter = (new Users)->get((int) $this->queryParam("id")); - $this->template->reporter_stats = [$this->reports->getCountByReporter((int) $this->queryParam("id")), $this->reports->getSuccCountByReporter((int) $this->queryParam("id"))]; + switch ($this->template->mode) { + case 'reporter': + $this->template->reporter = (new Users)->get((int) $this->queryParam("id")); + $this->template->reporter_stats = [$this->reports->getCountByReporter((int) $this->queryParam("id")), $this->reports->getSuccCountByReporter((int) $this->queryParam("id"))]; - $this->template->page = (int) ($this->queryParam("p") ?? 1); - $this->template->iterator = $this->reports->getByReporter((int) $this->queryParam("id")); - $this->template->count = $this->reports->getCountByReporter((int) $this->queryParam("id")); - } else { - $this->template->page = (int) ($this->queryParam("p") ?? 1); - $this->template->count = $this->reports->getReportsCount((int) $this->queryParam("product")); - $this->template->iterator = $this->queryParam("product") - ? $this->reports->getReports((int) $this->queryParam("product"), $this->template->page) - : $this->reports->getAllReports($this->template->page); + $this->template->iterator = $this->reports->getByReporter((int) $this->queryParam("id"), $this->template->page); + $this->template->count = $this->reports->getCountByReporter((int) $this->queryParam("id")); + break; + + case 'products': + $this->template->count = $this->products->getCount(); + $this->template->iterator = $this->products->getAll($this->template->page); + break; + + default: + $this->template->count = $this->reports->getReportsCount((int) $this->queryParam("product")); + $this->template->iterator = $this->queryParam("product") + ? $this->reports->getReports((int) $this->queryParam("product"), $this->template->page) + : $this->reports->getAllReports($this->template->page); + break; } - $this->template->canAdminBugTracker = $this->user->identity->getChandlerUser()->can("admin")->model('openvk\Web\Models\Repositories\BugtrackerReports')->whichBelongsTo(NULL); + $this->template->isModerator = $this->user->identity->isBtModerator(); } function renderView(int $id): void @@ -59,7 +69,7 @@ final class BugtrackerPresenter extends OpenVKPresenter $this->template->reporter = $this->template->bug->getReporter(); $this->template->comments = $this->comments->getByReport($this->template->bug); - $this->template->canAdminBugTracker = $this->user->identity->getChandlerUser()->can("admin")->model('openvk\Web\Models\Repositories\BugtrackerReports')->whichBelongsTo(NULL); + $this->template->isModerator = $this->user->identity->isBtModerator(); } else { $this->flashFail("err", tr("bug_tracker_report_not_found")); } @@ -127,12 +137,12 @@ final class BugtrackerPresenter extends OpenVKPresenter function createComment(?BugReport $report, string $text, string $label = "", bool $is_moder = FALSE, bool $is_hidden = FALSE, string $point_actions = NULL) { - $moder = $this->user->identity->getChandlerUser()->can("admin")->model('openvk\Web\Models\Repositories\BugtrackerReports')->whichBelongsTo(NULL); + $moder = $this->user->identity->isBtModerator(); if (!$text && !$label) $this->flashFail("err", tr("error"), tr("bug_tracker_empty_comment")); - if ($report->getRawStatus() == 6 && !$moder) + if (in_array($report->getRawStatus(), [5, 6]) && !$moder) $this->flashFail("err", tr("forbidden")); DB::i()->getContext()->table("bt_comments")->insert([ @@ -142,7 +152,8 @@ final class BugtrackerPresenter extends OpenVKPresenter "is_hidden" => $moder === $is_hidden, "point_actions" => $point_actions, "text" => $text, - "label" => $label + "label" => $label, + "created" => time() ]); $this->flashFail("succ", tr("bug_tracker_success"), tr("bug_tracker_comment_sent")); @@ -192,7 +203,7 @@ final class BugtrackerPresenter extends OpenVKPresenter $this->assertUserLoggedIn(); $this->willExecuteWriteAction(); - $moder = $this->user->identity->getChandlerUser()->can("admin")->model('openvk\Web\Models\Repositories\BugtrackerReports')->whichBelongsTo(NULL); + $moder = $this->user->identity->isBtModerator(); if (!$moder) $this->flashFail("err", tr("forbidden")); diff --git a/Web/Presenters/templates/Bugtracker/Index.xml b/Web/Presenters/templates/Bugtracker/Index.xml index e58ad6b8..9d15cb79 100644 --- a/Web/Presenters/templates/Bugtracker/Index.xml +++ b/Web/Presenters/templates/Bugtracker/Index.xml @@ -60,7 +60,7 @@
|