Skip to content

Commit

Permalink
Merge pull request #177 from 5pm-HDH/feat/176/base-calculated-end-and…
Browse files Browse the repository at this point in the history
…-start-date

feat(appointment): add calculated and base start/end-date #176
  • Loading branch information
DumbergerL authored Nov 3, 2023
2 parents 0a62fa1 + 5b0c1f9 commit 7e45ca4
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Song-Tags ([PR168](https://github.com/5pm-HDH/churchtools-api/pull/168))
- CTSession ([PR170](https://github.com/5pm-HDH/churchtools-api/pull/170))
- CombinedAppointment ([PR174](https://github.com/5pm-HDH/churchtools-api/pull/174))
- Appointment property for calculated and Base StartDate/EndDate ([PR177](https://github.com/5pm-HDH/churchtools-api/pull/177))

### Changed
- Refactor Imports ([PR165](https://github.com/5pm-HDH/churchtools-api/pull/165))
Expand Down
105 changes: 102 additions & 3 deletions docs/out/CalendarAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,16 +37,17 @@
## Load appointments for calendar:

```php
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;

$allCalendars = CalendarRequest::all();
$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());
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/ressources/CalendarAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
134 changes: 105 additions & 29 deletions src/Models/Calendars/Appointment/Appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use CTApi\Models\AbstractModel;
use CTApi\Models\Calendars\Calendar\Calendar;
use CTApi\Models\Common\Domain\Meta;
use CTApi\Traits\Model\FillWithData;
use CTApi\Models\Common\File\File;
use CTApi\Traits\Model\FillWithData;
use CTApi\Utils\CTDateTimeService;

class Appointment extends AbstractModel
Expand All @@ -24,8 +24,14 @@ class Appointment extends AbstractModel
protected ?File $image = null;
protected ?string $link = null;
protected ?bool $isInternal = null;
protected ?string $startDate = null;
protected ?string $endDate = null;

protected ?string $base_startDate = null;
protected ?string $base_endDate = null;

protected ?string $calculated_startDate = null;
protected ?string $calculated_endDate = null;


protected ?string $allDay = null;
protected ?string $repeatId = null;
protected ?string $repeatFrequency = null;
Expand All @@ -37,9 +43,11 @@ protected function fillArrayType(string $key, array $data): void
{
switch ($key) {
case "base":
$this->processStartAndEndDate(true, $data);
$this->fillWithData($data); // inline "base"-array attributes
break;
case "calculated":
$this->processStartAndEndDate(false, $data);
$this->fillWithData($data); // inline "calculated"-array attributes
break;
case "calendar":
Expand All @@ -59,14 +67,56 @@ protected function fillArrayType(string $key, array $data): void
}
}

private function processStartAndEndDate(bool $isBase, array &$data)
{
if ($isBase) {
$this->base_startDate = $data['startDate'] ?? null;
$this->base_endDate = $data['endDate'] ?? null;
} else {
$this->calculated_startDate = $data['startDate'] ?? null;
$this->calculated_endDate = $data['endDate'] ?? null;
}

unset($data['startDate']);
unset($data['endDate']);
}

public function getStartDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->startDate);
return CTDateTimeService::stringToDateTime($this->getStartDate());
}

public function getEndDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->endDate);
return CTDateTimeService::stringToDateTime($this->getEndDate());
}

public function getCalculatedStartDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->getCalculatedStartDate());
}

public function getCalculatedEndDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->getCalculatedEndDate());
}

public function getBaseStartDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->getBaseStartDate());
}

public function getBaseEndDateAsDateTime(): ?\DateTimeImmutable
{
return CTDateTimeService::stringToDateTime($this->getBaseEndDate());
}

public function toData(): array
{
$data = $this->convertPropertiesToData();
$data["startDate"] = $this->getStartDate();
$data["endDate"] = $this->getEndDate();
return $data;
}

/**
Expand Down Expand Up @@ -111,10 +161,10 @@ public function getImage(): ?File
*/
public function setImage(?File $image): Appointment
{
$this->image= $image;
$this->image = $image;
return $this;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -246,35 +296,21 @@ public function setIsInternal(?bool $isInternal): Appointment
*/
public function getStartDate(): ?string
{
return $this->startDate;
}

/**
* @param string|null $startDate
* @return Appointment
*/
public function setStartDate(?string $startDate): Appointment
{
$this->startDate = $startDate;
return $this;
if ($this->calculated_startDate != null) {
return $this->calculated_startDate;
}
return $this->base_startDate;
}

/**
* @return string|null
*/
public function getEndDate(): ?string
{
return $this->endDate;
}

/**
* @param string|null $endDate
* @return Appointment
*/
public function setEndDate(?string $endDate): Appointment
{
$this->endDate = $endDate;
return $this;
if ($this->calculated_endDate != null) {
return $this->calculated_endDate;
}
return $this->base_endDate;
}

/**
Expand Down Expand Up @@ -384,4 +420,44 @@ public function setMeta(?Meta $meta): Appointment
$this->meta = $meta;
return $this;
}

public function getBaseStartDate(): ?string
{
return $this->base_startDate;
}

public function setBaseStartDate(?string $base_startDate): void
{
$this->base_startDate = $base_startDate;
}

public function getBaseEndDate(): ?string
{
return $this->base_endDate;
}

public function setBaseEndDate(?string $base_endDate): void
{
$this->base_endDate = $base_endDate;
}

public function getCalculatedStartDate(): ?string
{
return $this->calculated_startDate;
}

public function setCalculatedStartDate(?string $calculated_startDate): void
{
$this->calculated_startDate = $calculated_startDate;
}

public function getCalculatedEndDate(): ?string
{
return $this->calculated_endDate;
}

public function setCalculatedEndDate(?string $calculated_endDate): void
{
$this->calculated_endDate = $calculated_endDate;
}
}
Loading

0 comments on commit 7e45ca4

Please sign in to comment.