diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dce60c7..a27eaa19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - 2021-06-10 ### Added +- Group: [add Group-API](https://github.com/5pm-HDH/churchtools-api/pull/47) ### Changed - Refactoring: [refactor Code, introduce namespace to test-suites, update phpunit-configuration](https://github.com/5pm-HDH/churchtools-api/pull/46) diff --git a/README.md b/README.md index de8ff86c..292d78bd 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ the Requests retrieve. More informations can be found in the documentation. All APIs with examples: * [Person-API](/docs/PersonAPI.md) +* [Group-API](/docs/GroupAPI.md) * [Event-API](/docs/EventAPI.md) * [Song-API](/docs/SongAPI.md) * [Service-API](/docs/ServiceAPI.md) diff --git a/docs/GroupAPI.md b/docs/GroupAPI.md new file mode 100644 index 00000000..ef910864 --- /dev/null +++ b/docs/GroupAPI.md @@ -0,0 +1,82 @@ +# GroupAPI + +```php +use CTApi\Requests\GroupRequest;use CTApi\Requests\PersonRequest; + +/** + * Group-Request + */ + +// Retrieve all groups +$allGroups = GroupRequest::all(); +$allGroups = GroupRequest::orderBy('name')->get(); + +$myGroups = PersonRequest::whoami()?->requestGroups(); + +// Get specific Group +$group = GroupRequest::find(21); // returns "null" if id is invalid +$group = GroupRequest::findOrFail(22); // throws exception if id is invalid + + +/** + * Group-Data + */ +echo "-".$group->getId(); +echo "-".$group->getGuid(); +echo "-".$group->getName(); +print_r($group->getSecurityLevelForGroup()); +print_r($group->getPermissions()); +print_r($group->getInformation()); +print_r($group->getFollowUp()); +print_r($group->getRoles()); + +echo "GroupSettings\n"; +echo "-".$group->getSettings()?->getIsHidden(); +echo "-".$group->getSettings()?->getIsOpenForMembers(); +echo "-".$group->getSettings()?->getAllowSpouseRegistration(); +echo "-".$group->getSettings()?->getAllowChildRegistration(); +echo "-".$group->getSettings()?->getAllowSameEmailRegistration(); +echo "-".$group->getSettings()?->getAutoAccept(); +echo "-".$group->getSettings()?->getAllowWaitinglist(); +echo "-".$group->getSettings()?->getWaitinglistMaxPersons(); +echo "-".$group->getSettings()?->getAutomaticMoveUp(); +echo "-".$group->getSettings()?->getIsPublic(); +print_r($group->getSettings()?->getGroupMeeting()); +echo "-".$group->getSettings()?->getQrCodeCheckin(); +print_r($group->getSettings()?->getNewMember()); + +echo "GroupRoles\n"; +$groupRole = $group->getRoles()[0]; +echo "-".$groupRole->getId(); +echo "-".$groupRole->getGroupTypeId(); +echo "-".$groupRole->getName(); +echo "-".$groupRole->getShorty(); +echo "-".$groupRole->getShortKey(); +echo "-".$groupRole->getToDelete(); +echo "-".$groupRole->getHasRequested(); +echo "-".$groupRole->getIsLeader(); +echo "-".$groupRole->getIsDefault(); +echo "-".$groupRole->getIsHidden(); +echo "-".$groupRole->getGrowPathId(); +echo "-".$groupRole->getGroupTypeRoleId(); +echo "-".$groupRole->getForceTwoFactorAuth(); +echo "-".$groupRole->getIsActive(); +echo "-".$groupRole->getCanReadChat(); +echo "-".$groupRole->getCanWriteChat(); + +echo "GroupMembers"; +$groupMember = $group->requestMembers()[0]; + +echo "-".$groupMember->getId(); +echo "-".$groupMember->getPersonId(); +echo "-".$groupMember->getGroupTypeRoleId(); +echo "-".$groupMember->getMemberStartDate(); +echo "-".$groupMember->getComment(); +echo "-".$groupMember->getMemberEndDate(); +echo "-".$groupMember->getWaitinglistPosition(); +print_r($groupMember->getFields()); + +$personGroupMember = $groupMember->getPerson(); +$personGroupMember = $groupMember->requestPerson(); + +``` \ No newline at end of file diff --git a/src/Models/Group.php b/src/Models/Group.php new file mode 100644 index 00000000..6a04fb28 --- /dev/null +++ b/src/Models/Group.php @@ -0,0 +1,224 @@ +setName($value); + break; + case "domainIdentifier": + $this->setId($value); + break; + default: + $this->{$key} = $value; + } + } + + protected function fillArrayType(string $key, array $data) + { + switch ($key) { + case "roles": + $this->setRoles(GroupRole::createModelsFromArray($data)); + break; + case "settings": + $this->setSettings(GroupSettings::createModelFromData($data)); + break; + default: + $this->{$key} = $data; + } + } + + + public function requestMembers(): ?GroupMemberRequestBuilder + { + if ($this->getId() != null) { + return new GroupMemberRequestBuilder((int)$this->getId()); + } else { + return null; + } + } + + /** + * @return string|null + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param string|null $id + * @return Group + */ + public function setId(?string $id): Group + { + $this->id = $id; + return $this; + } + + /** + * @return string|null + */ + public function getGuid(): ?string + { + return $this->guid; + } + + /** + * @param string|null $guid + * @return Group + */ + public function setGuid(?string $guid): Group + { + $this->guid = $guid; + return $this; + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param string|null $name + * @return Group + */ + public function setName(?string $name): Group + { + $this->name = $name; + return $this; + } + + /** + * @return string|null + */ + public function getSecurityLevelForGroup(): ?string + { + return $this->securityLevelForGroup; + } + + /** + * @param string|null $securityLevelForGroup + * @return Group + */ + public function setSecurityLevelForGroup(?string $securityLevelForGroup): Group + { + $this->securityLevelForGroup = $securityLevelForGroup; + return $this; + } + + /** + * @return array + */ + public function getPermissions(): array + { + return $this->permissions; + } + + /** + * @param array $permissions + * @return Group + */ + public function setPermissions(array $permissions): Group + { + $this->permissions = $permissions; + return $this; + } + + /** + * @return array + */ + public function getInformation(): array + { + return $this->information; + } + + /** + * @param array $information + * @return Group + */ + public function setInformation(array $information): Group + { + $this->information = $information; + return $this; + } + + /** + * @return GroupSettings|null + */ + public function getSettings(): ?GroupSettings + { + return $this->settings; + } + + /** + * @param GroupSettings|null $settings + * @return Group + */ + public function setSettings(?GroupSettings $settings): Group + { + $this->settings = $settings; + return $this; + } + + /** + * @return array + */ + public function getFollowUp(): array + { + return $this->followUp; + } + + /** + * @param array $followUp + * @return Group + */ + public function setFollowUp(array $followUp): Group + { + $this->followUp = $followUp; + return $this; + } + + /** + * @return array + */ + public function getRoles(): array + { + return $this->roles; + } + + /** + * @param array $roles + * @return Group + */ + public function setRoles(array $roles): Group + { + $this->roles = $roles; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/GroupMember.php b/src/Models/GroupMember.php new file mode 100644 index 00000000..e4eadefb --- /dev/null +++ b/src/Models/GroupMember.php @@ -0,0 +1,206 @@ +setPerson(Person::createModelFromData($data)); + break; + default: + $this->{$key} = $data; + } + } + + public function requestPerson(): ?Person + { + if ($this->getPersonId() != null) { + return PersonRequest::find($this->getPersonId()); + } else { + return null; + } + } + + /** + * @return string|null + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param string|null $id + * @return GroupMember + */ + public function setId(?string $id): GroupMember + { + $this->id = $id; + return $this; + } + + /** + * @return string|null + */ + public function getPersonId(): ?string + { + return $this->personId; + } + + /** + * @param string|null $personId + * @return GroupMember + */ + public function setPersonId(?string $personId): GroupMember + { + $this->personId = $personId; + return $this; + } + + /** + * @return Person|null + */ + public function getPerson(): ?Person + { + return $this->person; + } + + /** + * @param Person|null $person + * @return GroupMember + */ + public function setPerson(?Person $person): GroupMember + { + $this->person = $person; + return $this; + } + + /** + * @return string|null + */ + public function getGroupTypeRoleId(): ?string + { + return $this->groupTypeRoleId; + } + + /** + * @param string|null $groupTypeRoleId + * @return GroupMember + */ + public function setGroupTypeRoleId(?string $groupTypeRoleId): GroupMember + { + $this->groupTypeRoleId = $groupTypeRoleId; + return $this; + } + + /** + * @return string|null + */ + public function getMemberStartDate(): ?string + { + return $this->memberStartDate; + } + + /** + * @param string|null $memberStartDate + * @return GroupMember + */ + public function setMemberStartDate(?string $memberStartDate): GroupMember + { + $this->memberStartDate = $memberStartDate; + return $this; + } + + /** + * @return string|null + */ + public function getComment(): ?string + { + return $this->comment; + } + + /** + * @param string|null $comment + * @return GroupMember + */ + public function setComment(?string $comment): GroupMember + { + $this->comment = $comment; + return $this; + } + + /** + * @return string|null + */ + public function getMemberEndDate(): ?string + { + return $this->memberEndDate; + } + + /** + * @param string|null $memberEndDate + * @return GroupMember + */ + public function setMemberEndDate(?string $memberEndDate): GroupMember + { + $this->memberEndDate = $memberEndDate; + return $this; + } + + /** + * @return string|null + */ + public function getWaitinglistPosition(): ?string + { + return $this->waitinglistPosition; + } + + /** + * @param string|null $waitinglistPosition + * @return GroupMember + */ + public function setWaitinglistPosition(?string $waitinglistPosition): GroupMember + { + $this->waitinglistPosition = $waitinglistPosition; + return $this; + } + + /** + * @return array + */ + public function getFields(): array + { + return $this->fields; + } + + /** + * @param array $fields + * @return GroupMember + */ + public function setFields(array $fields): GroupMember + { + $this->fields = $fields; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/GroupRole.php b/src/Models/GroupRole.php new file mode 100644 index 00000000..72742617 --- /dev/null +++ b/src/Models/GroupRole.php @@ -0,0 +1,318 @@ +id; + } + + /** + * @param string|null $id + * @return GroupRole + */ + public function setId(?string $id): GroupRole + { + $this->id = $id; + return $this; + } + + /** + * @return string|null + */ + public function getGroupTypeId(): ?string + { + return $this->groupTypeId; + } + + /** + * @param string|null $groupTypeId + * @return GroupRole + */ + public function setGroupTypeId(?string $groupTypeId): GroupRole + { + $this->groupTypeId = $groupTypeId; + return $this; + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param string|null $name + * @return GroupRole + */ + public function setName(?string $name): GroupRole + { + $this->name = $name; + return $this; + } + + /** + * @return string|null + */ + public function getShorty(): ?string + { + return $this->shorty; + } + + /** + * @param string|null $shorty + * @return GroupRole + */ + public function setShorty(?string $shorty): GroupRole + { + $this->shorty = $shorty; + return $this; + } + + /** + * @return string|null + */ + public function getSortKey(): ?string + { + return $this->sortKey; + } + + /** + * @param string|null $sortKey + * @return GroupRole + */ + public function setSortKey(?string $sortKey): GroupRole + { + $this->sortKey = $sortKey; + return $this; + } + + /** + * @return string|null + */ + public function getToDelete(): ?string + { + return $this->toDelete; + } + + /** + * @param string|null $toDelete + * @return GroupRole + */ + public function setToDelete(?string $toDelete): GroupRole + { + $this->toDelete = $toDelete; + return $this; + } + + /** + * @return string|null + */ + public function getHasRequested(): ?string + { + return $this->hasRequested; + } + + /** + * @param string|null $hasRequested + * @return GroupRole + */ + public function setHasRequested(?string $hasRequested): GroupRole + { + $this->hasRequested = $hasRequested; + return $this; + } + + /** + * @return string|null + */ + public function getIsLeader(): ?string + { + return $this->isLeader; + } + + /** + * @param string|null $isLeader + * @return GroupRole + */ + public function setIsLeader(?string $isLeader): GroupRole + { + $this->isLeader = $isLeader; + return $this; + } + + /** + * @return string|null + */ + public function getIsDefault(): ?string + { + return $this->isDefault; + } + + /** + * @param string|null $isDefault + * @return GroupRole + */ + public function setIsDefault(?string $isDefault): GroupRole + { + $this->isDefault = $isDefault; + return $this; + } + + /** + * @return string|null + */ + public function getIsHidden(): ?string + { + return $this->isHidden; + } + + /** + * @param string|null $isHidden + * @return GroupRole + */ + public function setIsHidden(?string $isHidden): GroupRole + { + $this->isHidden = $isHidden; + return $this; + } + + /** + * @return string|null + */ + public function getGrowPathId(): ?string + { + return $this->growPathId; + } + + /** + * @param string|null $growPathId + * @return GroupRole + */ + public function setGrowPathId(?string $growPathId): GroupRole + { + $this->growPathId = $growPathId; + return $this; + } + + /** + * @return string|null + */ + public function getGroupTypeRoleId(): ?string + { + return $this->groupTypeRoleId; + } + + /** + * @param string|null $groupTypeRoleId + * @return GroupRole + */ + public function setGroupTypeRoleId(?string $groupTypeRoleId): GroupRole + { + $this->groupTypeRoleId = $groupTypeRoleId; + return $this; + } + + /** + * @return string|null + */ + public function getForceTwoFactorAuth(): ?string + { + return $this->forceTwoFactorAuth; + } + + /** + * @param string|null $forceTwoFactorAuth + * @return GroupRole + */ + public function setForceTwoFactorAuth(?string $forceTwoFactorAuth): GroupRole + { + $this->forceTwoFactorAuth = $forceTwoFactorAuth; + return $this; + } + + /** + * @return string|null + */ + public function getIsActive(): ?string + { + return $this->isActive; + } + + /** + * @param string|null $isActive + * @return GroupRole + */ + public function setIsActive(?string $isActive): GroupRole + { + $this->isActive = $isActive; + return $this; + } + + /** + * @return string|null + */ + public function getCanReadChat(): ?string + { + return $this->canReadChat; + } + + /** + * @param string|null $canReadChat + * @return GroupRole + */ + public function setCanReadChat(?string $canReadChat): GroupRole + { + $this->canReadChat = $canReadChat; + return $this; + } + + /** + * @return string|null + */ + public function getCanWriteChat(): ?string + { + return $this->canWriteChat; + } + + /** + * @param string|null $canWriteChat + * @return GroupRole + */ + public function setCanWriteChat(?string $canWriteChat): GroupRole + { + $this->canWriteChat = $canWriteChat; + return $this; + } + +} \ No newline at end of file diff --git a/src/Models/GroupSettings.php b/src/Models/GroupSettings.php new file mode 100644 index 00000000..c5c0a403 --- /dev/null +++ b/src/Models/GroupSettings.php @@ -0,0 +1,279 @@ +isHidden; + } + + /** + * @param string|null $isHidden + * @return GroupSettings + */ + public function setIsHidden(?string $isHidden): GroupSettings + { + $this->isHidden = $isHidden; + return $this; + } + + /** + * @return string|null + */ + public function getIsOpenForMembers(): ?string + { + return $this->isOpenForMembers; + } + + /** + * @param string|null $isOpenForMembers + * @return GroupSettings + */ + public function setIsOpenForMembers(?string $isOpenForMembers): GroupSettings + { + $this->isOpenForMembers = $isOpenForMembers; + return $this; + } + + /** + * @return string|null + */ + public function getAllowSpouseRegistration(): ?string + { + return $this->allowSpouseRegistration; + } + + /** + * @param string|null $allowSpouseRegistration + * @return GroupSettings + */ + public function setAllowSpouseRegistration(?string $allowSpouseRegistration): GroupSettings + { + $this->allowSpouseRegistration = $allowSpouseRegistration; + return $this; + } + + /** + * @return string|null + */ + public function getAllowChildRegistration(): ?string + { + return $this->allowChildRegistration; + } + + /** + * @param string|null $allowChildRegistration + * @return GroupSettings + */ + public function setAllowChildRegistration(?string $allowChildRegistration): GroupSettings + { + $this->allowChildRegistration = $allowChildRegistration; + return $this; + } + + /** + * @return string|null + */ + public function getAllowSameEmailRegistration(): ?string + { + return $this->allowSameEmailRegistration; + } + + /** + * @param string|null $allowSameEmailRegistration + * @return GroupSettings + */ + public function setAllowSameEmailRegistration(?string $allowSameEmailRegistration): GroupSettings + { + $this->allowSameEmailRegistration = $allowSameEmailRegistration; + return $this; + } + + /** + * @return string|null + */ + public function getAllowOtherRegistration(): ?string + { + return $this->allowOtherRegistration; + } + + /** + * @param string|null $allowOtherRegistration + * @return GroupSettings + */ + public function setAllowOtherRegistration(?string $allowOtherRegistration): GroupSettings + { + $this->allowOtherRegistration = $allowOtherRegistration; + return $this; + } + + /** + * @return string|null + */ + public function getAutoAccept(): ?string + { + return $this->autoAccept; + } + + /** + * @param string|null $autoAccept + * @return GroupSettings + */ + public function setAutoAccept(?string $autoAccept): GroupSettings + { + $this->autoAccept = $autoAccept; + return $this; + } + + /** + * @return string|null + */ + public function getAllowWaitinglist(): ?string + { + return $this->allowWaitinglist; + } + + /** + * @param string|null $allowWaitinglist + * @return GroupSettings + */ + public function setAllowWaitinglist(?string $allowWaitinglist): GroupSettings + { + $this->allowWaitinglist = $allowWaitinglist; + return $this; + } + + /** + * @return string|null + */ + public function getWaitinglistMaxPersons(): ?string + { + return $this->waitinglistMaxPersons; + } + + /** + * @param string|null $waitinglistMaxPersons + * @return GroupSettings + */ + public function setWaitinglistMaxPersons(?string $waitinglistMaxPersons): GroupSettings + { + $this->waitinglistMaxPersons = $waitinglistMaxPersons; + return $this; + } + + /** + * @return string|null + */ + public function getAutomaticMoveUp(): ?string + { + return $this->automaticMoveUp; + } + + /** + * @param string|null $automaticMoveUp + * @return GroupSettings + */ + public function setAutomaticMoveUp(?string $automaticMoveUp): GroupSettings + { + $this->automaticMoveUp = $automaticMoveUp; + return $this; + } + + /** + * @return string|null + */ + public function getIsPublic(): ?string + { + return $this->isPublic; + } + + /** + * @param string|null $isPublic + * @return GroupSettings + */ + public function setIsPublic(?string $isPublic): GroupSettings + { + $this->isPublic = $isPublic; + return $this; + } + + /** + * @return array + */ + public function getGroupMeeting(): array + { + return $this->groupMeeting; + } + + /** + * @param array $groupMeeting + * @return GroupSettings + */ + public function setGroupMeeting(array $groupMeeting): GroupSettings + { + $this->groupMeeting = $groupMeeting; + return $this; + } + + /** + * @return string|null + */ + public function getQrCodeCheckin(): ?string + { + return $this->qrCodeCheckin; + } + + /** + * @param string|null $qrCodeCheckin + * @return GroupSettings + */ + public function setQrCodeCheckin(?string $qrCodeCheckin): GroupSettings + { + $this->qrCodeCheckin = $qrCodeCheckin; + return $this; + } + + /** + * @return array + */ + public function getNewMember(): array + { + return $this->newMember; + } + + /** + * @param array $newMember + * @return GroupSettings + */ + public function setNewMember(array $newMember): GroupSettings + { + $this->newMember = $newMember; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/Person.php b/src/Models/Person.php index 98922a9b..e0652861 100644 --- a/src/Models/Person.php +++ b/src/Models/Person.php @@ -7,6 +7,7 @@ use CTApi\Models\Traits\FillWithData; use CTApi\Models\Traits\MetaAttribute; use CTApi\Requests\PersonEventRequestBuilder; +use CTApi\Requests\PersonGroupRequestBuilder; class Person { @@ -38,17 +39,44 @@ class Person protected ?Meta $meta = null; + protected function fillNonArrayType(string $key, $value) + { + switch ($key) { + case "domainIdentifier": + $this->setId($value); + break; + default: + $this->{$key} = $value; + } + } + protected function fillArrayType(string $key, array $data): void { switch ($key) { case "meta": $this->setMeta(Meta::createModelFromData($data)); break; + case "domainAttributes": + $this->processDomainAttributes($data); + break; default: $this->{$key} = $data; } } + private function processDomainAttributes(array $domainAttributes) + { + if (array_key_exists('firstName', $domainAttributes)) { + $this->setFirstName($domainAttributes['firstName']); + } + if (array_key_exists('lastName', $domainAttributes)) { + $this->setLastName($domainAttributes['lastName']); + } + if (array_key_exists('guid', $domainAttributes)) { + $this->setGuid($domainAttributes['guid']); + } + } + public function requestEvents(): ?PersonEventRequestBuilder { if (!is_null($this->getId())) { @@ -57,6 +85,14 @@ public function requestEvents(): ?PersonEventRequestBuilder return null; } + public function requestGroups(): ?PersonGroupRequestBuilder + { + if (!is_null($this->getId())) { + return new PersonGroupRequestBuilder((int)$this->getId()); + } + return null; + } + /** * @return string|null diff --git a/src/Models/PersonGroup.php b/src/Models/PersonGroup.php new file mode 100644 index 00000000..d2d74e6e --- /dev/null +++ b/src/Models/PersonGroup.php @@ -0,0 +1,92 @@ +group = Group::createModelFromData($data); + break; + default: + $this->{$key} = $data; + } + } + + public function requestGroup(): ?Group + { + $id = $this->getGroup()?->getId(); + if ($id != null) { + return GroupRequest::find($id); + } else { + return null; + } + } + + /** + * @return Group|null + */ + public function getGroup(): ?Group + { + return $this->group; + } + + /** + * @param Group|null $group + * @return PersonGroup + */ + public function setGroup(?Group $group): PersonGroup + { + $this->group = $group; + return $this; + } + + /** + * @return int|null + */ + public function getGroupTypeRoleId(): ?int + { + return $this->groupTypeRoleId; + } + + /** + * @param int|null $groupTypeRoleId + * @return PersonGroup + */ + public function setGroupTypeRoleId(?int $groupTypeRoleId): PersonGroup + { + $this->groupTypeRoleId = $groupTypeRoleId; + return $this; + } + + /** + * @return string|null + */ + public function getMemberStartDate(): ?string + { + return $this->memberStartDate; + } + + /** + * @param string|null $memberStartDate + * @return PersonGroup + */ + public function setMemberStartDate(?string $memberStartDate): PersonGroup + { + $this->memberStartDate = $memberStartDate; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/SongArrangement.php b/src/Models/SongArrangement.php index b3218b25..2c7da1ef 100644 --- a/src/Models/SongArrangement.php +++ b/src/Models/SongArrangement.php @@ -11,14 +11,14 @@ class SongArrangement { use FillWithData, MetaAttribute; - protected ?string $id; - protected ?string $name; - protected ?string $isDefault; - protected ?string $keyOfArrangement; - protected ?string $bpm; - protected ?string $beat; - protected ?string $duration; - protected ?string $note; + protected ?string $id = null; + protected ?string $name = null; + protected ?string $isDefault = null; + protected ?string $keyOfArrangement = null; + protected ?string $bpm = null; + protected ?string $beat = null; + protected ?string $duration = null; + protected ?string $note = null; protected array $links = []; protected array $files = []; diff --git a/src/Models/SongCategory.php b/src/Models/SongCategory.php index 1dd5d829..9d0e0a21 100644 --- a/src/Models/SongCategory.php +++ b/src/Models/SongCategory.php @@ -8,11 +8,11 @@ class SongCategory { - protected ?string $id; - protected ?string $name; - protected ?string $nameTranslated; - protected ?string $sortKey; - protected ?string $campusId; + protected ?string $id = null; + protected ?string $name = null; + protected ?string $nameTranslated = null; + protected ?string $sortKey = null; + protected ?string $campusId = null; use FillWithData; diff --git a/src/Requests/GroupMemberRequestBuilder.php b/src/Requests/GroupMemberRequestBuilder.php new file mode 100644 index 00000000..a3600071 --- /dev/null +++ b/src/Requests/GroupMemberRequestBuilder.php @@ -0,0 +1,30 @@ +groupId = $groupId; + } + + public function get(): array + { + $data = $this->collectDataFromPages('/api/groups/' . $this->groupId . '/members'); + $this->orderRawData($data); + + return GroupMember::createModelsFromArray($data); + } + +} \ No newline at end of file diff --git a/src/Requests/GroupRequest.php b/src/Requests/GroupRequest.php new file mode 100644 index 00000000..ef749ba7 --- /dev/null +++ b/src/Requests/GroupRequest.php @@ -0,0 +1,37 @@ +all(); + } + + public static function where(string $key, $value): GroupRequestBuilder + { + return (new GroupRequestBuilder())->where($key, $value); + } + + public static function orderBy(string $key, $orderAscending = true): GroupRequestBuilder + { + return (new GroupRequestBuilder())->orderBy($key, $orderAscending); + } + + public static function findOrFail(int $id): Group + { + return (new GroupRequestBuilder())->findOrFail($id); + } + + public static function find(int $id): ?Group + { + return (new GroupRequestBuilder())->find($id); + } + +} \ No newline at end of file diff --git a/src/Requests/GroupRequestBuilder.php b/src/Requests/GroupRequestBuilder.php new file mode 100644 index 00000000..d1ebf001 --- /dev/null +++ b/src/Requests/GroupRequestBuilder.php @@ -0,0 +1,65 @@ +collectDataFromPages('/api/groups', []); + return Group::createModelsFromArray($data); + } + + public function findOrFail(int $id): Group + { + $group = $this->find($id); + if($group != null){ + return $group; + }else{ + throw new CTModelException("Could not retrieve model!"); + } + } + + public function find(int $id): ?Group + { + $groupData = null; + try{ + $response = CTClient::getClient()->get('/api/groups/'.$id); + $groupData = CTResponseUtil::dataAsArray($response); + } catch(GuzzleException $e){ + // ignore + } + + if(empty($groupData)){ + return null; + } else { + return Group::createModelFromData($groupData); + } + } + + public function get(): array + { + $options = []; + $this->addWhereConditionsToOption($options); + + $data = $this->collectDataFromPages('/api/groups', $options); + + $this->orderRawData($data); + + return Event::createModelsFromArray($data); + } +} \ No newline at end of file diff --git a/src/Requests/PersonGroupRequestBuilder.php b/src/Requests/PersonGroupRequestBuilder.php new file mode 100644 index 00000000..9bd8a44b --- /dev/null +++ b/src/Requests/PersonGroupRequestBuilder.php @@ -0,0 +1,32 @@ +personId = $personId; + } + + public function get(): array + { + $data = $this->collectDataFromPages('/api/persons/' . $this->personId . '/groups'); + $this->orderRawData($data); + + return PersonGroup::createModelsFromArray($data); + } + +} \ No newline at end of file diff --git a/tests/integration/Requests/GroupMemberRequestTest.php b/tests/integration/Requests/GroupMemberRequestTest.php new file mode 100644 index 00000000..0ded5753 --- /dev/null +++ b/tests/integration/Requests/GroupMemberRequestTest.php @@ -0,0 +1,54 @@ +markTestSkipped("Test suite is disabled in testdata.ini"); + } else { + $this->groupId = TestData::getValue("GROUP_ID") ?? ""; + $this->groupName = TestData::getValue("GROUP_NAME") ?? ""; + } + } + + public function testGetGroupMembers() + { + $myGroup = GroupRequest::find((int)$this->groupId); + $this->assertNotNull($myGroup); + $this->assertInstanceOf(Group::class, $myGroup); + + $firstMember = $myGroup->requestMembers()->get()[0]; + + $this->assertNotNull($firstMember->getPerson()); + $this->assertInstanceOf(Person::class, $firstMember->getPerson()); + + $firstPerson = $firstMember->requestPerson(); + $this->assertNotNull($firstPerson); + $this->assertInstanceOf(Person::class, $firstPerson); + } + + public function testEmptyGroupMember() + { + $emptyGroupMember = GroupMember::createModelFromData([]); + + $this->assertNull($emptyGroupMember->getPerson()); + $this->assertNull($emptyGroupMember->requestPerson()); + } + +} \ No newline at end of file diff --git a/tests/integration/Requests/GroupRequestTest.php b/tests/integration/Requests/GroupRequestTest.php new file mode 100644 index 00000000..7a5bbb8b --- /dev/null +++ b/tests/integration/Requests/GroupRequestTest.php @@ -0,0 +1,69 @@ +markTestSkipped("Test suite is disabled in testdata.ini"); + } else { + $this->groupId = TestData::getValue("GROUP_ID") ?? ""; + $this->groupName = TestData::getValue("GROUP_NAME") ?? ""; + } + } + + public function testGetAllGroups() + { + $allGroups = GroupRequest::all(); + + $this->assertIsArray($allGroups); + $foundMyGroup = false; + foreach ($allGroups as $group) { + $this->assertInstanceOf(Group::class, $group); + if ($group->getId() == $this->groupId) { + $foundMyGroup = true; + } + } + $this->assertTrue($foundMyGroup); + } + + public function testGetGroup() + { + $myGroup = GroupRequest::find((int)$this->groupId); + $this->assertNotNull($myGroup); + $this->assertInstanceOf(Group::class, $myGroup); + $this->assertEquals($myGroup->getName(), $this->groupName); + + $this->assertNotNull($myGroup->getRoles()); + $this->assertNotEmpty($myGroup->getRoles()); + + $firstGroupRole = $myGroup->getRoles()[0]; + $this->assertInstanceOf(GroupRole::class, $firstGroupRole); + + $this->assertNotNull($myGroup->getSettings()); + $this->assertInstanceOf(GroupSettings::class, $myGroup->getSettings()); + } + + public function testCreateEmptyGroup() + { + $myGroup = Group::createModelFromData([]); + $this->assertInstanceOf(Group::class, $myGroup); + $this->assertNull($myGroup->getId()); + } + +} \ No newline at end of file diff --git a/tests/integration/Requests/PersonRequestTest.php b/tests/integration/Requests/PersonRequestTest.php index 74b2173d..d1565bf4 100644 --- a/tests/integration/Requests/PersonRequestTest.php +++ b/tests/integration/Requests/PersonRequestTest.php @@ -3,7 +3,9 @@ namespace Tests\Integration\Requests; use CTApi\Models\Event; +use CTApi\Models\Group; use CTApi\Models\Person; +use CTApi\Models\PersonGroup; use CTApi\Requests\AuthRequest; use CTApi\Requests\PersonRequest; use Exception; @@ -88,6 +90,19 @@ public function testRequestEvents() foreach ($events as $event) { $this->assertInstanceOf(Event::class, $event); } + } + + public function testRequestGroups() + { + $person = PersonRequest::whoami(); + + $groups = $person->requestGroups()->get(); + $this->assertIsArray($groups); + foreach ($groups as $group) { + $this->assertInstanceOf(PersonGroup::class, $group); + $this->assertInstanceOf(Group::class, $group->getGroup()); + $this->assertInstanceOf(Group::class, $group->requestGroup()); + } } } diff --git a/tests/integration/testdata.example.ini b/tests/integration/testdata.example.ini index f87c7299..b6939ba0 100644 --- a/tests/integration/testdata.example.ini +++ b/tests/integration/testdata.example.ini @@ -47,4 +47,9 @@ WIKI_CATEGORY_ID = 21 WIKI_CATEGORY_NAME = Tutorials WIKI_PAGE_IDENTIFIER = 289124-ion-209123-ioanwd-29012 WIKI_PAGE_TITLE = How to add a CT-User -WIKI_SEARCH_QUERY = user \ No newline at end of file +WIKI_SEARCH_QUERY = user + +# enable GROUP testsuite with YES and disable with NO +GROUP_SHOULD_TEST = NO +GROUP_ID = 291 +GROUP_NAME = Test Group \ No newline at end of file