Skip to content

Commit c29a639

Browse files
authored
[Core] add for{ObjectType}Id Support (#28)
Co-authored-by: onairmarc <onairmarc@users.noreply.github.com>
1 parent cd539e6 commit c29a639

File tree

17 files changed

+156
-46
lines changed

17 files changed

+156
-46
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ de929a45798d68147fec3ab9527979a5e5f0fce1
55
c90d7383de6e86260b6cc997b3d0af8e64826a11
66
baa146cd798ade580c6a6f4f2cbf98d5b72cc19f
77
cbe36f817a31ddbeb1ef59120b2406f6e9d4a689
8+
8bc4a90640e6ca09b522425509a0a147837a83e2

src/Objects/Calendar/EventInstance.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use EncoreDigitalGroup\PlanningCenter\Support\PlanningCenterApiVersion;
1616
use EncoreDigitalGroup\PlanningCenter\Support\RelationshipMapper;
1717
use EncoreDigitalGroup\PlanningCenter\Traits\HasPlanningCenterClient;
18+
use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\NullException;
1819

1920
/** @api */
2021
class EventInstance
@@ -36,10 +37,39 @@ public static function make(string $clientId, string $clientSecret): EventInstan
3637
return $event;
3738
}
3839

40+
public function forEventInstanceId(string $eventInstanceId): static
41+
{
42+
$this->attributes->eventInstanceId = $eventInstanceId;
43+
44+
return $this;
45+
}
46+
47+
public function forEventId(string $eventId): static
48+
{
49+
$this->setupEventRelationship();
50+
51+
if ($this->relationships->event !== null && $this->relationships->event->data !== null) {
52+
$this->relationships->event->data->id = $eventId;
53+
}
54+
55+
return $this;
56+
}
57+
3958
public function all(array $query = []): ClientResponse
4059
{
41-
$this->relationships->event = $this->relationships->event ?? new BasicRelationship;
42-
$this->relationships->event->data = $this->relationships->event->data ?? new BasicRelationshipData;
60+
$this->setupEventRelationship();
61+
62+
if ($this->relationships->event === null) {
63+
throw new NullException("relationships->event");
64+
}
65+
66+
if ($this->relationships->event->data === null) {
67+
throw new NullException("relationships->event->data");
68+
}
69+
70+
if ($this->relationships->event->data->id === null) {
71+
throw new NullException("relationships->event->data->id");
72+
}
4373

4474
$http = $this->client()
4575
->get($this->hostname() . Event::EVENT_ENDPOINT . "/{$this->relationships->event->data->id}/event_instances", $query);
@@ -88,4 +118,10 @@ private function mapFromPco(mixed $pco): void
88118

89119
RelationshipMapper::from($pco, $this->relationships, $relationshipMap);
90120
}
121+
122+
private function setupEventRelationship(): void
123+
{
124+
$this->relationships->event = $this->relationships->event ?? new BasicRelationship;
125+
$this->relationships->event->data = $this->relationships->event->data ?? new BasicRelationshipData;
126+
}
91127
}

src/Objects/Calendar/Tag.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public static function make(string $clientId, string $clientSecret): Tag
2828
return $tagGroup;
2929
}
3030

31-
public function all(array $query = []): ClientResponse
31+
public function forTagGroupId(string $tagGroupId): static
3232
{
33-
$http = $this->client()
34-
->get($this->hostname() . TagGroup::TAG_GROUP_ENDPOINT . "/{$this->tagGroupId}/tags", $query);
33+
$this->tagGroupId = $tagGroupId;
3534

36-
return $this->processResponse($http);
35+
return $this;
3736
}
3837

39-
public function inTagGroup(string $tagGroupId): static
38+
public function all(array $query = []): ClientResponse
4039
{
41-
$this->tagGroupId = $tagGroupId;
40+
$http = $this->client()
41+
->get($this->hostname() . TagGroup::TAG_GROUP_ENDPOINT . "/{$this->tagGroupId}/tags", $query);
4242

43-
return $this;
43+
return $this->processResponse($http);
4444
}
4545

4646
/** @internal */

src/Objects/Calendar/TagGroup.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public static function make(string $clientId, string $clientSecret): TagGroup
2929
return $tagGroup;
3030
}
3131

