Enums
1 year ago
ApiConnection.php
1 year ago
MemberLevel.php
2 years ago
MemberSection.php
1 year ago
Membership.php
1 year ago
MembershipChange.php
1 year ago
Page.php
1 year ago
Settings.php
2 years ago
User.php
1 year ago
MemberLevel.php
103 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace FapiMember\Model; |
| 4 | |
| 5 | use FapiMember\Library\SmartEmailing\Types\IntArray; |
| 6 | use FapiMember\Library\SmartEmailing\Types\IntType; |
| 7 | use FapiMember\Library\SmartEmailing\Types\StringType; |
| 8 | |
| 9 | class MemberLevel |
| 10 | { |
| 11 | protected int $id; |
| 12 | protected string $name; |
| 13 | protected int|null $parentId; |
| 14 | protected string|null $unlockType; |
| 15 | protected array|null $pageIds; |
| 16 | protected int|null $noAccessPageId; |
| 17 | protected int|null $loginPageId; |
| 18 | protected int|null $afterLoginPageId; |
| 19 | |
| 20 | public function __construct($data) |
| 21 | { |
| 22 | $this->id = IntType::extract($data, 'id'); |
| 23 | $this->name = StringType::extract($data ,'name'); |
| 24 | |
| 25 | $parentId = IntType::extractOrNull($data, 'parent_id'); |
| 26 | $this->parentId = $parentId === 0 |
| 27 | ? null |
| 28 | : $parentId; |
| 29 | |
| 30 | $this->unlockType = StringType::extractOrNull($data, 'unlock_type'); |
| 31 | |
| 32 | $this->pageIds = IntArray::extract($data, 'page_ids'); |
| 33 | $this->noAccessPageId = IntType::extractOrNull($data, 'no_access_page_id'); |
| 34 | $this->loginPageId = IntType::extractOrNull($data, 'login_page_id'); |
| 35 | $this->afterLoginPageId = IntType::extractOrNull($data, 'after_login_page_id'); |
| 36 | } |
| 37 | |
| 38 | public function getId(): int |
| 39 | { |
| 40 | return $this->id; |
| 41 | } |
| 42 | |
| 43 | public function getName(): string |
| 44 | { |
| 45 | return $this->name; |
| 46 | } |
| 47 | |
| 48 | public function getParentId(): int|null |
| 49 | { |
| 50 | return $this->parentId; |
| 51 | } |
| 52 | |
| 53 | public function getUnlockType(): string|null |
| 54 | { |
| 55 | return $this->unlockType; |
| 56 | } |
| 57 | |
| 58 | /** @return array<int> */ |
| 59 | public function getPageIds(): array |
| 60 | { |
| 61 | if ($this->pageIds === null) { |
| 62 | return []; |
| 63 | } |
| 64 | |
| 65 | return $this->pageIds; |
| 66 | } |
| 67 | |
| 68 | public function getNoAccessPageId(): int|null |
| 69 | { |
| 70 | return $this->noAccessPageId; |
| 71 | } |
| 72 | |
| 73 | public function getLoginPageId(): int|null |
| 74 | { |
| 75 | return $this->loginPageId; |
| 76 | } |
| 77 | |
| 78 | public function getAfterLoginPageId(): int|null |
| 79 | { |
| 80 | return $this->afterLoginPageId; |
| 81 | } |
| 82 | |
| 83 | public function isSection(): bool |
| 84 | { |
| 85 | return ($this->parentId === null); |
| 86 | } |
| 87 | |
| 88 | public function toArray(): array |
| 89 | { |
| 90 | return [ |
| 91 | 'id' => $this->id, |
| 92 | 'parent_id' => $this->parentId, |
| 93 | 'name' => $this->name, |
| 94 | 'unlock_type' => $this->unlockType, |
| 95 | 'page_ids' => $this->pageIds, |
| 96 | 'no_access_page_id' => $this->noAccessPageId, |
| 97 | 'login_page_id' => $this->loginPageId, |
| 98 | 'after_login_page_id' => $this->afterLoginPageId, |
| 99 | ]; |
| 100 | } |
| 101 | |
| 102 | } |
| 103 |