Skip to content

Commit

Permalink
Practical fixes (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: EncoreBot <[email protected]>
  • Loading branch information
onairmarc and EncoreBot authored Dec 3, 2024
1 parent 0b13752 commit 25eadeb
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 325 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ c90d7383de6e86260b6cc997b3d0af8e64826a11
baa146cd798ade580c6a6f4f2cbf98d5b72cc19f
cbe36f817a31ddbeb1ef59120b2406f6e9d4a689
8bc4a90640e6ca09b522425509a0a147837a83e2
56cf02b78b6c1327e150c1f5f6357cd973371434
fa4b60ada3c0013ece75995fe7d741e5ab3e80b4
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
"autoload": {
"psr-4": {
"EncoreDigitalGroup\\PlanningCenter\\": "src/"
},
"files": [
"src/Support/helpers.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
55 changes: 25 additions & 30 deletions src/Objects/Calendar/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,40 @@ public function tags(array $query = []): ClientResponse
$http = $this->client()
->get($this->hostname() . self::EVENT_ENDPOINT . "/{$this->attributes->eventId}/tags", $query);

if ($this->isUsingSupportedApiVersion()) {
$tags = $http->json("data");
foreach ($tags as $tag) {
$tagRecord = Tag::make($this->clientId, $this->clientSecret);
$tagRecord->mapFromPco($tag);
$this->relationships->tags->add($tagRecord);
}
}

$tagRecord = Tag::make($this->clientId, $this->clientSecret);
$clientResponse = new ClientResponse($http);
$clientResponse->data->add($this);
$tagRecord->mapFromPco($clientResponse);

return $clientResponse;
}

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

if (is_null($pco)) {
if (!is_iterable($records)) {
return;
}

$attributeMap = [
"eventId" => "id",
"approvalStatus" => "approval_status",
"createdAt" => "created_at",
"description" => "description",
"featured" => "featured",
"imageUrl" => "image_url",
"name" => "name",
"percentApproved" => "percent_approved",
"percentRejected" => "percent_rejected",
"registrationUrl" => "registration_url",
"summary" => "summary",
"updatedAt" => "updated_at",
"visibleInChurchCenter" => "visible_in_church_center",
];

AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
foreach ($records as $record) {
$this->attributes->eventId = $record->id;
$attributeMap = [
"approvalStatus" => "approval_status",
"createdAt" => "created_at",
"description" => "description",
"featured" => "featured",
"imageUrl" => "image_url",
"name" => "name",
"percentApproved" => "percent_approved",
"percentRejected" => "percent_rejected",
"registrationUrl" => "registration_url",
"summary" => "summary",
"updatedAt" => "updated_at",
"visibleInChurchCenter" => "visible_in_church_center",
];

AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
$clientResponse->data->add($this);
}
}
}
64 changes: 34 additions & 30 deletions src/Objects/Calendar/EventInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function forEventId(string $eventId): static
{
$this->setupEventRelationship();

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

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

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

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

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

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

if (is_null($pco)) {
if (!is_iterable($records)) {
return;
}

$this->attributes->eventInstanceId = $pco->id;

$attributeMap = [
"allDayEvent" => "all_day_event",
"compactRecurrenceDescription" => "compact_recurrence_description",
"createdAt" => "created_at",
"endsAt" => "ends_at",
"location" => "location",
"recurrence" => "recurrence",
"recurrenceDescription" => "recurrence_description",
"startsAt" => "starts_at",
"updatedAt" => "updated_at",
"churchCenterUrl" => "church_center_url",
"publishedStartAt" => "published_start_at",
"publishedEndsAt" => "published_ends_at",
];

AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "ends_at", "starts_at", "updated_at"]);

$relationshipMap = [
"event" => "event",
];

RelationshipMapper::from($pco, $this->relationships, $relationshipMap);
foreach ($records as $record) {
$this->attributes->eventInstanceId = $record->id;
$attributeMap = [
"allDayEvent" => "all_day_event",
"compactRecurrenceDescription" => "compact_recurrence_description",
"createdAt" => "created_at",
"endsAt" => "ends_at",
"location" => "location",
"recurrence" => "recurrence",
"recurrenceDescription" => "recurrence_description",
"startsAt" => "starts_at",
"updatedAt" => "updated_at",
"churchCenterUrl" => "church_center_url",
"publishedStartAt" => "published_start_at",
"publishedEndsAt" => "published_ends_at",
];

AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "ends_at", "starts_at", "updated_at"]);

