Skip to content

Commit 25eadeb

Browse files
onairmarcEncoreBot
andauthored
Practical fixes (#29)
Co-authored-by: EncoreBot <ghbot@encoredigitalgroup.com>
1 parent 0b13752 commit 25eadeb

22 files changed

+366
-325
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ c90d7383de6e86260b6cc997b3d0af8e64826a11
66
baa146cd798ade580c6a6f4f2cbf98d5b72cc19f
77
cbe36f817a31ddbeb1ef59120b2406f6e9d4a689
88
8bc4a90640e6ca09b522425509a0a147837a83e2
9+
56cf02b78b6c1327e150c1f5f6357cd973371434
10+
fa4b60ada3c0013ece75995fe7d741e5ab3e80b4

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@
4444
"autoload": {
4545
"psr-4": {
4646
"EncoreDigitalGroup\\PlanningCenter\\": "src/"
47-
},
48-
"files": [
49-
"src/Support/helpers.php"
50-
]
47+
}
5148
},
5249
"autoload-dev": {
5350
"psr-4": {

src/Objects/Calendar/Event.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,40 @@ public function tags(array $query = []): ClientResponse
8585
$http = $this->client()
8686
->get($this->hostname() . self::EVENT_ENDPOINT . "/{$this->attributes->eventId}/tags", $query);
8787

88-
if ($this->isUsingSupportedApiVersion()) {
89-
$tags = $http->json("data");
90-
foreach ($tags as $tag) {
91-
$tagRecord = Tag::make($this->clientId, $this->clientSecret);
92-
$tagRecord->mapFromPco($tag);
93-
$this->relationships->tags->add($tagRecord);
94-
}
95-
}
96-
88+
$tagRecord = Tag::make($this->clientId, $this->clientSecret);
9789
$clientResponse = new ClientResponse($http);
98-
$clientResponse->data->add($this);
90+
$tagRecord->mapFromPco($clientResponse);
9991

10092
return $clientResponse;
10193
}
10294

103-
private function mapFromPco(mixed $pco): void
95+
private function mapFromPco(ClientResponse $clientResponse): void
10496
{
105-
$pco = pco_objectify($pco);
97+
$records = objectify($clientResponse->meta->response->json("data"));
10698

107-
if (is_null($pco)) {
99+
if (!is_iterable($records)) {
108100
return;
109101
}
110102

111-
$attributeMap = [
112-
"eventId" => "id",
113-
"approvalStatus" => "approval_status",
114-
"createdAt" => "created_at",
115-
"description" => "description",
116-
"featured" => "featured",
117-
"imageUrl" => "image_url",
118-
"name" => "name",
119-
"percentApproved" => "percent_approved",
120-
"percentRejected" => "percent_rejected",
121-
"registrationUrl" => "registration_url",
122-
"summary" => "summary",
123-
"updatedAt" => "updated_at",
124-
"visibleInChurchCenter" => "visible_in_church_center",
125-
];
126-
127-
AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
103+
foreach ($records as $record) {
104+
$this->attributes->eventId = $record->id;
105+
$attributeMap = [
106+
"approvalStatus" => "approval_status",
107+
"createdAt" => "created_at",
108+
"description" => "description",
109+
"featured" => "featured",
110+
"imageUrl" => "image_url",
111+
"name" => "name",
112+
"percentApproved" => "percent_approved",
113+
"percentRejected" => "percent_rejected",
114+
"registrationUrl" => "registration_url",
115+
"summary" => "summary",
116+
"updatedAt" => "updated_at",
117+
"visibleInChurchCenter" => "visible_in_church_center",
118+
];
119+
120+
AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
121+
$clientResponse->data->add($this);
122+
}
128123
}
129124
}

src/Objects/Calendar/EventInstance.php

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function forEventId(string $eventId): static
4848
{
4949
$this->setupEventRelationship();
5050

51-
if ($this->relationships->event !== null && $this->relationships->event->data !== null) {
51+
if ($this->relationships->event instanceof \EncoreDigitalGroup\PlanningCenter\Objects\SdkObjects\Relationships\BasicRelationship && $this->relationships->event->data instanceof \EncoreDigitalGroup\PlanningCenter\Objects\SdkObjects\Relationships\BasicRelationshipData) {
5252
$this->relationships->event->data->id = $eventId;
5353
}
5454

@@ -59,11 +59,11 @@ public function all(array $query = []): ClientResponse
5959
{
6060
$this->setupEventRelationship();
6161

62-
if ($this->relationships->event === null) {
62+
if (!$this->relationships->event instanceof \EncoreDigitalGroup\PlanningCenter\Objects\SdkObjects\Relationships\BasicRelationship) {
6363
throw new NullException("relationships->event");
6464
}
6565

66-
if ($this->relationships->event->data === null) {
66+
if (!$this->relationships->event->data instanceof \EncoreDigitalGroup\PlanningCenter\Objects\SdkObjects\Relationships\BasicRelationshipData) {
6767
throw new NullException("relationships->event->data");
6868
}
6969

@@ -85,38 +85,42 @@ public function get(array $query = []): ClientResponse
8585
return $this->processResponse($http);
8686
}
8787

88-
private function mapFromPco(mixed $pco): void
88+
private function mapFromPco(ClientResponse $clientResponse): void
8989
{
90-
$pco = pco_objectify($pco);
90+
$records = objectify($clientResponse->meta->response->json("data"));
9191

92-
if (is_null($pco)) {
92+
if (!is_iterable($records)) {
9393
return;
9494
}
9595

96-
$this->attributes->eventInstanceId = $pco->id;
97-
98-
$attributeMap = [
99-
"allDayEvent" => "all_day_event",
100-
"compactRecurrenceDescription" => "compact_recurrence_description",
101-
"createdAt" => "created_at",
102-
"endsAt" => "ends_at",
103-
"location" => "location",
104-
"recurrence" => "recurrence",
105-
"recurrenceDescription" => "recurrence_description",
106-
"startsAt" => "starts_at",
107-
"updatedAt" => "updated_at",
108-
"churchCenterUrl" => "church_center_url",
109-
"publishedStartAt" => "published_start_at",
110-
"publishedEndsAt" => "published_ends_at",
111-
];
112-
113-
AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "ends_at", "starts_at", "updated_at"]);
114-
115-
$relationshipMap = [
116-
"event" => "event",
117-
];
118-
119-
RelationshipMapper::from($pco, $this->relationships, $relationshipMap);
96+
foreach ($records as $record) {
97+
$this->attributes->eventInstanceId = $record->id;
98+
$attributeMap = [
99+
"allDayEvent" => "all_day_event",
100+
"compactRecurrenceDescription" => "compact_recurrence_description",
101+
"createdAt" => "created_at",
102+
"endsAt" => "ends_at",
103+
"location" => "location",
104+
"recurrence" => "recurrence",
105+
"recurrenceDescription" => "recurrence_description",
106+
"startsAt" => "starts_at",
107+
"updatedAt" => "updated_at",
108+
"churchCenterUrl" => "church_center_url",
109+
"publishedStartAt" => "published_start_at",
110+
"publishedEndsAt" => "published_ends_at",
111+
];
112+
113+
AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "ends_at", "starts_at", "updated_at"]);
114+
115+
$relationshipMap = [
116+
"event" => "event",
117+
];
118+
119+
RelationshipMapper::from($record, $this->relationships, $relationshipMap);
120+
$clientResponse->data->add($this);
121+
122+
}
123+
120124
}
121125

122126
private function setupEventRelationship(): void

src/Objects/Calendar/Exceptions/NoCalendarEventInstancesException.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Objects/Calendar/Tag.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,29 @@ public function all(array $query = []): ClientResponse
4444
}
4545

4646
/** @internal */
47-
public function mapFromPco(mixed $pco): void
47+
public function mapFromPco(ClientResponse $clientResponse): void
4848
{
49-
$pco = pco_objectify($pco);
49+
$records = objectify($clientResponse->meta->response->json("data"));
5050

51-
if (is_null($pco)) {
51+
if (!is_iterable($records)) {
5252
return;
5353
}
5454

55-
$this->attributes->tagId = $pco->id;
55+
foreach ($records as $record) {
56+
$this->attributes->tagId = $record->id;
5657

57-
$attributeMap = [
58-
"churchCenterCategory" => "church_center_category",
59-
"color" => "color",
60-
"createdAt" => "created_at",
61-
"name" => "name",
62-
"position" => "position",
63-
"updatedAt" => "updated_at",
64-
];
58+
$attributeMap = [
59+
"churchCenterCategory" => "church_center_category",
60+
"color" => "color",
61+
"createdAt" => "created_at",
62+
"name" => "name",
63+
"position" => "position",
64+
"updatedAt" => "updated_at",
65+
];
66+
67+
AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
68+
$clientResponse->data->add($this);
69+
}
6570

66-
AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
6771
}
6872
}

src/Objects/Calendar/TagGroup.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,25 @@ public function tags(array $query = []): ClientResponse
5151
->all($query);
5252
}
5353

