Skip to content

Commit

Permalink
Merge pull request #47 from 5pm-HDH/feature/groups
Browse files Browse the repository at this point in the history
Groups
  • Loading branch information
DumbergerL authored Aug 20, 2021
2 parents a1fbdef + b081303 commit 16c8b63
Show file tree
Hide file tree
Showing 19 changed files with 1,560 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
82 changes: 82 additions & 0 deletions docs/GroupAPI.md
Original file line number Diff line number Diff line change
@@ -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();

```
224 changes: 224 additions & 0 deletions src/Models/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<?php


namespace CTApi\Models;


use CTApi\Models\Traits\FillWithData;
use CTApi\Requests\GroupMemberRequestBuilder;

class Group
{
use FillWithData;

protected ?string $id = null;
protected ?string $guid = null;
protected ?string $name = null;
protected ?string $securityLevelForGroup = null;
protected array $permissions = [];
protected array $information = [];
protected ?GroupSettings $settings = null;
protected array $followUp = [];
protected array $roles = [];


protected function fillNonArrayType(string $key, $value)
{
switch ($key) {
case "title":
$this->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;
}
}
Loading

0 comments on commit 16c8b63

Please sign in to comment.