diff --git a/src/Blocks/Zaak.php b/src/Blocks/Zaak.php index 3558bb1..79c92a4 100644 --- a/src/Blocks/Zaak.php +++ b/src/Blocks/Zaak.php @@ -61,6 +61,18 @@ protected function render_block( array $attributes, string $block_content, WP_Bl $zaak->setValue( 'supplier', $supplier ); } + /** + * TEST. + */ + $zaak->setValue( + 'verlenging', + array( + 'reden' => 'test', + 'duur' => 'P42D', + ) + ); + $zaak->setValue( 'opschorting', array( 'reden' => 'test' ) ); + return owc_mijn_services_render_view( 'owc-single-zaak', array( diff --git a/src/Macros/ZgwApiMacros.php b/src/Macros/ZgwApiMacros.php index ce0f6d0..c7093d5 100644 --- a/src/Macros/ZgwApiMacros.php +++ b/src/Macros/ZgwApiMacros.php @@ -21,6 +21,7 @@ use Exception; use DateTimeImmutable; +use DateInterval; use OWC\My_Services\Services\LoggerService; use OWC\ZGW\Entities\Enkelvoudiginformatieobject; use OWC\ZGW\Entities\Statustype; @@ -41,7 +42,7 @@ public static function register(): void { Zaak::macro( 'permalink', - function () { + function (): string { $identification = $this->getValue( 'identificatie', '' ); if ('' === $identification) { @@ -60,7 +61,7 @@ function () { Zaak::macro( 'startDate', - function ( string $format = 'j F Y' ) { + function ( string $format = 'j F Y' ): string { $startDate = $this->getValue( 'startdatum', null ); if ( ! $startDate instanceof DateTimeImmutable) { @@ -73,7 +74,7 @@ function ( string $format = 'j F Y' ) { Zaak::macro( 'registerDate', - function ( string $format = 'j F Y' ) { + function ( string $format = 'j F Y' ): string { $register_date = $this->getValue( 'registratiedatum', null ); if ( ! $register_date instanceof DateTimeImmutable) { @@ -86,7 +87,7 @@ function ( string $format = 'j F Y' ) { Zaak::macro( 'endDate', - function ( string $format = 'j F Y' ) { + function ( string $format = 'j F Y' ): string { $end_date = $this->getValue( 'einddatum', null ); if ( ! $end_date instanceof DateTimeImmutable) { @@ -99,7 +100,7 @@ function ( string $format = 'j F Y' ) { Zaak::macro( 'endDatePlanned', - function ( string $format = 'j F Y' ) { + function ( string $format = 'j F Y' ): string { $end_date_planned = $this->getValue( 'einddatumGepland', null ); if ( ! $end_date_planned instanceof DateTimeImmutable) { @@ -112,9 +113,9 @@ function ( string $format = 'j F Y' ) { Enkelvoudiginformatieobject::macro( 'downloadUrl', - function ( string $zaak_identification, string $supplier ) { + function ( string $zaak_identification, string $supplier ): string { if ($this->isClassified() || ! $this->hasFinalStatus()) { - // return ''; // Is disabled for testing purposes. + return ''; } $identification = $this->identification(); @@ -128,7 +129,7 @@ function ( string $zaak_identification, string $supplier ) { Enkelvoudiginformatieobject::macro( 'identification', - function () { + function (): string { $url = $this->getValue( 'url', '' ); if ( ! is_string( $url ) || '' === $url) { @@ -143,7 +144,7 @@ function () { Enkelvoudiginformatieobject::macro( 'sizeFormatted', - function () { + function (): string { $size = $this->getValue( 'bestandsomvang', 0 ); return $size ? ( size_format( $size ) ?: '' ) : ''; @@ -152,7 +153,7 @@ function () { Enkelvoudiginformatieobject::macro( 'formatType', - function () { + function (): string { $mime_type = $this->getValue( 'formaat', '' ); if ( ! is_string( $mime_type ) || 1 > strlen( $mime_type )) { @@ -167,7 +168,7 @@ function () { Enkelvoudiginformatieobject::macro( 'creationDate', - function () { + function (): string { $date = $this->getValue( 'creatiedatum', null ); if ( ! $date instanceof DateTimeImmutable) { @@ -184,7 +185,7 @@ function () { Enkelvoudiginformatieobject::macro( 'formattedMetaData', - function () { + function (): string { $meta = array_filter( array( $this->formatType(), @@ -203,7 +204,7 @@ function () { Statustype::macro( 'volgnummer', - function () { + function (): string { $volgnummer = (string) $this->getValue( 'volgnummer', '' ); return ltrim( $volgnummer, '0' ); @@ -212,9 +213,9 @@ function () { Zaak::macro( 'result', - function () { + function (): string { try { - return $this->getValue( 'resultaat' )?->resultaattype?->getValue( 'toelichting' ); + return $this->getValue( 'resultaat' )?->resultaattype?->getValue( 'toelichting', '' ) ?? ''; } catch (Exception $e) { LoggerService::log_exception( $e, array( 'context' => "Unable to get 'Zaak resultaat'" ) ); @@ -222,5 +223,117 @@ function () { } } ); + + /** + * @since NEXT + */ + Zaak::macro( + 'extensionReason', + function (): string { + try { + return $this->getValue( 'verlenging' )['reden'] ?? ''; + } catch (Exception $e) { + LoggerService::log_exception( $e, array( 'context' => "Unable to get 'Zaak verlenging reden'" ) ); + + return ''; + } + } + ); + + /** + * @since NEXT + */ + Zaak::macro( + 'extensionDuration', + function (): string { + try { + return $this->getValue( 'verlenging' )['duur'] ?? ''; + } catch (Exception $e) { + LoggerService::log_exception( $e, array( 'context' => "Unable to get 'Zaak verlenging duur'" ) ); + + return ''; + } + } + ); + + /** + * @since NEXT + */ + Zaak::macro( + 'extensionDurationFormatted', + function (): string { + try { + $period = $this->extensionDuration(); + + if ('' === $period) { + return ''; + } + + $interval = new DateInterval( $period ); + + $units = array( + 'y' => array( 'jaar', 'jaren' ), + 'm' => array( 'maand', 'maanden' ), + 'd' => array( 'dag', 'dagen' ), + 'h' => array( 'uur', 'uren' ), + 'i' => array( 'minuut', 'minuten' ), + ); + + $parts = array(); + + foreach ( $units as $property => list( $singular, $plural ) ) { + $value = $interval->{$property}; + + if ( $value > 0 ) { + $parts[] = sprintf( + '%d %s', + $value, + 1 === $value ? $singular : $plural + ); + } + } + + return implode( ', ', $parts ); + } catch (Exception $e) { + LoggerService::log_exception( $e, array( 'context' => "Unable to get 'Zaak verlenging duur'" ) ); + + return ''; + } + } + ); + + /** + * @since NEXT + */ + Zaak::macro( + 'extensionFormatted', + function (): string { + $reason = $this->extensionReason(); + + if ('' === $reason) { + return ''; + } + + $duration = $this->extensionDurationFormatted(); + + return '' === $duration ? $reason : sprintf( '%s (%s)', $reason, $duration ); + } + ); + + /** + * @since NEXT + */ + Zaak::macro( + 'suspensionReason', + function (): string { + try { + return $this->getValue( 'opschorting' )['reden'] ?? ''; + } catch (Exception $e) { + LoggerService::log_exception( $e, array( 'context' => "Unable to get 'Zaak opschorting reden'" ) ); + + return ''; + } + } + ); } } diff --git a/src/Views/partials/owc-single-zaak-details.blade.php b/src/Views/partials/owc-single-zaak-details.blade.php index cade9fc..b963234 100644 --- a/src/Views/partials/owc-single-zaak-details.blade.php +++ b/src/Views/partials/owc-single-zaak-details.blade.php @@ -11,6 +11,8 @@ $fields = [ 'Datum aanvraag' => $zaak->registerDate('j F Y'), 'Startdatum' => $zaak->startDate('j F Y'), + 'Verlenging' => $zaak->extensionFormatted(), + 'Opschorting' => $zaak->suspensionReason(), 'Einddatum gepland' => $zaak->endDatePlanned() && empty($zaak->endDate()) ? $zaak->endDatePlanned() : null, 'Einddatum' => $zaak->endDate(), 'Zaaknummer' => $zaak->getValue('identificatie', ''),