54-
private function mapFromPco(mixed $pco): void
54+
private function mapFromPco(ClientResponse $clientResponse): void
5555
{
56-
$pco = pco_objectify($pco);
56+
$records = objectify($clientResponse->meta->response->json("data"));
5757

58-
if (is_null($pco)) {
58+
if (!is_iterable($records)) {
5959
return;
6060
}
6161

62-
$this->attributes->tagGroupId = $pco->id;
63-
64-
$attributeMap = [
65-
"createdAt" => "created_at",
66-
"name" => "name",
67-
"updatedAt" => "updated_at",
68-
"required" => "required",
69-
];
70-
71-
AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
62+
foreach ($records as $record) {
63+
$this->attributes->tagGroupId = $record->id;
64+
$attributeMap = [
65+
"createdAt" => "created_at",
66+
"name" => "name",
67+
"updatedAt" => "updated_at",
68+
"required" => "required",
69+
];
70+
71+
AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
72+
$clientResponse->data->add($this);
73+
}
7274
}
7375
}

src/Objects/Groups/Event.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,37 @@ public function get(array $query = []): ClientResponse
6161
return $this->processResponse($http);
6262
}
6363

64-
private function mapFromPco(mixed $pco): void
64+
private function mapFromPco(ClientResponse $clientResponse): void
6565
{
66-
$pco = pco_objectify($pco);
66+
$records = objectify($clientResponse->meta->response->json("data"));
6767

68-
if (is_null($pco)) {
68+
if (!is_iterable($records)) {
6969
return;
7070
}
7171

72-
$attributeMap = [
73-
"eventId" => "id",
74-
"attendanceRequestsEnabled" => "attendance_requests_enabled",
75-
"automatedReminderEnabled" => "automated_reminder_enabled",
76-
"canceled" => "canceled",
77-
"canceledAt" => "canceled_at",
78-
"description" => "description",
79-
"endsAt" => "ends_at",
80-
"locationTypePreference" => "location_type_preference",
81-
"multiDay" => "multi_day",
82-
"name" => "name",
83-
"remindersSent" => "reminders_sent",
84-
"remindersSentAt" => "reminders_sent_at",
85-
"repeating" => "repeating",
86-
"startsAt" => "starts_at",
87-
"virtualLocationUrl" => "virtual_location_url",
88-
"visitorsCount" => "visitors_count",
89-
];
90-
91-
AttributeMapper::from($pco, $this->attributes, $attributeMap, ["canceledAt", "endsAt", "remindersSentAt", "startsAt"]);
72+
foreach ($records as $record) {
73+
$this->attributes->eventId = $record->id;
74+
$attributeMap = [
75+
"attendanceRequestsEnabled" => "attendance_requests_enabled",
76+
"automatedReminderEnabled" => "automated_reminder_enabled",
77+
"canceled" => "canceled",
78+
"canceledAt" => "canceled_at",
79+
"description" => "description",
80+
"endsAt" => "ends_at",
81+
"locationTypePreference" => "location_type_preference",
82+
"multiDay" => "multi_day",
83+
"name" => "name",
84+
"remindersSent" => "reminders_sent",
85+
"remindersSentAt" => "reminders_sent_at",
86+
"repeating" => "repeating",
87+
"startsAt" => "starts_at",
88+
"virtualLocationUrl" => "virtual_location_url",
89+
"visitorsCount" => "visitors_count",
90+
];
91+
92+
AttributeMapper::from($record, $this->attributes, $attributeMap, ["canceledAt", "endsAt", "remindersSentAt", "startsAt"]);
93+
$clientResponse->data->add($this);
94+
}
95+
9296
}
9397
}

0 commit comments

Comments
 (0)