Skip to content

Commit

Permalink
Added variables for consultations date start and end (#57)
Browse files Browse the repository at this point in the history
* Added variables for consultations date start and end

* Update composer
  • Loading branch information
daVitekPL authored Feb 17, 2023
1 parent d99d04d commit 3f34e57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
"config": {
"optimize-autoloader": false,
"preferred-install": "dist",
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
18 changes: 14 additions & 4 deletions src/Consultations/CommonConsultationVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use EscolaLms\Consultations\Models\ConsultationUserPivot;
use EscolaLms\Consultations\Services\Contracts\ConsultationServiceContract;
use EscolaLms\Core\Models\User;
use EscolaLms\Templates\Events\EventWrapper;
use EscolaLms\TemplatesEmail\Core\EmailVariables;
Expand All @@ -13,14 +14,19 @@ abstract class CommonConsultationVariables extends EmailVariables
const VAR_USER_NAME = '@VarUserName';
const VAR_CONSULTATION_TITLE = '@VarConsultationTitle';
const VAR_CONSULTATION_PROPOSED_TERM = '@VarConsultationProposedTerm';
const VAR_CONSULTATION_DATE_TIME_START = '@VarConsultationDateTimeStart';
const VAR_CONSULTATION_DATE_TIME_END = '@VarConsultationDateTimeEnd';

public static function mockedVariables(?User $user = null): array
{
$faker = \Faker\Factory::create();
$date = $faker->dateTime();
return array_merge(parent::mockedVariables(), [
self::VAR_USER_NAME => $faker->name(),
self::VAR_CONSULTATION_TITLE => $faker->word(),
self::VAR_CONSULTATION_PROPOSED_TERM => $faker->dateTime()->format('Y-m-d H:i:s'),
self::VAR_CONSULTATION_PROPOSED_TERM => $date->format('Y-m-d H:i:s'),
self::VAR_CONSULTATION_DATE_TIME_START => Carbon::parse($date)->toISOString(),
self::VAR_CONSULTATION_DATE_TIME_END => Carbon::parse($date)->addHour()->toISOString(),
]);
}

Expand All @@ -32,14 +38,18 @@ public static function variablesFromEvent(EventWrapper $event): array
$executedAt = Carbon::make($executedAt);
}
$executedAt = $executedAt
->setTimezone($event->getUser()->current_timezone)
->format('Y-m-d H:i:s');
->setTimezone($event->getUser()->current_timezone);

}
$executedTo = $executedAt ? app(ConsultationServiceContract::class)
->generateDateTo($executedAt, $event->getConsultationTerm()->consultation->getDuration()) : $executedAt;

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 => $executedAt,
self::VAR_CONSULTATION_PROPOSED_TERM => $executedAt->format('Y-m-d H:i:s'),
self::VAR_CONSULTATION_DATE_TIME_START => $executedAt->toISOString(),
self::VAR_CONSULTATION_DATE_TIME_END => $executedTo->toISOString(),
]);
}

Expand Down

0 comments on commit 3f34e57

Please sign in to comment.