Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Web/Models/Entities/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Club extends RowModel
public const WALL_OPEN = 1;
public const WALL_LIMITED = 2;

public const PAGES_DISABLED = 0;
public const PAGES_OPEN = 1;
public const PAGES_LIMITED = 2;

public function getId(): int
{
return $this->getRecord()->id;
Expand Down Expand Up @@ -524,6 +528,51 @@ public function canUploadDocs(?User $user): bool
return $this->canBeModifiedBy($user);
}

public function getPagesType(): int
{
return (int) ($this->getRecord()->pages ?? 0);
}

public function isPagesEnabled(): bool
{
return $this->getPagesType() !== self::PAGES_DISABLED;
}

public function setPages(int $type): void
{
if ($type > 2 || $type < 0) {
throw new \LogicException("Invalid pages");
}

$this->stateChanges("pages", $type);
}

public function canManagePages(?User $user): bool
{
if (!$user) {
return false;
}

return $this->isPagesEnabled() && $this->canBeModifiedBy($user);
}

public function canCreatePages(?User $user): bool
{
if (!$user || !$this->isPagesEnabled()) {
return false;
}

if ($this->canBeModifiedBy($user)) {
return true;
}

if ($this->getPagesType() === self::PAGES_OPEN) {
return (bool) $this->getSubscriptionStatus($user);
}

return false;
}

public function getAudiosCollectionSize()
{
return (new \openvk\Web\Models\Repositories\Audios())->getClubCollectionSize($this);
Expand Down
Loading