From b78a06babb8c2813f32ed77ded7e8c1bd496df96 Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak Date: Fri, 16 Dec 2022 09:21:27 +0100 Subject: [PATCH 1/3] Repair bug in templte email --- src/Consultations/CommonConsultationVariables.php | 9 ++++++++- src/Webinar/CommonWebinarVariables.php | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Consultations/CommonConsultationVariables.php b/src/Consultations/CommonConsultationVariables.php index 30b61cc..53d00de 100644 --- a/src/Consultations/CommonConsultationVariables.php +++ b/src/Consultations/CommonConsultationVariables.php @@ -2,6 +2,7 @@ namespace EscolaLms\TemplatesEmail\Consultations; +use DateTimeInterface; use EscolaLms\Consultations\Models\ConsultationUserPivot; use EscolaLms\Core\Models\User; use EscolaLms\Templates\Events\EventWrapper; @@ -26,10 +27,16 @@ public static function mockedVariables(?User $user = null): array public static function variablesFromEvent(EventWrapper $event): array { + if ($event->getWebinar()->active_to instanceof DateTimeInterface) { + $proposedTerm = $event->getConsultationTerm()->executed_at; + } else { + $proposedTerm = Carbon::make($event->getConsultationTerm()->executed_at); + } + return array_merge(parent::variablesFromEvent($event), [ self::VAR_USER_NAME => $event->getUser()->name, self::VAR_CONSULTATION_TITLE => $event->getConsultationTerm()->consultation->name, - self::VAR_CONSULTATION_PROPOSED_TERM => Carbon::make($event->getConsultationTerm()->executed_at) + self::VAR_CONSULTATION_PROPOSED_TERM => $proposedTerm ->setTimezone($event->getUser()->current_timezone) ->format('Y-m-d H:i:s'), ]); diff --git a/src/Webinar/CommonWebinarVariables.php b/src/Webinar/CommonWebinarVariables.php index c0d8a52..0970b2b 100644 --- a/src/Webinar/CommonWebinarVariables.php +++ b/src/Webinar/CommonWebinarVariables.php @@ -26,10 +26,16 @@ public static function mockedVariables(?User $user = null): array public static function variablesFromEvent(EventWrapper $event): array { + if ($event->getWebinar()->active_to instanceof DateTimeInterface) { + $proposedTerm = $event->getWebinar()->active_to; + } else { + $proposedTerm = Carbon::make($event->getWebinar()->active_to); + } + return array_merge(parent::variablesFromEvent($event), [ self::VAR_USER_NAME => $event->getUser()->name, self::VAR_WEBINAR_TITLE => $event->getWebinar()->name, - self::VAR_WEBINAR_PROPOSED_TERM => Carbon::make($event->getWebinar()->active_to) + self::VAR_WEBINAR_PROPOSED_TERM => $proposedTerm ->setTimezone($event->getUser()->current_timezone) ->format('Y-m-d H:i:s'), ]); From 8376c1154c19a12a9204fc806dda72caa3ccbd3e Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak Date: Fri, 16 Dec 2022 09:25:13 +0100 Subject: [PATCH 2/3] Add similar fix to consultation variable --- src/Consultations/CommonConsultationVariables.php | 6 ++++-- src/Webinar/CommonWebinarVariables.php | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Consultations/CommonConsultationVariables.php b/src/Consultations/CommonConsultationVariables.php index 53d00de..0b223d9 100644 --- a/src/Consultations/CommonConsultationVariables.php +++ b/src/Consultations/CommonConsultationVariables.php @@ -36,9 +36,11 @@ public static function variablesFromEvent(EventWrapper $event): array return array_merge(parent::variablesFromEvent($event), [ self::VAR_USER_NAME => $event->getUser()->name, self::VAR_CONSULTATION_TITLE => $event->getConsultationTerm()->consultation->name, - self::VAR_CONSULTATION_PROPOSED_TERM => $proposedTerm + self::VAR_CONSULTATION_PROPOSED_TERM => $proposedTerm ? + $proposedTerm ->setTimezone($event->getUser()->current_timezone) - ->format('Y-m-d H:i:s'), + ->format('Y-m-d H:i:s') : + '', ]); } diff --git a/src/Webinar/CommonWebinarVariables.php b/src/Webinar/CommonWebinarVariables.php index 0970b2b..811dd15 100644 --- a/src/Webinar/CommonWebinarVariables.php +++ b/src/Webinar/CommonWebinarVariables.php @@ -3,6 +3,7 @@ namespace EscolaLms\TemplatesEmail\Webinar; use Carbon\Carbon; +use DateTimeInterface; use EscolaLms\Core\Models\User; use EscolaLms\Templates\Events\EventWrapper; use EscolaLms\TemplatesEmail\Core\EmailVariables; @@ -35,9 +36,11 @@ public static function variablesFromEvent(EventWrapper $event): array return array_merge(parent::variablesFromEvent($event), [ self::VAR_USER_NAME => $event->getUser()->name, self::VAR_WEBINAR_TITLE => $event->getWebinar()->name, - self::VAR_WEBINAR_PROPOSED_TERM => $proposedTerm + self::VAR_WEBINAR_PROPOSED_TERM => $proposedTerm ? + $proposedTerm ->setTimezone($event->getUser()->current_timezone) - ->format('Y-m-d H:i:s'), + ->format('Y-m-d H:i:s') : + '', ]); } From d860ca09c2384ec258b2eed52c45143e90f0449c Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak Date: Fri, 16 Dec 2022 12:18:48 +0100 Subject: [PATCH 3/3] Repair wrong condition in variable consultations --- src/Consultations/CommonConsultationVariables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Consultations/CommonConsultationVariables.php b/src/Consultations/CommonConsultationVariables.php index 0b223d9..3e64c37 100644 --- a/src/Consultations/CommonConsultationVariables.php +++ b/src/Consultations/CommonConsultationVariables.php @@ -27,7 +27,7 @@ public static function mockedVariables(?User $user = null): array public static function variablesFromEvent(EventWrapper $event): array { - if ($event->getWebinar()->active_to instanceof DateTimeInterface) { + if ($event->getConsultationTerm()->active_to instanceof DateTimeInterface) { $proposedTerm = $event->getConsultationTerm()->executed_at; } else { $proposedTerm = Carbon::make($event->getConsultationTerm()->executed_at);