Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Blocks/Zaak.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
143 changes: 128 additions & 15 deletions src/Macros/ZgwApiMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +42,7 @@ public static function register(): void
{
Zaak::macro(
'permalink',
function () {
function (): string {
$identification = $this->getValue( 'identificatie', '' );

if ('' === $identification) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();

Expand All @@ -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) {
Expand All @@ -143,7 +144,7 @@ function () {

Enkelvoudiginformatieobject::macro(
'sizeFormatted',
function () {
function (): string {
$size = $this->getValue( 'bestandsomvang', 0 );

return $size ? ( size_format( $size ) ?: '' ) : '';
Expand All @@ -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 )) {
Expand All @@ -167,7 +168,7 @@ function () {

Enkelvoudiginformatieobject::macro(
'creationDate',
function () {
function (): string {
$date = $this->getValue( 'creatiedatum', null );

if ( ! $date instanceof DateTimeImmutable) {
Expand All @@ -184,7 +185,7 @@ function () {

Enkelvoudiginformatieobject::macro(
'formattedMetaData',
function () {
function (): string {
$meta = array_filter(
array(
$this->formatType(),
Expand All @@ -203,7 +204,7 @@ function () {

Statustype::macro(
'volgnummer',
function () {
function (): string {
$volgnummer = (string) $this->getValue( 'volgnummer', '' );

return ltrim( $volgnummer, '0' );
Expand All @@ -212,15 +213,127 @@ 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'" ) );

return __( 'Ophalen van het resultaat is mislukt', 'owc-mijn-services' );
}
}
);

/**
* @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 '';
}
}
);
}
}
2 changes: 2 additions & 0 deletions src/Views/partials/owc-single-zaak-details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''),
Expand Down