Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added model for group type roles #197

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Retrieve, create and delete SongArrangement comments ([PR187](https://github.com/5pm-HDH/churchtools-api/pull/187))
- Get GroupTypes ([PR188](https://github.com/5pm-HDH/churchtools-api/pull/188))
- Get GroupTypeRoles ([PR197](https://github.com/5pm-HDH/churchtools-api/pull/197))
- PHP coding standard ([PR193](https://github.com/5pm-HDH/churchtools-api/pull/193))

### Changed
Expand Down
42 changes: 42 additions & 0 deletions docs/out/GroupAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,46 @@
// Output: 0


```

## Group Roles

```php
use CTApi\Models\Groups\GroupTypeRole\GroupTypeRoleRequest;

$roles = GroupTypeRoleRequest::all();
$role = $roles[0];

var_dump( $role->getId());
// Output: 15

var_dump( $role->getGroupTypeId());
// Output: 2

$groupType = $role->requestGroupType();
var_dump( $role->getGrowPathId());
// Output: null

var_dump( $role->getName());
// Output: "Mitarbeiter"

var_dump( $role->getShorty());
// Output: "MA"

var_dump( $role->getType());
// Output: "participant"

var_dump( $role->getIsDefault());
// Output: true

var_dump( $role->getIsHidden());
// Output: false

var_dump( $role->getIsLeader());
// Output: false

var_dump( $role->getSortKey());
// Output: 0


```
6 changes: 5 additions & 1 deletion docs/src/ressources/GroupAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@

{{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testGetAll }}

{{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testFind }}
{{ \CTApi\Test\Unit\Docs\GroupTypeRequestTest.testFind }}

## Group Roles

{{ \CTApi\Test\Unit\Docs\GroupTypeRoleRequestTest.testGetGroupTypeRoleRequest }}
151 changes: 151 additions & 0 deletions src/Models/Groups/GroupTypeRole/GroupTypeRole.php
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;
}
}
31 changes: 31 additions & 0 deletions src/Models/Groups/GroupTypeRole/GroupTypeRoleRequest.php
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 src/Models/Groups/GroupTypeRole/GroupTypeRoleRequestBuilder.php
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;
}
}
69 changes: 69 additions & 0 deletions tests/Integration/Requests/GroupTypeRoleRequestTest.php
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());
}
}
24 changes: 24 additions & 0 deletions tests/Integration/integration-test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@
}
}
},
"group_type_roles": {
"description": "Get group type roles.",
"result": {
"any_group_type_role": {
"id": 12,
"groupType": {
"id": 1,
"availableForNewPerson": false,
"isLeaderNecessary": true,
"name": "Kleingruppe",
"permissionDepth": 1,
"shorty": "KG",
"sortKey": 0
},
"name": "Organisator",
"shorty": "O",
"type": "participant",
"isDefault": false,
"isHidden": false,
"isLeader": false,
"sortKey": 4
}
}
},
"update_group_member": {
"description": "Add person to group and remove them again.",
"filter": {
Expand Down
Loading
Loading