-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from stollr/group_type_roles
Added model for group type roles
- Loading branch information
Showing
10 changed files
with
597 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Groups\GroupTypeRole; | ||
|
||
use CTApi\Models\AbstractModel; | ||
use CTApi\Models\Groups\Group\GroupType; | ||
use CTApi\Models\Groups\Group\GroupTypeRequest; | ||
use CTApi\Traits\Model\FillWithData; | ||
use CTApi\Traits\Model\MetaAttribute; | ||
|
||
class GroupTypeRole extends AbstractModel | ||
{ | ||
use FillWithData; | ||
use MetaAttribute; | ||
|
||
protected ?int $groupTypeId = null; | ||
protected ?int $growPathId = null; | ||
protected ?string $name = null; | ||
protected ?string $nameTranslated = null; | ||
protected ?string $shorty = null; | ||
protected ?string $type = null; | ||
protected ?bool $isDefault = null; | ||
protected ?bool $isHidden = null; | ||
protected ?bool $isLeader = null; | ||
protected ?int $sortKey = null; | ||
|
||
public function setId(?string $id): static | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
public function requestGroupType(): ?GroupType | ||
{ | ||
if($this->groupTypeId != null) { | ||
return GroupTypeRequest::find((int) $this->groupTypeId); | ||
} | ||
return null; | ||
} | ||
|
||
public function getGroupTypeId(): ?int | ||
{ | ||
return $this->groupTypeId; | ||
} | ||
|
||
public function setGroupTypeId(?int $groupTypeId) | ||
{ | ||
$this->groupTypeId = $groupTypeId; | ||
return $this; | ||
} | ||
|
||
public function getGrowPathId(): ?int | ||
{ | ||
return $this->growPathId; | ||
} | ||
|
||
public function setGrowPathId(?int $growPathId) | ||
{ | ||
$this->growPathId = $growPathId; | ||
return $this; | ||
} | ||
|
||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): static | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
public function getNameTranslated(): ?string | ||
{ | ||
return $this->nameTranslated; | ||
} | ||
|
||
public function setNameTranslated(?string $nameTranslated): static | ||
{ | ||
$this->nameTranslated = $nameTranslated; | ||
return $this; | ||
} | ||
|
||
public function getShorty(): ?string | ||
{ | ||
return $this->shorty; | ||
} | ||
|
||
public function setShorty(?string $shorty): static | ||
{ | ||
$this->shorty = $shorty; | ||
return $this; | ||
} | ||
|
||
public function getType(): ?string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function setType(?string $type): static | ||
{ | ||
$this->type = $type; | ||
return $this; | ||
} | ||
|
||
public function getIsDefault(): ?bool | ||
{ | ||
return $this->isDefault; | ||
} | ||
|
||
public function setIsDefault(?bool $isDefault): static | ||
{ | ||
$this->isDefault = $isDefault; | ||
return $this; | ||
} | ||
|
||
public function getIsHidden(): ?bool | ||
{ | ||
return $this->isHidden; | ||
} | ||
|
||
public function setIsHidden(?bool $isHidden): static | ||
{ | ||
$this->isHidden = $isHidden; | ||
return $this; | ||
} | ||
|
||
public function getIsLeader(): ?bool | ||
{ | ||
return $this->isLeader; | ||
} | ||
|
||
public function setIsLeader(?bool $isLeader): static | ||
{ | ||
$this->isLeader = $isLeader; | ||
return $this; | ||
} | ||
|
||
public function getSortKey(): ?int | ||
{ | ||
return $this->sortKey; | ||
} | ||
|
||
public function setSortKey(?int $sortKey): static | ||
{ | ||
$this->sortKey = $sortKey; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Groups\GroupTypeRole; | ||
|
||
class GroupTypeRoleRequest | ||
{ | ||
public static function all(): array | ||
{ | ||
return (new GroupTypeRoleRequestBuilder())->all(); | ||
} | ||
|
||
public static function where(string $key, $value): GroupTypeRoleRequestBuilder | ||
{ | ||
return (new GroupTypeRoleRequestBuilder())->where($key, $value); | ||
} | ||
|
||
public static function orderBy(string $key, $orderAscending = true): GroupTypeRoleRequestBuilder | ||
{ | ||
return (new GroupTypeRoleRequestBuilder())->orderBy($key, $orderAscending); | ||
} | ||
|
||
public static function findOrFail(int $id): GroupTypeRole | ||
{ | ||
return (new GroupTypeRoleRequestBuilder())->findOrFail($id); | ||
} | ||
|
||
public static function find(int $id): ?GroupTypeRole | ||
{ | ||
return (new GroupTypeRoleRequestBuilder())->find($id); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace CTApi\Models\Groups\GroupTypeRole; | ||
|
||
use CTApi\Models\AbstractRequestBuilder; | ||
|
||
class GroupTypeRoleRequestBuilder extends AbstractRequestBuilder | ||
{ | ||
protected function getApiEndpoint(): string | ||
{ | ||
return '/api/group/roles'; | ||
} | ||
|
||
protected function getModelClass(): string | ||
{ | ||
return GroupTypeRole::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace CTApi\Test\Integration\Requests; | ||
|
||
use CTApi\CTLog; | ||
use CTApi\Models\Groups\Group\GroupType; | ||
use CTApi\Models\Groups\GroupTypeRole\GroupTypeRole; | ||
use CTApi\Models\Groups\GroupTypeRole\GroupTypeRoleRequest; | ||
use CTApi\Test\Integration\IntegrationTestData; | ||
use CTApi\Test\Integration\TestCaseAuthenticated; | ||
|
||
class GroupTypeRoleRequestTest extends TestCaseAuthenticated | ||
{ | ||
private int $id; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->id = IntegrationTestData::getResultAsInt("group_type_roles", "any_group_type_role.id"); | ||
} | ||
|
||
public function testGetAll() | ||
{ | ||
CTLog::enableHttpLog(); | ||
$groupTypeRoles = GroupTypeRoleRequest::all(); | ||
|
||
$foundGroupTypeRole = null; | ||
foreach ($groupTypeRoles as $groupTypeRole) { | ||
if ($groupTypeRole->getIdAsInteger() === $this->id) { | ||
$foundGroupTypeRole = $groupTypeRole; | ||
} | ||
} | ||
|
||
$this->assertNotNull($foundGroupTypeRole); | ||
$this->assertGroupTypeRole($foundGroupTypeRole); | ||
} | ||
|
||
public function testGetGroupTypeRole() | ||
{ | ||
$groupTypeRole = GroupTypeRoleRequest::findOrFail($this->id); | ||
$this->assertGroupTypeRole($groupTypeRole); | ||
|
||
$groupType = $groupTypeRole->requestGroupType(); | ||
$this->assertGroupType($groupType); | ||
} | ||
|
||
private function assertGroupTypeRole(GroupTypeRole $groupTypeRole): void | ||
{ | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.id", $groupTypeRole->getGroupTypeId()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.name", $groupTypeRole->getName()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.shorty", $groupTypeRole->getShorty()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.type", $groupTypeRole->getType()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.isDefault", $groupTypeRole->getIsDefault()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.isHidden", $groupTypeRole->getIsHidden()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.isLeader", $groupTypeRole->getIsLeader()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.sortKey", $groupTypeRole->getSortKey()); | ||
} | ||
|
||
private function assertGroupType(GroupType $groupType): void | ||
{ | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.id", $groupType->getId()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.availableForNewPerson", $groupType->getAvailableForNewPerson()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.isLeaderNecessary", $groupType->getIsLeaderNecessary()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.name", $groupType->getName()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.permissionDepth", $groupType->getPermissionDepth()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.shorty", $groupType->getShorty()); | ||
$this->assertEqualsTestData("group_type_roles", "any_group_type_role.groupType.sortKey", $groupType->getSortKey()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.