From 98045ec121997962f9291d3445f7918004a7bfc8 Mon Sep 17 00:00:00 2001 From: Alma Armas Date: Sat, 1 Aug 2020 14:22:52 +0000 Subject: [PATCH] Add club managers logic to Club model --- Web/Models/Entities/Club.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index cad4eafb..10a97154 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -2,8 +2,8 @@ namespace openvk\Web\Models\Entities; use openvk\Web\Util\DateTime; use openvk\Web\Models\RowModel; -use openvk\Web\Models\Entities\User; -use openvk\Web\Models\Repositories\{Users, Clubs, Albums}; +use openvk\Web\Models\Entities\{User, Manager}; +use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers}; use Nette\Database\Table\{ActiveRow, GroupedSelection}; use Chandler\Database\DatabaseConnection as DB; use Chandler\Security\User as ChandlerUser; @@ -265,6 +265,20 @@ class Club extends RowModel foreach($rels as $rel) { $rel = (new Users)->get($rel->user); if(!$rel) continue; + + yield $rel; + } + } + + function getManagersWithComment(int $page = 1): \Traversable + { + $rels = $this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")->page($page, 10); + + foreach($rels as $rel) { + $rel = (new Managers)->get($rel->id); + if(!$rel) continue; + + yield $rel; } } @@ -272,6 +286,11 @@ class Club extends RowModel { return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; } + + function getManagersCountWithComment(): int + { + return sizeof($this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")) + 1; + } function addManager(User $user, ?string $comment = NULL): void { @@ -293,7 +312,7 @@ class Club extends RowModel function canBeModifiedBy(User $user): bool { $id = $user->getId(); - if($this->getRecord()->owner === $id) + if($this->getOwner()->getId() === $id) return true; return !is_null($this->getRecord()->related("group_coadmins.club")->where("user", $id)->fetch());