diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a3bfae..69f947e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [1.3.1] - 2022-02-11 + +### Fixed + +- add TargetGroup, GroupPlace to [Group-Information](https://github.com/5pm-HDH/churchtools-api/pull/64) +- generate Registration-Link in [PublicGroup](https://github.com/5pm-HDH/churchtools-api/pull/64) + ## [1.3.0] - 2022-02-11 ### Added diff --git a/README.md b/README.md index e040cf53..b893764c 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,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) +* [PublicGroup-API](/docs/PublicGroupAPI.md) * [Event-API](/docs/EventAPI.md) * [Song-API](/docs/SongAPI.md) * [Service-API](/docs/ServiceAPI.md) diff --git a/docs/PublicGroupAPI.md b/docs/PublicGroupAPI.md index 20488cb8..bb75bd8a 100644 --- a/docs/PublicGroupAPI.md +++ b/docs/PublicGroupAPI.md @@ -1,9 +1,11 @@ # Public-Group API +Load Data of Group Homepage with Hash-String. This route is public, so no authentication of the CTConfig is necessary. + ```php use \CTApi\Requests\PublicGroupRequest; -$groupHomepage = PublicGroupRequest::get("SOME_HASH_STRING"); +$groupHomepage = PublicGroupRequest::get("wryawBH318GLHasgm27awB0c241aj"); $groupHomepage->getId(); $groupHomepage->getIsEnabled(); @@ -14,12 +16,67 @@ $groupHomepage->getDefaultView(); $groupHomepage->getSortBy(); $groupHomepage->getOrderDirection(); -$groupHomepage->getRandomUrl(); -// RandomUrl = "SOME_HASH_STRING" +$hash = $groupHomepage->getRandomUrl(); +echo ("Hash: ".$hash); +// OUTPUT: Hash: wryawBH318GLHasgm27awB0c241aj $groupHomepage->getMeta(); + +// Array of PublicGroups: $groups = $groupHomepage->getGroups(); -// Array of PublicGroups -// PublicGroup is a subtype of Group -``` \ No newline at end of file +``` + +The PublicGroup-Model is a Subtype of Group. So all methods of Group will be available in +PublicGroup: [GroupAPI](GroupAPI.md) + +Further the PublicGroup-Model contains the following Methods: + +```php +use \CTApi\Requests\PublicGroupRequest; + +$groupHomepage = PublicGroupRequest::get("wryawBH318GLHasgm27awB0c241aj"); +$group = $groupHomepage->getGroups()[0]; + +echo ("Id: ". $group->getId()); +// OUTPUT: Id: 221 +echo ("Headline: ". $group->getSignUpHeadline()); +// OUTPUT: Headline: Teilnahme beantragen +echo ("Max. Teilnehmer: ". $group->getMaxMemberCount()); +// OUTPUT: Max. Teilnehmer: 42 +echo ("Akt. Teilnehmer: ". $group->getCurrentMemberCount()); +// OUTPUT: Akt. Teilnehmer: 30 +echo ("Name: ". $group->getName()); +// OUTPUT: Name: Jugendwoche Kraftberg + +// GroupInformation +echo ("Termin: ".$group->getInformation()?->getMeetingTime()); +// OUTPUT: Termin: Freitag, 01.03. um 16h bis Sonntag 03.03. um 24h +echo ("Kategorie: ".$group->getInformation()?->getGroupCategory()?->getNameTranslated()); +// OUTPUT: Kategorie: Freizeit +echo ("Zielgruppe: ".$group->getInformation()?->getTargetGroup()?->getNameTranslated()); +// OUTPUT: Zielgruppe: Jugendliche +echo ("Beschreibung: ".$group->getInformation()?->getNote()); +// OUTPUT: Beschreibung: Eine spannende Freizeit erwartet dich! +echo ("Bild-Url: ".$group->getInformation()?->getImageUrl()); +// OUTPUT: Bild-Url: https://test.church.tools/images/9281/2928912ioha8921ns891bs9 + +echo ("Location: ".$group->getInformation()?->getGroupPlaces()[0]->getName()); +// OUTPUT: Location: Freizeitheim Rosenberg +echo ("Stadt: ".$group->getInformation()?->getGroupPlaces()[0]->getCity()); +// OUTPUT: Stadt: Heilbronn +echo ("GeoLat: ".$group->getInformation()?->getGroupPlaces()[0]->getGeoLat()); +// OUTPUT: GeoLat: 92.2912 +echo ("GeoLng: ".$group->getInformation()?->getGroupPlaces()[0]->getGeoLng()); +// OUTPUT: GeoLng: 2.291 + +``` + +For More-Informations on the Attributes have a look at the SourceCode: + +- [Group](../src/Models/Group.php) +- [PublicGroup](../src/Models/PublicGroup.php) +- [GroupInformation](../src/Models/GroupInformation.php) +- [TargetGroup](../src/Models/TargetGroup.php) +- [GroupCategory](../src/Models/GroupCategory.php) +- [GroupPlace](../src/Models/GroupPlace.php) diff --git a/docs/src/DocGenerator.php b/docs/src/DocGenerator.php index f0003906..2bbe6fb5 100644 --- a/docs/src/DocGenerator.php +++ b/docs/src/DocGenerator.php @@ -80,6 +80,8 @@ private static function parseResourceToDocName(string $resource): string private static function processResourceContent(string $resource): string { + \CTApi\CTLog::enableConsoleLog(); + \CTApi\CTLog::getLog()->emergency("GenerateDocs of: ".$resource); $content = file_get_contents(self::$RESOURCES_DIR . $resource); $contentParts = explode('```', $content); diff --git a/docs/src/ressources/PublicGroupAPI.md b/docs/src/ressources/PublicGroupAPI.md index 6a096bce..68725687 100644 --- a/docs/src/ressources/PublicGroupAPI.md +++ b/docs/src/ressources/PublicGroupAPI.md @@ -1,9 +1,11 @@ # Public-Group API +Load Data of Group Homepage with Hash-String. This route is public, so no authentication of the CTConfig is necessary. + ```php use \CTApi\Requests\PublicGroupRequest; -$groupHomepage = PublicGroupRequest::get("SOME_HASH_STRING"); +$groupHomepage = PublicGroupRequest::get("wryawBH318GLHasgm27awB0c241aj"); $groupHomepage->getId(); $groupHomepage->getIsEnabled(); @@ -14,11 +16,50 @@ $groupHomepage->getDefaultView(); $groupHomepage->getSortBy(); $groupHomepage->getOrderDirection(); -$groupHomepage->getRandomUrl(); -// RandomUrl = "SOME_HASH_STRING" +$hash = $groupHomepage->getRandomUrl(); +dd("Hash: ".$hash); $groupHomepage->getMeta(); + +// Array of PublicGroups: $groups = $groupHomepage->getGroups(); -// Array of PublicGroups -// PublicGroup is a subtype of Group -``` \ No newline at end of file +``` + +The PublicGroup-Model is a Subtype of Group. So all methods of Group will be available in +PublicGroup: [GroupAPI](GroupAPI.md) + +Further the PublicGroup-Model contains the following Methods: + +```php +use \CTApi\Requests\PublicGroupRequest; + +$groupHomepage = PublicGroupRequest::get("wryawBH318GLHasgm27awB0c241aj"); +$group = $groupHomepage->getGroups()[0]; + +dd("Id: ". $group->getId()); +dd("Headline: ". $group->getSignUpHeadline()); +dd("Max. Teilnehmer: ". $group->getMaxMemberCount()); +dd("Akt. Teilnehmer: ". $group->getCurrentMemberCount()); +dd("Name: ". $group->getName()); + +// GroupInformation +dd("Termin: ".$group->getInformation()?->getMeetingTime()); +dd("Kategorie: ".$group->getInformation()?->getGroupCategory()?->getNameTranslated()); +dd("Zielgruppe: ".$group->getInformation()?->getTargetGroup()?->getNameTranslated()); +dd("Beschreibung: ".$group->getInformation()?->getNote()); +dd("Bild-Url: ".$group->getInformation()?->getImageUrl()); + +dd("Location: ".$group->getInformation()?->getGroupPlaces()[0]->getName()); +dd("Stadt: ".$group->getInformation()?->getGroupPlaces()[0]->getCity()); +dd("GeoLat: ".$group->getInformation()?->getGroupPlaces()[0]->getGeoLat()); +dd("GeoLng: ".$group->getInformation()?->getGroupPlaces()[0]->getGeoLng()); +``` + +For More-Informations on the Attributes have a look at the SourceCode: + +- [Group](../src/Models/Group.php) +- [PublicGroup](../src/Models/PublicGroup.php) +- [GroupInformation](../src/Models/GroupInformation.php) +- [TargetGroup](../src/Models/TargetGroup.php) +- [GroupCategory](../src/Models/GroupCategory.php) +- [GroupPlace](../src/Models/GroupPlace.php) diff --git a/src/Models/GroupCategory.php b/src/Models/GroupCategory.php new file mode 100644 index 00000000..c8f5d7db --- /dev/null +++ b/src/Models/GroupCategory.php @@ -0,0 +1,89 @@ +id; + } + + /** + * @param string|null $id + * @return GroupCategory + */ + public function setId(?string $id): GroupCategory + { + $this->id = $id; + return $this; + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param string|null $name + * @return GroupCategory + */ + public function setName(?string $name): GroupCategory + { + $this->name = $name; + return $this; + } + + /** + * @return string|null + */ + public function getNameTranslated(): ?string + { + return $this->nameTranslated; + } + + /** + * @param string|null $nameTranslated + * @return GroupCategory + */ + public function setNameTranslated(?string $nameTranslated): GroupCategory + { + $this->nameTranslated = $nameTranslated; + return $this; + } + + /** + * @return string|null + */ + public function getSortKey(): ?string + { + return $this->sortKey; + } + + /** + * @param string|null $sortKey + * @return GroupCategory + */ + public function setSortKey(?string $sortKey): GroupCategory + { + $this->sortKey = $sortKey; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/GroupInformation.php b/src/Models/GroupInformation.php index 48b2f681..4ee7d9ac 100644 --- a/src/Models/GroupInformation.php +++ b/src/Models/GroupInformation.php @@ -12,11 +12,29 @@ class GroupInformation protected ?string $meetingTime = null; protected ?array $weekday = []; - protected ?array $groupCategory = []; + protected ?GroupCategory $groupCategory = null; protected ?array $ageGroups = []; - protected ?array $targetGroup = []; + protected ?TargetGroup $targetGroup = null; protected ?string $note = null; protected ?string $imageUrl = null; + protected ?array $groupPlaces = null; + + protected function fillArrayType(string $key, array $data): void + { + switch ($key) { + case "groupCategory": + $this->groupCategory = GroupCategory::createModelFromData($data); + break; + case "targetGroup": + $this->targetGroup = TargetGroup::createModelFromData($data); + break; + case "groupPlaces": + $this->groupPlaces = GroupPlace::createModelsFromArray($data); + break; + default: + $this->{$key} = $data; + } + } /** * @return string|null @@ -57,16 +75,34 @@ public function setWeekday(?array $weekday): GroupInformation /** * @return array|null */ - public function getGroupCategory(): ?array + public function getGroupPlaces(): ?array + { + return $this->groupPlaces; + } + + /** + * @param array|null $groupPlaces + * @return GroupInformation + */ + public function setGroupPlaces(?array $groupPlaces): GroupInformation + { + $this->groupPlaces = $groupPlaces; + return $this; + } + + /** + * @return GroupCategory|null + */ + public function getGroupCategory(): ?GroupCategory { return $this->groupCategory; } /** - * @param array|null $groupCategory + * @param GroupCategory|null $groupCategory * @return GroupInformation */ - public function setGroupCategory(?array $groupCategory): GroupInformation + public function setGroupCategory(?GroupCategory $groupCategory): GroupInformation { $this->groupCategory = $groupCategory; return $this; @@ -91,18 +127,18 @@ public function setAgeGroups(?array $ageGroups): GroupInformation } /** - * @return array|null + * @return TargetGroup|null */ - public function getTargetGroup(): ?array + public function getTargetGroup(): ?TargetGroup { return $this->targetGroup; } /** - * @param array|null $targetGroup + * @param TargetGroup|null $targetGroup * @return GroupInformation */ - public function setTargetGroup(?array $targetGroup): GroupInformation + public function setTargetGroup(?TargetGroup $targetGroup): GroupInformation { $this->targetGroup = $targetGroup; return $this; diff --git a/src/Models/GroupPlace.php b/src/Models/GroupPlace.php new file mode 100644 index 00000000..84e4838c --- /dev/null +++ b/src/Models/GroupPlace.php @@ -0,0 +1,196 @@ +createdPerson = Person::createModelFromData($data); + break; + default: + $this->{$key} = $data; + } + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param string|null $name + * @return GroupPlace + */ + public function setName(?string $name): GroupPlace + { + $this->name = $name; + return $this; + } + + /** + * @return string|null + */ + public function getDistrict(): ?string + { + return $this->district; + } + + /** + * @param string|null $district + * @return GroupPlace + */ + public function setDistrict(?string $district): GroupPlace + { + $this->district = $district; + return $this; + } + + /** + * @return string|null + */ + public function getPostalcode(): ?string + { + return $this->postalcode; + } + + /** + * @param string|null $postalcode + * @return GroupPlace + */ + public function setPostalcode(?string $postalcode): GroupPlace + { + $this->postalcode = $postalcode; + return $this; + } + + /** + * @return string|null + */ + public function getCity(): ?string + { + return $this->city; + } + + /** + * @param string|null $city + * @return GroupPlace + */ + public function setCity(?string $city): GroupPlace + { + $this->city = $city; + return $this; + } + + /** + * @return string|null + */ + public function getMarkerUrl(): ?string + { + return $this->markerUrl; + } + + /** + * @param string|null $markerUrl + * @return GroupPlace + */ + public function setMarkerUrl(?string $markerUrl): GroupPlace + { + $this->markerUrl = $markerUrl; + return $this; + } + + /** + * @return string|null + */ + public function getGeoLat(): ?string + { + return $this->geoLat; + } + + /** + * @param string|null $geoLat + * @return GroupPlace + */ + public function setGeoLat(?string $geoLat): GroupPlace + { + $this->geoLat = $geoLat; + return $this; + } + + /** + * @return string|null + */ + public function getGeoLng(): ?string + { + return $this->geoLng; + } + + /** + * @param string|null $geoLng + * @return GroupPlace + */ + public function setGeoLng(?string $geoLng): GroupPlace + { + $this->geoLng = $geoLng; + return $this; + } + + /** + * @return string|null + */ + public function getCreatedDate(): ?string + { + return $this->createdDate; + } + + /** + * @param string|null $createdDate + * @return GroupPlace + */ + public function setCreatedDate(?string $createdDate): GroupPlace + { + $this->createdDate = $createdDate; + return $this; + } + + /** + * @return Person|null + */ + public function getCreatedPerson(): ?Person + { + return $this->createdPerson; + } + + /** + * @param Person|null $createdPerson + * @return GroupPlace + */ + public function setCreatedPerson(?Person $createdPerson): GroupPlace + { + $this->createdPerson = $createdPerson; + return $this; + } +} \ No newline at end of file diff --git a/src/Models/PublicGroup.php b/src/Models/PublicGroup.php index cbee8edd..feb00123 100644 --- a/src/Models/PublicGroup.php +++ b/src/Models/PublicGroup.php @@ -4,6 +4,7 @@ namespace CTApi\Models; +use CTApi\CTConfig; use CTApi\Models\Traits\FillWithData; class PublicGroup extends Group @@ -31,6 +32,21 @@ protected function fillNonArrayType(string $key, $value): void parent::fillNonArrayType($key, $value); } + public function generateRegistrationLink(string $groupHash): string + { + $url = CTConfig::getApiUrl(); + + if (!is_null($url) && '/' != substr($url, -1)) { + $url .= '/'; + } + + $url .= 'publicgroup/' . $this->getId(); + + $url .= '?hash=' . $groupHash; + + return $url; + } + /** * @return string|null */ diff --git a/src/Models/TargetGroup.php b/src/Models/TargetGroup.php new file mode 100644 index 00000000..7ad60a45 --- /dev/null +++ b/src/Models/TargetGroup.php @@ -0,0 +1,89 @@ +id; + } + + /** + * @param string|null $id + * @return TargetGroup + */ + public function setId(?string $id): TargetGroup + { + $this->id = $id; + return $this; + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param string|null $name + * @return TargetGroup + */ + public function setName(?string $name): TargetGroup + { + $this->name = $name; + return $this; + } + + /** + * @return string|null + */ + public function getNameTranslated(): ?string + { + return $this->nameTranslated; + } + + /** + * @param string|null $nameTranslated + * @return TargetGroup + */ + public function setNameTranslated(?string $nameTranslated): TargetGroup + { + $this->nameTranslated = $nameTranslated; + return $this; + } + + /** + * @return string|null + */ + public function getSortKey(): ?string + { + return $this->sortKey; + } + + /** + * @param string|null $sortKey + * @return TargetGroup + */ + public function setSortKey(?string $sortKey): TargetGroup + { + $this->sortKey = $sortKey; + return $this; + } +} \ No newline at end of file diff --git a/tests/integration/Requests/PublicGroupRequestTest.php b/tests/integration/Requests/PublicGroupRequestTest.php index c01d83d9..4496e8c1 100644 --- a/tests/integration/Requests/PublicGroupRequestTest.php +++ b/tests/integration/Requests/PublicGroupRequestTest.php @@ -4,6 +4,10 @@ namespace Tests\Integration\Requests; +use CTApi\Models\GroupCategory; +use CTApi\Models\GroupInformation; +use CTApi\Models\GroupPlace; +use CTApi\Models\TargetGroup; use CTApi\Requests\PublicGroupRequest; use Tests\Integration\TestCaseAuthenticated; use Tests\Integration\TestData; @@ -37,10 +41,20 @@ public function testGetPublicGroup() } } - print_r($foundGroup); - $this->assertNotNull($foundGroup); $this->assertEquals($this->groupName, $foundGroup->getName()); + + $this->assertNotNull($foundGroup->getInformation()); + $this->assertInstanceOf(GroupInformation::class, $foundGroup->getInformation()); + + $this->assertNotNull($foundGroup->getInformation()->getGroupCategory()); + $this->assertInstanceOf(GroupCategory::class, $foundGroup->getInformation()->getGroupCategory()); + + $this->assertNotNull($foundGroup->getInformation()->getTargetGroup()); + $this->assertInstanceOf(TargetGroup::class, $foundGroup->getInformation()->getTargetGroup()); + + $this->assertNotNull($foundGroup->getInformation()->getGroupPlaces()); + $this->assertIsArray($foundGroup->getInformation()->getGroupPlaces()); } } \ No newline at end of file diff --git a/tests/unit/HttpMock/data/api_grouphomepages_wryawBH318GLHasgm27awB0c241aj.json b/tests/unit/HttpMock/data/api_grouphomepages_wryawBH318GLHasgm27awB0c241aj.json new file mode 100644 index 00000000..0141cf4a --- /dev/null +++ b/tests/unit/HttpMock/data/api_grouphomepages_wryawBH318GLHasgm27awB0c241aj.json @@ -0,0 +1,36 @@ +{ + "data": { + "id": 21, + "randomUrl": "wryawBH318GLHasgm27awB0c241aj", + "groups": [ + { + "id": 221, + "maxMemberCount": 42, + "currentMemberCount": 30, + "signUpHeadline": "Teilnahme beantragen", + "name": "Jugendwoche Kraftberg", + "information": { + "meetingTime": "Freitag, 01.03. um 16h bis Sonntag 03.03. um 24h", + "groupCategory": { + "name": "leisure", + "nameTranslated": "Freizeit" + }, + "targetGroup": { + "name": "youth", + "nameTranslated": "Jugendliche" + }, + "note": "Eine spannende Freizeit erwartet dich!", + "imageUrl": "https://test.church.tools/images/9281/2928912ioha8921ns891bs9", + "groupPlaces": [ + { + "name": "Freizeitheim Rosenberg", + "city": "Heilbronn", + "geoLat": "92.2912", + "geoLng": "2.291" + } + ] + } + } + ] + } +} \ No newline at end of file diff --git a/tests/unit/Models/PublicGroupTest.php b/tests/unit/Models/PublicGroupTest.php new file mode 100644 index 00000000..e2c31cb3 --- /dev/null +++ b/tests/unit/Models/PublicGroupTest.php @@ -0,0 +1,30 @@ +setId("21"); + + $this->assertEquals("https://test.church.tools/publicgroup/21?hash=EXAMPLEHASHCODE", $publicGroup->generateRegistrationLink("EXAMPLEHASHCODE")); + + // WITH SLASH IN THE END OF URL + CTConfig::setApiUrl("https://test.church.tools/"); + + $this->assertEquals("https://test.church.tools/publicgroup/21?hash=EXAMPLEHASHCODE", $publicGroup->generateRegistrationLink("EXAMPLEHASHCODE")); + + } +} \ No newline at end of file