diff --git a/docs/out/CalendarAPI.md b/docs/out/CalendarAPI.md index 33e8a28d..5f3e9fe4 100644 --- a/docs/out/CalendarAPI.md +++ b/docs/out/CalendarAPI.md @@ -3,6 +3,7 @@ ## Load all calendars: ```php + use CTApi\Models\Calendars\Appointment\Appointment; use CTApi\Models\Calendars\Appointment\AppointmentRequest; use CTApi\Models\Calendars\Calendar\CalendarRequest; @@ -36,6 +37,7 @@ ## Load appointments for calendar: ```php + use CTApi\Models\Calendars\Appointment\Appointment; use CTApi\Models\Calendars\Appointment\AppointmentRequest; use CTApi\Models\Calendars\Calendar\CalendarRequest; @@ -43,9 +45,9 @@ $lastCalendar = end($allCalendars); $appointments = $lastCalendar->requestAppointments() - ?->where("from", "2020-01-01") - ?->where("to", "2022-01-01") - ?->get() ?? []; + ?->where("from", "2020-01-01") + ?->where("to", "2022-01-01") + ?->get() ?? []; $lastAppointment = end($appointments); var_dump( $lastAppointment->getId()); @@ -129,6 +131,7 @@ ## Load appointments for multiple calendars: ```php + use CTApi\Models\Calendars\Appointment\Appointment; use CTApi\Models\Calendars\Appointment\AppointmentRequest; use CTApi\Models\Calendars\Calendar\CalendarRequest; @@ -139,6 +142,102 @@ ``` +## Series appointments: + +```php + use CTApi\Models\Calendars\Appointment\Appointment; + use CTApi\Models\Calendars\Appointment\AppointmentRequest; + use CTApi\Models\Calendars\Calendar\CalendarRequest; + + /** + * Load Seminar series: + * Consists of 2 series appointments + * - #1: Friday 03.11.2023 + * - #2: Friday 10.11.2023 + */ + $appointments = $this->loadSeriesAppointments(); + + $firstSeriesAppointment = $appointments[0]; + $secondSeriesAppointment = $appointments[1]; + + /** + * ID PROPERTY: + * For every calculated series appointment the id stays the same as the base appointment: + */ + var_dump( $firstSeriesAppointment->getId()); + // Output: 15 + + var_dump( $firstSeriesAppointment->getId()); + // Output: 15 + + + /** + * START_DATE / END_DATE PROPERTY: + * Shows the start date / end date of the series appointment. + */ + var_dump( $firstSeriesAppointment->getStartDate()); + // Output: "2023-11-03T17:00:00Z" + + var_dump( $firstSeriesAppointment->getEndDate()); + // Output: "2023-11-03T18:30:00Z" + + + var_dump( $secondSeriesAppointment->getStartDate()); + // Output: "2023-11-10T17:00:00Z" + + var_dump( $secondSeriesAppointment->getEndDate()); + // Output: "2023-11-10T18:30:00Z" + + + /** + * BASE START_DATE / END_DATE PROPERTY: + * Refers for every appointment to the base appointment, where the series starts: + */ + var_dump( $firstSeriesAppointment->getBaseStartDate()); + // Output: "2023-11-03T17:00:00Z" + + var_dump( $firstSeriesAppointment->getBaseEndDate()); + // Output: "2023-11-03T18:30:00Z" + + + var_dump( $secondSeriesAppointment->getBaseStartDate()); + // Output: "2023-11-03T17:00:00Z" + + var_dump( $secondSeriesAppointment->getBaseEndDate()); + // Output: "2023-11-03T18:30:00Z" + + + /** + * CALCULATED START_DATE / END_DATE PROPERTY: + * Same as default startDate / endDate property. Contains the calculated date for the specific appointment. + */ + var_dump( $firstSeriesAppointment->getCalculatedStartDate()); + // Output: "2023-11-03T17:00:00Z" + + var_dump( $firstSeriesAppointment->getCalculatedEndDate()); + // Output: "2023-11-03T18:30:00Z" + + + var_dump( $secondSeriesAppointment->getCalculatedStartDate()); + // Output: "2023-11-10T17:00:00Z" + + var_dump( $secondSeriesAppointment->getCalculatedEndDate()); + // Output: "2023-11-10T18:30:00Z" + + + /** + * DATE_TIME: + * All string properties can be casted to date time. + */ + $firstSeriesAppointment->getStartDateAsDateTime(); + $firstSeriesAppointment->getBaseStartDateAsDateTime(); + $firstSeriesAppointment->getCalculatedStartDateAsDateTime(); + $firstSeriesAppointment->getEndDateAsDateTime(); + $firstSeriesAppointment->getBaseEndDateAsDateTime(); + $firstSeriesAppointment->getCalculatedEndDateAsDateTime(); + +``` + ## Load appointment with event and bookings (CombinedAppointment): Load single appointment including the event and bookings for this appointment. diff --git a/docs/src/ressources/CalendarAPI.md b/docs/src/ressources/CalendarAPI.md index 59c1d5ab..ba81bf56 100644 --- a/docs/src/ressources/CalendarAPI.md +++ b/docs/src/ressources/CalendarAPI.md @@ -12,6 +12,10 @@ {{ \CTApi\Test\Unit\Docs\CalendarRequestTest.testGetAppointmentsViaBuilder }} +## Series appointments: + +{{ \CTApi\Test\Unit\Docs\CalendarRequestTest.testGetSeriesAppointments}} + ## Load appointment with event and bookings (CombinedAppointment): Load single appointment including the event and bookings for this appointment. diff --git a/tests/Integration/Requests/CalendarRequestTest.php b/tests/Integration/Requests/CalendarRequestTest.php index b5c05fd7..e260483b 100644 --- a/tests/Integration/Requests/CalendarRequestTest.php +++ b/tests/Integration/Requests/CalendarRequestTest.php @@ -4,6 +4,8 @@ namespace CTApi\Test\Integration\Requests; +use CTApi\CTLog; +use CTApi\Models\Calendars\Appointment\Appointment; use CTApi\Models\Calendars\Appointment\AppointmentRequest; use CTApi\Models\Calendars\Calendar\CalendarRequest; use CTApi\Models\Calendars\CombinedAppointment\CombinedAppointmentRequest; @@ -100,4 +102,39 @@ public function testCombinedAppointmentRequest() $this->assertEqualsTestData("combined_appointment", "any_booking.resource.id", $oneBooking->getResource()?->getId()); $this->assertEqualsTestData("combined_appointment", "any_booking.resource.name", $oneBooking->getResource()?->getName()); } + + public function testSeriesAppointment() + { + $testCase = IntegrationTestData::getTestCase("appointment_series"); + + $calendar_id = $testCase->getFilterAsInt("calendar_id"); + $from = $testCase->getFilter("from"); + $to = $testCase->getFilter("to"); + + $appointments = AppointmentRequest::forCalendar($calendar_id) + ->where("from", $from) + ->where("to", $to)->get(); + + $this->assertTrue(sizeof($appointments) >= 2); + + $firstSeriesAppointment = null; + $first_startDate = $testCase->getResult("first_series_appointment.calculated_start_date"); + $secondSeriesAppointment = null; + $second_startDate = $testCase->getResult("second_series_appointment.calculated_start_date"); + + foreach($appointments as $appointment){ + if($first_startDate === $appointment->getStartDate()){ + $firstSeriesAppointment = $appointment; + } + if($second_startDate === $appointment->getStartDate()){ + $secondSeriesAppointment = $appointment; + } + } + + $this->assertNotNull($firstSeriesAppointment); + $this->assertEquals($testCase->getResult("first_series_appointment.base_start_date"), $firstSeriesAppointment->getBaseStartDate()); + + $this->assertNotNull($secondSeriesAppointment); + $this->assertEquals($testCase->getResult("second_series_appointment.base_start_date"), $secondSeriesAppointment->getBaseStartDate()); + } } \ No newline at end of file diff --git a/tests/Integration/integration-test-data.json b/tests/Integration/integration-test-data.json index 7b3925b5..11a36f03 100644 --- a/tests/Integration/integration-test-data.json +++ b/tests/Integration/integration-test-data.json @@ -391,6 +391,26 @@ } } }, + "appointment_series": { + "description": "Filter series appointment.", + "filter": { + "calendar_id": 2, + "from": "2023-11-02", + "to": "2023-11-11" + }, + "result": { + "first_series_appointment": { + "id": 14, + "base_start_date": "2023-11-03T17:00:00Z", + "calculated_start_date": "2023-11-03T17:00:00Z" + }, + "second_series_appointment": { + "id": 14, + "base_start_date": "2023-11-03T17:00:00Z", + "calculated_start_date": "2023-11-10T17:00:00Z" + } + } + }, "permission_group": { "description": "Load permission for group.", "filter": { diff --git a/tests/Unit/Docs/CalendarRequestTest.php b/tests/Unit/Docs/CalendarRequestTest.php index c9b3cc85..0a04ada3 100644 --- a/tests/Unit/Docs/CalendarRequestTest.php +++ b/tests/Unit/Docs/CalendarRequestTest.php @@ -4,6 +4,7 @@ namespace CTApi\Test\Unit\Docs; +use CTApi\Models\Calendars\Appointment\Appointment; use CTApi\Models\Calendars\Appointment\AppointmentRequest; use CTApi\Models\Calendars\Calendar\CalendarRequest; use CTApi\Test\Unit\TestCaseHttpMocked; @@ -31,9 +32,9 @@ public function testGetApppointments() $lastCalendar = end($allCalendars); $appointments = $lastCalendar->requestAppointments() - ?->where("from", "2020-01-01") - ?->where("to", "2022-01-01") - ?->get() ?? []; + ?->where("from", "2020-01-01") + ?->where("to", "2022-01-01") + ?->get() ?? []; $lastAppointment = end($appointments); $this->assertEquals(848, $lastAppointment->getId()); @@ -78,4 +79,77 @@ public function testGetAppointmentsViaBuilder() ->where("to", "2022-02-01")->get(); } + + public function testGetSeriesAppointments() + { + /** + * Load Seminar series: + * Consists of 2 series appointments + * - #1: Friday 03.11.2023 + * - #2: Friday 10.11.2023 + */ + $appointments = $this->loadSeriesAppointments(); + + $firstSeriesAppointment = $appointments[0]; + $secondSeriesAppointment = $appointments[1]; + + /** + * ID PROPERTY: + * For every calculated series appointment the id stays the same as the base appointment: + */ + $this->assertEquals(15, $firstSeriesAppointment->getId()); + $this->assertEquals(15, $firstSeriesAppointment->getId()); + + /** + * START_DATE / END_DATE PROPERTY: + * Shows the start date / end date of the series appointment. + */ + $this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getStartDate()); + $this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getEndDate()); + + $this->assertEquals("2023-11-10T17:00:00Z", $secondSeriesAppointment->getStartDate()); + $this->assertEquals("2023-11-10T18:30:00Z", $secondSeriesAppointment->getEndDate()); + + /** + * BASE START_DATE / END_DATE PROPERTY: + * Refers for every appointment to the base appointment, where the series starts: + */ + $this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getBaseStartDate()); + $this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getBaseEndDate()); + + $this->assertEquals("2023-11-03T17:00:00Z", $secondSeriesAppointment->getBaseStartDate()); + $this->assertEquals("2023-11-03T18:30:00Z", $secondSeriesAppointment->getBaseEndDate()); + + /** + * CALCULATED START_DATE / END_DATE PROPERTY: + * Same as default startDate / endDate property. Contains the calculated date for the specific appointment. + */ + $this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getCalculatedStartDate()); + $this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getCalculatedEndDate()); + + $this->assertEquals("2023-11-10T17:00:00Z", $secondSeriesAppointment->getCalculatedStartDate()); + $this->assertEquals("2023-11-10T18:30:00Z", $secondSeriesAppointment->getCalculatedEndDate()); + + /** + * DATE_TIME: + * All string properties can be casted to date time. + */ + $firstSeriesAppointment->getStartDateAsDateTime(); + $firstSeriesAppointment->getBaseStartDateAsDateTime(); + $firstSeriesAppointment->getCalculatedStartDateAsDateTime(); + $firstSeriesAppointment->getEndDateAsDateTime(); + $firstSeriesAppointment->getBaseEndDateAsDateTime(); + $firstSeriesAppointment->getCalculatedEndDateAsDateTime(); + } + + /** + * @return Appointment[] + */ + private function loadSeriesAppointments(): array + { + $fileContent = file_get_contents(__DIR__ . '/calendar_request_series_appointments.json'); + $json = json_decode($fileContent, true); + return Appointment::createModelsFromArray($json["data"]); + } + } \ No newline at end of file diff --git a/tests/Unit/Docs/calendar_request_series_appointments.json b/tests/Unit/Docs/calendar_request_series_appointments.json new file mode 100644 index 00000000..4a667641 --- /dev/null +++ b/tests/Unit/Docs/calendar_request_series_appointments.json @@ -0,0 +1,121 @@ +{ + "data": [ + { + "base": { + "id": 15, + "caption": "Seminar series", + "note": "Letters to the first Christian churches", + "address": null, + "version": 0, + "calendar": { + "id": 3, + "name": "Gottesdienst", + "nameTranslated": "Gottesdienst", + "sortKey": 10, + "color": "black", + "isPublic": true, + "isPrivate": false, + "randomUrl": "30a2d4d8ea19c0a52c54ef59d1b76196", + "iCalSourceUrl": null, + "campusId": null, + "eventTemplateId": null, + "meta": { + "modifiedDate": "2023-05-03T11:59:11Z", + "modifiedPid": -1 + } + }, + "information": "", + "image": null, + "link": "", + "isInternal": false, + "startDate": "2023-11-03T17:00:00Z", + "endDate": "2023-11-03T18:30:00Z", + "allDay": false, + "repeatId": 7, + "repeatFrequency": 1, + "repeatUntil": "2023-11-10", + "repeatOption": null, + "additionals": [], + "exceptions": [], + "signup": null, + "meta": { + "createdDate": "2023-11-03T07:27:38Z", + "createdPerson": { + "id": 1 + }, + "modifiedDate": "2023-11-03T07:27:38Z", + "modifiedPerson": { + "id": 1 + } + }, + "onBehalfOfPid": null, + "@deprecated": "additions", + "additions": [] + }, + "calculated": { + "startDate": "2023-11-03T17:00:00Z", + "endDate": "2023-11-03T18:30:00Z" + } + }, + { + "base": { + "id": 15, + "caption": "Seminar series", + "note": "Letters to the first Christian churches", + "address": null, + "version": 0, + "calendar": { + "id": 3, + "name": "Gottesdienst", + "nameTranslated": "Gottesdienst", + "sortKey": 10, + "color": "black", + "isPublic": true, + "isPrivate": false, + "randomUrl": "30a2d4d8ea19c0a52c54ef59d1b76196", + "iCalSourceUrl": null, + "campusId": null, + "eventTemplateId": null, + "meta": { + "modifiedDate": "2023-05-03T11:59:11Z", + "modifiedPid": -1 + } + }, + "information": "", + "image": null, + "link": "", + "isInternal": false, + "startDate": "2023-11-03T17:00:00Z", + "endDate": "2023-11-03T18:30:00Z", + "allDay": false, + "repeatId": 7, + "repeatFrequency": 1, + "repeatUntil": "2023-11-10", + "repeatOption": null, + "additionals": [], + "exceptions": [], + "signup": null, + "meta": { + "createdDate": "2023-11-03T07:27:38Z", + "createdPerson": { + "id": 1 + }, + "modifiedDate": "2023-11-03T07:27:38Z", + "modifiedPerson": { + "id": 1 + } + }, + "onBehalfOfPid": null, + "@deprecated": "additions", + "additions": [] + }, + "calculated": { + "startDate": "2023-11-10T17:00:00Z", + "endDate": "2023-11-10T18:30:00Z" + } + } + ], + "meta": { + "count": 2 + } +} \ No newline at end of file