$relationshipMap = [
"event" => "event",
];

RelationshipMapper::from($record, $this->relationships, $relationshipMap);
$clientResponse->data->add($this);

}

}

private function setupEventRelationship(): void
Expand Down

This file was deleted.

30 changes: 17 additions & 13 deletions src/Objects/Calendar/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,29 @@ public function all(array $query = []): ClientResponse
}

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

if (is_null($pco)) {
if (!is_iterable($records)) {
return;
}

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

$attributeMap = [
"churchCenterCategory" => "church_center_category",
"color" => "color",
"createdAt" => "created_at",
"name" => "name",
"position" => "position",
"updatedAt" => "updated_at",
];
$attributeMap = [
"churchCenterCategory" => "church_center_category",
"color" => "color",
"createdAt" => "created_at",
"name" => "name",
"position" => "position",
"updatedAt" => "updated_at",
];

AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
$clientResponse->data->add($this);
}

AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
}
}
28 changes: 15 additions & 13 deletions src/Objects/Calendar/TagGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,25 @@ public function tags(array $query = []): ClientResponse
->all($query);
}

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

if (is_null($pco)) {
if (!is_iterable($records)) {
return;
}

$this->attributes->tagGroupId = $pco->id;

$attributeMap = [
"createdAt" => "created_at",
"name" => "name",
"updatedAt" => "updated_at",
"required" => "required",
];

AttributeMapper::from($pco, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
foreach ($records as $record) {
$this->attributes->tagGroupId = $record->id;
$attributeMap = [
"createdAt" => "created_at",
"name" => "name",
"updatedAt" => "updated_at",
"required" => "required",
];

AttributeMapper::from($record, $this->attributes, $attributeMap, ["created_at", "updated_at"]);
$clientResponse->data->add($this);
}
}
}
50 changes: 27 additions & 23 deletions src/Objects/Groups/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,37 @@ public function get(array $query = []): ClientResponse
return $this->processResponse($http);
}

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

if (is_null($pco)) {
if (!is_iterable($records)) {
return;
}

$attributeMap = [
"eventId" => "id",
"attendanceRequestsEnabled" => "attendance_requests_enabled",
"automatedReminderEnabled" => "automated_reminder_enabled",
"canceled" => "canceled",
"canceledAt" => "canceled_at",
"description" => "description",
"endsAt" => "ends_at",
"locationTypePreference" => "location_type_preference",
"multiDay" => "multi_day",
"name" => "name",
"remindersSent" => "reminders_sent",
"remindersSentAt" => "reminders_sent_at",
"repeating" => "repeating",
"startsAt" => "starts_at",
"virtualLocationUrl" => "virtual_location_url",
"visitorsCount" => "visitors_count",
];

AttributeMapper::from($pco, $this->attributes, $attributeMap, ["canceledAt", "endsAt", "remindersSentAt", "startsAt"]);
foreach ($records as $record) {
$this->attributes->eventId = $record->id;
$attributeMap = [
"attendanceRequestsEnabled" => "attendance_requests_enabled",
"automatedReminderEnabled" => "automated_reminder_enabled",
"canceled" => "canceled",
"canceledAt" => "canceled_at",
"description" => "description",
"endsAt" => "ends_at",
"locationTypePreference" => "location_type_preference",
"multiDay" => "multi_day",
"name" => "name",
"remindersSent" => "reminders_sent",
"remindersSentAt" => "reminders_sent_at",
"repeating" => "repeating",
"startsAt" => "starts_at",
"virtualLocationUrl" => "virtual_location_url",
"visitorsCount" => "visitors_count",
];

AttributeMapper::from($record, $this->attributes, $attributeMap, ["canceledAt", "endsAt", "remindersSentAt", "startsAt"]);
$clientResponse->data->add($this);
}

}
}
Loading

0 comments on commit 25eadeb

Please sign in to comment.