diff --git a/src/Consultations/CommonConsultationVariables.php b/src/Consultations/CommonConsultationVariables.php index 805871c..7d88b44 100644 --- a/src/Consultations/CommonConsultationVariables.php +++ b/src/Consultations/CommonConsultationVariables.php @@ -2,6 +2,7 @@ namespace EscolaLms\TemplatesEmail\Consultations; +use Carbon\Carbon; use EscolaLms\Consultations\Models\ConsultationUserPivot; use EscolaLms\Core\Models\User; use EscolaLms\Templates\Events\EventWrapper; @@ -25,12 +26,20 @@ public static function mockedVariables(?User $user = null): array public static function variablesFromEvent(EventWrapper $event): array { + $executedAt = $event->getConsultationTerm()->executed_at ?? ''; + if ($executedAt) { + if (!$executedAt instanceof Carbon) { + $executedAt = Carbon::make($executedAt); + } + $executedAt = $executedAt + ->setTimezone($event->getUser()->current_timezone) + ->format('Y-m-d H:i:s'); + } + 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 => $event->getConsultationTerm()->executed_at - ->setTimezone($event->getUser()->current_timezone) - ->format('Y-m-d H:i:s'), + self::VAR_CONSULTATION_PROPOSED_TERM => $executedAt, ]); } diff --git a/src/Core/EmailChannel.php b/src/Core/EmailChannel.php index 13d79ae..26ea90a 100644 --- a/src/Core/EmailChannel.php +++ b/src/Core/EmailChannel.php @@ -28,7 +28,7 @@ public static function send(EventWrapper $event, array $sections): bool } $email = $event->getUser()->email; if (method_exists($event, 'getEmail')) { - $email = $event->getEmail(); + $email = $event->getEmail() ?? $email; } $mailable = new EmailMailable(); $mailable->to($email); diff --git a/src/Webinar/CommonWebinarVariables.php b/src/Webinar/CommonWebinarVariables.php index 1c9b735..ead6407 100644 --- a/src/Webinar/CommonWebinarVariables.php +++ b/src/Webinar/CommonWebinarVariables.php @@ -6,6 +6,7 @@ use EscolaLms\Templates\Events\EventWrapper; use EscolaLms\TemplatesEmail\Core\EmailVariables; use EscolaLms\Webinar\Models\Webinar; +use Illuminate\Support\Carbon; abstract class CommonWebinarVariables extends EmailVariables { @@ -25,12 +26,20 @@ public static function mockedVariables(?User $user = null): array public static function variablesFromEvent(EventWrapper $event): array { + $proposedTerm = $event->getWebinar()->active_to ?? ''; + if ($proposedTerm) { + if (!$proposedTerm instanceof Carbon) { + $proposedTerm = Carbon::make($proposedTerm); + } + $proposedTerm = $proposedTerm + ->setTimezone($event->getUser()->current_timezone) + ->format('Y-m-d H:i:s'); + } + 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 => $event->getWebinar()->active_to - ->setTimezone($event->getUser()->current_timezone) - ->format('Y-m-d H:i:s'), + self::VAR_WEBINAR_PROPOSED_TERM => $proposedTerm, ]); }