diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index a124cba..a5fe8c4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -6,3 +6,5 @@ c90d7383de6e86260b6cc997b3d0af8e64826a11 baa146cd798ade580c6a6f4f2cbf98d5b72cc19f cbe36f817a31ddbeb1ef59120b2406f6e9d4a689 8bc4a90640e6ca09b522425509a0a147837a83e2 +56cf02b78b6c1327e150c1f5f6357cd973371434 +fa4b60ada3c0013ece75995fe7d741e5ab3e80b4 diff --git a/composer.json b/composer.json index a5ad607..e89c3d1 100644 --- a/composer.json +++ b/composer.json @@ -44,10 +44,7 @@ "autoload": { "psr-4": { "EncoreDigitalGroup\\PlanningCenter\\": "src/" - }, - "files": [ - "src/Support/helpers.php" - ] + } }, "autoload-dev": { "psr-4": { diff --git a/src/Objects/Calendar/Event.php b/src/Objects/Calendar/Event.php index 956a8d1..96153a6 100644 --- a/src/Objects/Calendar/Event.php +++ b/src/Objects/Calendar/Event.php @@ -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); + } } } diff --git a/src/Objects/Calendar/EventInstance.php b/src/Objects/Calendar/EventInstance.php index 18d8fad..df09c47 100644 --- a/src/Objects/Calendar/EventInstance.php +++ b/src/Objects/Calendar/EventInstance.php @@ -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; } @@ -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"); } @@ -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 diff --git a/src/Objects/Calendar/Exceptions/NoCalendarEventInstancesException.php b/src/Objects/Calendar/Exceptions/NoCalendarEventInstancesException.php deleted file mode 100644 index 4e54929..0000000 --- a/src/Objects/Calendar/Exceptions/NoCalendarEventInstancesException.php +++ /dev/null @@ -1,17 +0,0 @@ -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"]); } } diff --git a/src/Objects/Calendar/TagGroup.php b/src/Objects/Calendar/TagGroup.php index a108162..a3a7da6 100644 --- a/src/Objects/Calendar/TagGroup.php +++ b/src/Objects/Calendar/TagGroup.php @@ -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); + } } } diff --git a/src/Objects/Groups/Event.php b/src/Objects/Groups/Event.php index 3a2d0cb..baf1729 100644 --- a/src/Objects/Groups/Event.php +++ b/src/Objects/Groups/Event.php @@ -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); + } + } } diff --git a/src/Objects/Groups/Group.php b/src/Objects/Groups/Group.php index 5b7d42c..89162f3 100644 --- a/src/Objects/Groups/Group.php +++ b/src/Objects/Groups/Group.php @@ -104,38 +104,40 @@ public function tags(array $query = []): ClientResponse ->groups($query); } - protected function mapFromPco(mixed $pco): void + protected 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 = [ - "archivedAt" => "archived_at", - "contactEmail" => "contact_email", - "createdAt" => "created_at", - "description" => "description", - "eventVisibility" => "event_visibility", - "locationTypePreference" => "location_type_preference", - "membershipsCount" => "memberships_count", - "name" => "name", - "publicChurchCenterUrl" => "public_church_center_url", - "schedule" => "schedule", - "virtualLocationUrl" => "virtual_location_url", - ]; - - $this->attributes->groupId = $pco->id; - - AttributeMapper::from($pco, $this->attributes, $attributeMap, ["archived_at", "created_at"]); - - $headerImageAttributeMap = [ - "thumbnail" => "thumbnail", - "medium" => "medium", - "original" => "original", - ]; - - AttributeMapper::from($pco->attributes->header_image, $this->attributes->headerImage, $headerImageAttributeMap); + foreach ($records as $record) { + $this->attributes->groupId = $record->id; + $attributeMap = [ + "archivedAt" => "archived_at", + "contactEmail" => "contact_email", + "createdAt" => "created_at", + "description" => "description", + "eventVisibility" => "event_visibility", + "locationTypePreference" => "location_type_preference", + "membershipsCount" => "memberships_count", + "name" => "name", + "publicChurchCenterUrl" => "public_church_center_url", + "schedule" => "schedule", + "virtualLocationUrl" => "virtual_location_url", + ]; + + $headerImageAttributeMap = [ + "thumbnail" => "thumbnail", + "medium" => "medium", + "original" => "original", + ]; + + AttributeMapper::from($record, $this->attributes, $attributeMap, ["archived_at", "created_at"]); + AttributeMapper::from($record->attributes->header_image, $this->attributes->headerImage, $headerImageAttributeMap); + $clientResponse->data->add($this); + } + } } diff --git a/src/Objects/Groups/GroupEnrollment.php b/src/Objects/Groups/GroupEnrollment.php index bd5a433..ba43727 100644 --- a/src/Objects/Groups/GroupEnrollment.php +++ b/src/Objects/Groups/GroupEnrollment.php @@ -47,27 +47,30 @@ public function get(array $query = []): ClientResponse return $this->processResponse($http); } - protected function mapFromPco(mixed $pco): void + protected 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->groupId = $pco->id; + foreach ($records as $record) { + $this->attributes->groupId = $record->id; + $attributeMap = [ + "autoClosed" => "auto_closed", + "autoClosedReason" => "auto_closed_reason", + "dateLimit" => "date_limit", + "dateLimitReached" => "date_limit_reached", + "memberLimit" => "member_limit", + "memberLimitReached" => "member_limit_reached", + "status" => "status", + "strategy" => "strategy", + ]; - $attributeMap = [ - "autoClosed" => "auto_closed", - "autoClosedReason" => "auto_closed_reason", - "dateLimit" => "date_limit", - "dateLimitReached" => "date_limit_reached", - "memberLimit" => "member_limit", - "memberLimitReached" => "member_limit_reached", - "status" => "status", - "strategy" => "strategy", - ]; + AttributeMapper::from($record, $this->attributes, $attributeMap, ["date_limit"]); + $clientResponse->data->add($this); + } - AttributeMapper::from($pco, $this->attributes, $attributeMap, ["date_limit"]); } } \ No newline at end of file diff --git a/src/Objects/Groups/GroupMemberPerson.php b/src/Objects/Groups/GroupMemberPerson.php index ddca873..3b3db19 100644 --- a/src/Objects/Groups/GroupMemberPerson.php +++ b/src/Objects/Groups/GroupMemberPerson.php @@ -48,22 +48,25 @@ public function get(array $query = []): ClientResponse return $this->processResponse($http); } - protected function mapFromPco(array $pco): void + protected 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->personId = $pco->id; + foreach ($records as $record) { + $this->attributes->personId = $record->id; + $attributeMap = [ + "child" => "child", + "firstName" => "first_name", + "lastName" => "last_name", + ]; - $attributeMap = [ - "child" => "child", - "firstName" => "first_name", - "lastName" => "last_name", - ]; + AttributeMapper::from($record, $this->attributes, $attributeMap); + $clientResponse->data->add($this); + } - AttributeMapper::from($pco, $this->attributes, $attributeMap); } } \ No newline at end of file diff --git a/src/Objects/Groups/GroupMembership.php b/src/Objects/Groups/GroupMembership.php index 63b514c..da08616 100644 --- a/src/Objects/Groups/GroupMembership.php +++ b/src/Objects/Groups/GroupMembership.php @@ -52,26 +52,28 @@ public function get(array $query = []): ClientResponse return $this->processResponse($http); } - protected function mapFromPco(array $pco): void + protected 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 = [ - "joinedAt" => "joined_at", - "role" => "role", - ]; + foreach ($records as $record) { + $attributeMap = [ + "joinedAt" => "joined_at", + "role" => "role", + ]; - AttributeMapper::from($pco, $this->attributes, $attributeMap, ["joined_at"]); + $relationshipMap = [ + "group" => "group", + "person" => "person", + ]; - $relationshipMap = [ - "group" => "group", - "person" => "person", - ]; - - RelationshipMapper::from($pco, $this->relationships, $relationshipMap); + AttributeMapper::from($record, $this->attributes, $attributeMap, ["joined_at"]); + RelationshipMapper::from($record, $this->relationships, $relationshipMap); + $clientResponse->data->add($this); + } } } \ No newline at end of file diff --git a/src/Objects/Groups/Tag.php b/src/Objects/Groups/Tag.php index 5d8b37f..bd9cdf5 100644 --- a/src/Objects/Groups/Tag.php +++ b/src/Objects/Groups/Tag.php @@ -54,21 +54,23 @@ public function groups(array $query = []): ClientResponse return $this->processResponse($http); } - protected function mapFromPco(mixed $pco): void + protected 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 = [ + "name" => "name", + "position" => "position", + ]; - $attributeMap = [ - "name" => "name", - "position" => "position", - ]; - - AttributeMapper::from($pco, $this->attributes, $attributeMap); + AttributeMapper::from($record, $this->attributes, $attributeMap); + $clientResponse->data->add($this); + } } } diff --git a/src/Objects/Groups/TagGroup.php b/src/Objects/Groups/TagGroup.php index 60f5cb6..66d4f84 100644 --- a/src/Objects/Groups/TagGroup.php +++ b/src/Objects/Groups/TagGroup.php @@ -53,22 +53,26 @@ public function tags(array $query = []): ClientResponse return $this->processResponse($http); } - protected function mapFromPco(mixed $pco): void + protected 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 = [ - "tagGroupId" => "id", - "displayPublicly" => "display_publicly", - "multipleOptionsEnabled" => "multiple_options_enabled", - "name" => "name", - "position" => "position", - ]; - - AttributeMapper::from($pco, $this->attributes, $attributeMap); + foreach ($records as $record) { + $this->attributes->tagGroupId = $record->id; + $attributeMap = [ + "tagGroupId" => "id", + "displayPublicly" => "display_publicly", + "multipleOptionsEnabled" => "multiple_options_enabled", + "name" => "name", + "position" => "position", + ]; + + AttributeMapper::from($record, $this->attributes, $attributeMap); + $clientResponse->data->add($this); + } } } diff --git a/src/Objects/People/Email.php b/src/Objects/People/Email.php index d513bb8..2313b8d 100644 --- a/src/Objects/People/Email.php +++ b/src/Objects/People/Email.php @@ -58,15 +58,7 @@ public function person(): ClientResponse $http = $this->client() ->get($this->hostname() . Person::PEOPLE_ENDPOINT . "/{$this->attributes->personId}/emails"); - $clientResponse = new ClientResponse($http); - - foreach ($http->json("data") as $email) { - $pcoEmail = Email::make($this->clientId, $this->clientSecret); - $pcoEmail->mapFromPco($email); - $clientResponse->data->push($pcoEmail); - } - - return $clientResponse; + return $this->processResponse($http); } public function update(): ClientResponse @@ -77,21 +69,26 @@ public function update(): 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 = [ - "emailAddressId" => "id", - "address" => "address", - "primary" => "primary", - ]; + foreach ($records as $record) { + $this->attributes->emailAddressId = $record->id; + $attributeMap = [ + "emailAddressId" => "id", + "address" => "address", + "primary" => "primary", + ]; + + AttributeMapper::from($record, $this->attributes, $attributeMap); + $clientResponse->data->add($this); + } - AttributeMapper::from($pco, $this->attributes, $attributeMap); } private function mapToPco(): array diff --git a/src/Objects/People/Person.php b/src/Objects/People/Person.php index ee2c085..168bbaa 100644 --- a/src/Objects/People/Person.php +++ b/src/Objects/People/Person.php @@ -12,7 +12,9 @@ use EncoreDigitalGroup\PlanningCenter\Support\AttributeMapper; use EncoreDigitalGroup\PlanningCenter\Support\PlanningCenterApiVersion; use EncoreDigitalGroup\PlanningCenter\Traits\HasPlanningCenterClient; +use Exception; use Illuminate\Support\Arr; +use TypeError; /** @api */ class Person @@ -44,15 +46,7 @@ public function all(?array $query = null): ClientResponse $http = $this->client() ->get($this->hostname() . self::PEOPLE_ENDPOINT, $query); - $clientResponse = new ClientResponse($http); - - foreach ($http->json("data") as $person) { - $pcoPerson = Person::make($this->clientId, $this->clientSecret); - $pcoPerson->mapFromPco($person); - $clientResponse->data->push($pcoPerson); - } - - return $clientResponse; + return $this->processResponse($http); } public function get(?array $query = null): ClientResponse @@ -87,55 +81,62 @@ public function delete(): ClientResponse return $this->processResponse($http); } - private function mapFromPco(mixed $pco): void + private function mapFromPco(ClientResponse $clientResponse): void { - $pco = pco_objectify($pco); - - if (is_null($pco)) { + try { + $records = objectify($clientResponse->meta->response->json("data")); + } catch (Exception|TypeError) { return; } - $attributeMap = [ - "firstName" => "first_name", - "middleName" => "middle_name", - "lastName" => "last_name", - "birthdate" => "birthdate", - "anniversary" => "anniversary", - "gender" => "gender", - "grade" => "grade", - "child" => "child", - "graduationYear" => "graduation_year", - "siteAdministrator" => "site_administrator", - "accountingAdministrator" => "accounting_administrator", - "peoplePermissions" => "people_permissions", - "membership" => "membership", - "inactivatedAt" => "inactivated_at", - "medicalNotes" => "medical_notes", - "mfaConfigured" => "mfa_configured", - "createdAt" => "created_at", - "updatedAt" => "updated_at", - "avatar" => "avatar", - "name" => "name", - "demographicAvatarUrl" => "demographic_avatar_url", - "directoryStatus" => "directory_status", - "passedBackgroundCheck" => "passed_background_check", - "canCreateForms" => "can_create_forms", - "canEmailLists" => "can_email_lists", - "schoolType" => "school_type", - "status" => "status", - "primaryCampusId" => "primary_campus_id", - "remoteId" => "remote_id", - ]; + if (!is_iterable($records)) { + return; + } - $this->attributes->personId = $pco->id; + foreach ($records as $record) { + $this->attributes->personId = $record->id; + $attributeMap = [ + "firstName" => "first_name", + "middleName" => "middle_name", + "lastName" => "last_name", + "birthdate" => "birthdate", + "anniversary" => "anniversary", + "gender" => "gender", + "grade" => "grade", + "child" => "child", + "graduationYear" => "graduation_year", + "siteAdministrator" => "site_administrator", + "accountingAdministrator" => "accounting_administrator", + "peoplePermissions" => "people_permissions", + "membership" => "membership", + "inactivatedAt" => "inactivated_at", + "medicalNotes" => "medical_notes", + "mfaConfigured" => "mfa_configured", + "createdAt" => "created_at", + "updatedAt" => "updated_at", + "avatar" => "avatar", + "name" => "name", + "demographicAvatarUrl" => "demographic_avatar_url", + "directoryStatus" => "directory_status", + "passedBackgroundCheck" => "passed_background_check", + "canCreateForms" => "can_create_forms", + "canEmailLists" => "can_email_lists", + "schoolType" => "school_type", + "status" => "status", + "primaryCampusId" => "primary_campus_id", + "remoteId" => "remote_id", + ]; + + AttributeMapper::from($record, $this->attributes, $attributeMap, [ + "birthdate", + "anniversary", + "created_at", + "updated_at", + "inactivated_at", + ]); + $clientResponse->data->add($this); + } - AttributeMapper::from($pco, $this->attributes, $attributeMap, [ - "birthdate", - "anniversary", - "created_at", - "updated_at", - "inactivated_at", - ]); } private function mapToPco(): array diff --git a/src/Support/helpers.php b/src/Support/helpers.php deleted file mode 100644 index f794161..0000000 --- a/src/Support/helpers.php +++ /dev/null @@ -1,22 +0,0 @@ -isUsingSupportedApiVersion()) { - $this->mapFromPco($http->json("data")); - if (!is_null($http->json("data"))) { - $clientResponse->data->add($this); - } + $this->mapFromPco($clientResponse); } return $clientResponse; @@ -64,7 +61,7 @@ protected function processResponse(Response $http): ClientResponse protected function isUsingSupportedApiVersion(): bool { return $this->apiVersion == PlanningCenterApiVersion::PEOPLE_DEFAULT - || $this->apiVersion == PlanningCenterApiVersion::GROUPS_DEFAULT - || $this->apiVersion == PlanningCenterApiVersion::CALENDAR_DEFAULT; + || $this->apiVersion == PlanningCenterApiVersion::GROUPS_DEFAULT + || $this->apiVersion == PlanningCenterApiVersion::CALENDAR_DEFAULT; } } diff --git a/tests/Helpers/BaseMock.php b/tests/Helpers/BaseMock.php index 5084502..3607d91 100644 --- a/tests/Helpers/BaseMock.php +++ b/tests/Helpers/BaseMock.php @@ -24,7 +24,9 @@ protected static function useSingleResponse(ObjectType $type): array $method = $type->value; return [ - "data" => static::$method(), + "data" => [ + static::$method(), + ], ]; } diff --git a/tests/Unit/Calendar/EventTests.php b/tests/Unit/Calendar/EventTests.php index 7d3f410..03ea788 100644 --- a/tests/Unit/Calendar/EventTests.php +++ b/tests/Unit/Calendar/EventTests.php @@ -59,11 +59,8 @@ ->forEventId("1") ->tags(); - /** @var Event $calendarEvent */ - $calendarEvent = $response->data->first(); - /** @var Tag $tag */ - $tag = $calendarEvent->relationships->tags->first(); + $tag = $response->data->first(); expect($response)->toBeInstanceOf(ClientResponse::class) ->and($response->data)->toBeInstanceOf(Collection::class) diff --git a/tests/Unit/Groups/GroupMocks.php b/tests/Unit/Groups/GroupMocks.php index 973be52..436b671 100644 --- a/tests/Unit/Groups/GroupMocks.php +++ b/tests/Unit/Groups/GroupMocks.php @@ -6,10 +6,8 @@ namespace Tests\Unit\Groups; -use EncoreDigitalGroup\PlanningCenter\Objects\Calendar\Event; -use EncoreDigitalGroup\PlanningCenter\Objects\Calendar\EventInstance; -use EncoreDigitalGroup\PlanningCenter\Objects\Calendar\TagGroup; use EncoreDigitalGroup\PlanningCenter\Objects\Groups\Group; +use EncoreDigitalGroup\PlanningCenter\Objects\Groups\TagGroup; use EncoreDigitalGroup\PlanningCenter\Traits\HasPlanningCenterClient; use PHPGenesis\Http\HttpClient; use Tests\Helpers\BaseMock; @@ -30,6 +28,8 @@ class GroupMocks extends BaseMock public const string TAG_ID = "1"; public const string TAG_NAME = "Demo Tag"; public const int TAG_POSITION = 1; + public const string TAG_GROUP_ID = "1"; + public const string TAG_GROUP_NAME = "Demo Tag Group"; public const int ENROLLMENT_MEMBER_LIMIT = 1; public const bool ENROLLMENT_MEMBER_LIMIT_REACHED = true; @@ -41,6 +41,7 @@ public static function setup(): void self::useGroupMemberPersonCollection(); self::useGroupTagRelationshipCollection(); self::useEnrollmentCollection(); + self::useTagGroupCollection(); } protected static function useGroupCollection(): void @@ -124,6 +125,18 @@ protected static function useEnrollmentCollection(): void ]); } + protected static function useTagGroupCollection(): void + { + HttpClient::fake([ + self::HOSTNAME . TagGroup::TAG_GROUP_ENDPOINT => function ($request) { + return match ($request->method()) { + "GET" => HttpClient::response(self::useCollectionResponse(ObjectType::TagGroup)), + default => HttpClient::response([], 405), + }; + }, + ]); + } + protected static function group(): array { return [ @@ -254,4 +267,19 @@ protected static function enrollment(): array ], ]; } + + protected static function tagGroup(): array + { + return [ + "type" => "TagGroup", + "id" => self::TAG_GROUP_ID, + "attributes" => [ + "display_publicly" => true, + "multiple_options_enabled" => true, + "name" => self::TAG_GROUP_NAME, + "position" => 1, + ], + "relationships" => [], + ]; + } } \ No newline at end of file diff --git a/tests/Unit/Groups/TagGroupTests.php b/tests/Unit/Groups/TagGroupTests.php new file mode 100644 index 0000000..679da5a --- /dev/null +++ b/tests/Unit/Groups/TagGroupTests.php @@ -0,0 +1,34 @@ +all(); + + /** @var TagGroupAttributes $tagGroupAttributes */ + $tagGroupAttributes = $response->data->first()->attributes; + + expect($response)->toBeInstanceOf(ClientResponse::class) + ->and($response->data)->toBeInstanceOf(Collection::class) + ->and($response->data->count())->toBe(1) + ->and($tagGroupAttributes->tagGroupId)->toBe(GroupMocks::TAG_GROUP_ID) + ->and($tagGroupAttributes->name)->toBe(GroupMocks::TAG_GROUP_NAME); + }); +})->group("groups.tagGroup"); \ No newline at end of file