32+
public function forTagGroupId(string $tagGroupId): static
33+
{
34+
$this->attributes->tagGroupId = $tagGroupId;
35+
36+
return $this;
37+
}
38+
3239
public function all(array $query = []): ClientResponse
3340
{
3441
$http = $this->client()
@@ -40,7 +47,7 @@ public function all(array $query = []): ClientResponse
4047
public function tags(array $query = []): ClientResponse
4148
{
4249
return Tag::make($this->clientId, $this->clientSecret)
43-
->inTagGroup($this->attributes->tagGroupId)
50+
->forTagGroupId($this->attributes->tagGroupId)
4451
->all($query);
4552
}
4653

src/Objects/Groups/Event.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public static function make(string $clientId, string $clientSecret): Event
3030
return $event;
3131
}
3232

33+
public function forEventId(string $eventId): static
34+
{
35+
$this->attributes->eventId = $eventId;
36+
37+
return $this;
38+
}
39+
3340
public function all(array $query = []): ClientResponse
3441
{
3542
$http = $this->client()
@@ -56,7 +63,11 @@ public function get(array $query = []): ClientResponse
5663

5764
private function mapFromPco(mixed $pco): void
5865
{
59-
$pco = objectify($pco);
66+
$pco = pco_objectify($pco);
67+
68+
if (is_null($pco)) {
69+
return;
70+
}
6071

6172
$attributeMap = [
6273
"eventId" => "id",

src/Objects/Groups/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function people(array $query = []): ClientResponse
100100
public function tags(array $query = []): ClientResponse
101101
{
102102
return Tag::make($this->clientId, $this->clientSecret)
103-
->forGroup($this->attributes->groupId)
103+
->forGroupId($this->attributes->groupId)
104104
->groups($query);
105105
}
106106

src/Objects/Groups/GroupEnrollment.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public static function make(string $clientId, string $clientSecret): GroupEnroll
3232
return $group;
3333
}
3434

35+
public function forGroupId(string $groupId): static
36+
{
37+
$this->attributes->groupId = $groupId;
38+
39+
return $this;
40+
}
41+
3542
public function get(array $query = []): ClientResponse
3643
{
3744
$http = $this->client()

src/Objects/Groups/Tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function make(string $clientId, string $clientSecret): Tag
3131
return $tag;
3232
}
3333

34-
public function forGroup(string $groupId): static
34+
public function forGroupId(string $groupId): static
3535
{
3636
$this->groupId = $groupId;
3737

src/Objects/People/Email.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ public static function make(?string $clientId = null, ?string $clientSecret = nu
3131
return $email;
3232
}
3333

34+
public function forEmailAddressId(string $emailAddressId): static
35+
{
36+
$this->attributes->emailAddressId = $emailAddressId;
37+
38+
return $this;
39+
}
40+
41+
public function forPersonId(string $personId): static
42+
{
43+
$this->attributes->personId = $personId;
44+
45+
return $this;
46+
}
47+
3448
public function get(): ClientResponse
3549
{
3650
$http = $this->client()
@@ -39,7 +53,7 @@ public function get(): ClientResponse
3953
return $this->processResponse($http);
4054
}
4155

42-
public function forPerson(): ClientResponse
56+
public function person(): ClientResponse
4357
{
4458
$http = $this->client()
4559
->get($this->hostname() . Person::PEOPLE_ENDPOINT . "/{$this->attributes->personId}/emails");

src/Objects/People/Person.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ private function mapToPco(): array
177177
],
178178
];
179179

180-
unset($person["data"]["attributes"]["id"], $person["data"]["attributes"]["created_at"], $person["data"]["attributes"]["updated_at"], $person["data"]["attributes"]["name"], $person["data"]["attributes"]["demographic_avatar_url"]);
180+
unset(
181+
$person["data"]["attributes"]["id"],
182+
$person["data"]["attributes"]["created_at"],
183+
$person["data"]["attributes"]["updated_at"],
184+
$person["data"]["attributes"]["name"],
185+
$person["data"]["attributes"]["demographic_avatar_url"]
186+
);
181187

182188
return Arr::whereNotNull($person["data"]["attributes"]);
183189
}

0 commit comments

Comments
 (0)