Skip to content

Commit

Permalink
Add today date to the SIR (actually F-MOD)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvps committed Apr 29, 2024
1 parent 8f46359 commit e4855fb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
21 changes: 16 additions & 5 deletions public/sir.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace WEEEOpen\Crauto;

use DateTime;
use DateTimeZone;
use Exception;
use InvalidArgumentException;

require '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
Expand Down Expand Up @@ -53,12 +56,20 @@

$safetytestdate = Validation::dateSchacToHtml($attributes['safetytestdate']);

try {
$tz = new DateTimeZone('Europe/Rome');
$now = (new DateTime('now', $tz))->format('Y-m-d');
} catch (Exception) {
$now = '';
}

$replace = [
'[NAME]' => $attributes['givenname'],
'[SURNAME]' => $attributes['sn'],
'[ID]' => $attributes['schacpersonaluniquecode'],
'[TESTDATE]' => $safetytestdate,
'[CDL]' => $attributes['degreecourse'],
'[NAME]' => $attributes['givenname'],
'[SURNAME]' => $attributes['sn'],
'[ID]' => $attributes['schacpersonaluniquecode'],
'[TESTDATE]' => $safetytestdate,
'[TODAYDATE]' => $now,
'[CDL]' => $attributes['degreecourse'],
];

$sir = new Sir(__DIR__ . '/../resources/pdftemplates');
Expand Down
7 changes: 7 additions & 0 deletions tests/SirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testGenerateSir() {
'[SURNAME]' => 'Doe',
'[ID]' => 's123456',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria dell\'ingegnerizzazione',
];

Expand All @@ -50,6 +51,7 @@ public function testGenerateSirPhD() {
'[SURNAME]' => 'Andrea',
'[ID]' => 'd12345',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Dottorato in dottoramento',
];

Expand All @@ -69,6 +71,7 @@ public function testGenerateSir2() {
'[SURNAME]' => 'Doe',
'[ID]' => 's123456',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria dell\'ingegnerizzazione',
];
$sir = new Sir(TEST_DIR);
Expand All @@ -79,6 +82,7 @@ public function testGenerateSir2() {
'[SURNAME]' => 'Smith',
'[ID]' => 's456789',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria dell\'ingegnerizzazione',
];
$sir = new Sir(TEST_DIR);
Expand All @@ -99,6 +103,7 @@ public function testGenerateSirOnce() {
'[SURNAME]' => 'Doe',
'[ID]' => 's123456',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria dell\'ingegnerizzazione',
];
$sir = new Sir(TEST_DIR);
Expand All @@ -122,6 +127,7 @@ public function testGenerateSirWithUpdate() {
'[SURNAME]' => 'Doe',
'[ID]' => 's123456',
'[TESTDATE]' => '2099-01-01',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria dell\'ingegnerizzazione',
];
$sir = new Sir(TEST_DIR);
Expand All @@ -134,6 +140,7 @@ public function testGenerateSirWithUpdate() {
'[SURNAME]' => 'Doe',
'[ID]' => 's123456',
'[TESTDATE]' => '2099-02-02',
'[TODAYDATE]'=> '2099-02-02',
'[CDL]' => 'Ingegneria del disagio',
];
$sir = new Sir(TEST_DIR);
Expand Down
1 change: 1 addition & 0 deletions tests/pdftemplates-test/template-dottorandi.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1,21,62,12,[NAME]
1,21,72,12,[SURNAME]
1,21,82,12,"BTW, I study [CDL]"
1,21,92,12,"Today is [TODAYDATE]"
2,64,37,12,[ID]
2,108,37,12,[TESTDATE]
3,19,201,12,Some hardcoded text about [NAME] [SURNAME]
Expand Down
1 change: 1 addition & 0 deletions tests/pdftemplates-test/template-studenti.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1,21,62,12,[NAME]
1,21,72,12,[SURNAME]
1,21,82,12,"BTW, I study [CDL]"
1,21,92,12,"Today is [TODAYDATE]"
2,64,43,12,[ID]
2,108,43,12,[TESTDATE]
3,19,201,12,Some hardcoded text about [NAME] [SURNAME]
Expand Down

0 comments on commit e4855fb

Please sign in to comment.