context = DB::i()->getContext(); $this->blacklists = $this->context->table("blacklists"); } function getList(User $user, $page = 1): \Traversable { foreach($this->blacklists->where("author", $user->getId())->order("created DESC")->page($page, 10) as $blacklistItem) yield new BlacklistItem($blacklistItem); } function getByAuthorAndTarget(int $author, int $target): ?BlacklistItem { $fetch = $this->blacklists->where(["author" => $author, "target" => $target])->fetch(); if ($fetch) return new BlacklistItem($fetch); else return null; } function getCount(User $user): int { return sizeof($this->blacklists->where("author", $user->getId())->fetch()); } function isBanned(User $author, User $target): bool { if (!$author || !$target) return FALSE; return !is_null($this->getByAuthorAndTarget($author->getId(), $target->getId())); } }