Skip to content

Commit

Permalink
Add cert number to variables (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 committed Mar 1, 2024
1 parent 3d4f9f3 commit a097a12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Courses/CommonUserAndCourseVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use EscolaLms\Courses\Models\Course;
use EscolaLms\Templates\Events\EventWrapper;
use EscolaLms\TemplatesPdf\Core\PdfVariables;
use EscolaLms\TemplatesPdf\Models\FabricPDF;
use Illuminate\Support\Carbon;

abstract class CommonUserAndCourseVariables extends PdfVariables
Expand All @@ -19,6 +20,8 @@ abstract class CommonUserAndCourseVariables extends PdfVariables
const VAR_COURSE_CATEGORIES_WITH_BREADCRUMBS = '@VarCourseCategoriesWithBreadcrumbs';
const VAR_CATEGORIES_ID = '@VarCategoriesId';
const VAR_COURSE_ID = '@VarCourseId';
const VAR_CONTINUOUS_CERT_NUMBER = '@VarContinuousCertNumber';
const VAR_ANNUAL_CERT_NUMBER = '@VarAnnualCertNumber';

public static function mockedVariables(?User $user = null): array
{
Expand All @@ -33,6 +36,8 @@ public static function mockedVariables(?User $user = null): array
self::VAR_COURSE_CATEGORIES_WITH_BREADCRUMBS => $faker->word(),
self::VAR_CATEGORIES_ID => $faker->numberBetween(1),
self::VAR_COURSE_ID => $faker->numberBetween(1),
self::VAR_CONTINUOUS_CERT_NUMBER => $faker->numberBetween(1),
self::VAR_ANNUAL_CERT_NUMBER => $faker->numberBetween(1) . '/' . now()->year,
]);
}

Expand All @@ -47,7 +52,9 @@ public static function variablesFromEvent(EventWrapper $event): array
self::VAR_COURSE_CATEGORIES => $event->getCourse()->categories->pluck('name')->implode(', '),
self::VAR_COURSE_CATEGORIES_WITH_BREADCRUMBS => $event->getCourse()->categories->pluck('name_with_breadcrumbs')->implode(', '),
self::VAR_CATEGORIES_ID => $event->getCourse()->categories->pluck('id')->implode(', '),
self::VAR_COURSE_ID => $event->getCourse()->id,
self::VAR_COURSE_ID => (string) $event->getCourse()->id,
self::VAR_CONTINUOUS_CERT_NUMBER => (string) (FabricPDF::count() + 1),
self::VAR_ANNUAL_CERT_NUMBER => FabricPDF::whereYear('created_at', now()->year)->count() + 1 . '/' . now()->year,
]);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Api/CoursesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public function testUserFinishedCourseNotification(): void
$section = $template->sections->where('key', 'title')->first();

$this->assertEquals(str_replace(UserFinishedCourseVariables::VAR_COURSE_TITLE, $course->title, $section->content), $pdf->title);
$this->assertEquals('1', $pdf->vars[UserFinishedCourseVariables::VAR_CONTINUOUS_CERT_NUMBER]);
$this->assertEquals('1/' . now()->year, $pdf->vars[UserFinishedCourseVariables::VAR_ANNUAL_CERT_NUMBER]);
}

public function testUserFinishedCoursePDFfromReportBro(): void
Expand Down

0 comments on commit a097a12

Please sign in to comment.