auth = new Auth(); $this->categoryIdsGetter = new CategoryIdsGetter(); } public function canAdd(): bool { $user = $this->auth->getUserFromSession(); if ($user === null) { return false; } return true; } public function canDelete($categoryId, $authorId): bool { $user = $this->auth->getUserFromSession(); if ($user === null) { return false; } if ($authorId === $user->id) { return true; } if ($user->role === Role::admin()->value) { return true; } if ($user->role === Role::moderator()->value) { return in_array($categoryId, $this->categoryIdsGetter->exec()); } return false; } public function canChange($categoryId, $authorId): bool { $user = $this->auth->getUserFromSession(); if ($user === null) { return false; } if ($authorId === $user->id) { return true; } if ($user->role === Role::admin()->value) { return true; } if ($user->role === Role::moderator()->value) { return in_array($categoryId, $this->categoryIdsGetter->exec()); } return false; } }