Skip to content

Commit f2e607e

Browse files
author
laurent.abbal
committed
Ajout d'une route pour dupliquer les épreuves pratiques avec vérification d'accès
1 parent 42d096d commit f2e607e

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

resources/views/welcome.blade.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<div class="container mt-3">
1919

20+
{{--
2021
<div class="row pb-3 text-monospace">
2122
<div class="col-md-8 offset-md-2">
2223
<div class="border border-danger rounded p-2 text-danger small">
@@ -25,6 +26,8 @@
2526
</div>
2627
</div>
2728
</div>
29+
--}}
30+
2831

2932
<div class="row pt-3 text-monospace">
3033
<div class="col-md-1 text-muted text-right small">

routes/web.php

+84
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Http\Controllers\Auth\VerificationController;
99
use Illuminate\Support\Facades\Session;
1010

11+
use App\Models\Defi;
12+
1113

1214
// ============================================================================
1315
// == SETLOCALE & PREFIX BASED ON URL OR PREVIOUS URL
@@ -315,6 +317,88 @@
315317
});
316318

317319

320+
// ============================================================================
321+
// == Duplicate epreuve pratique
322+
// ============================================================================
323+
324+
Route::get('/duplicate-ep', function () {
325+
326+
// Vérifier que l'utilisateur connecté a l'ID 1
327+
if (auth()->user()->id !== 1) {
328+
abort(403, 'Accès non autorisé.');
329+
}
330+
331+
$conversion = [
332+
'01' => '47', '02' => '45', '03' => '08', '04' => '48', '05' => '02', '06' => '27',
333+
'07' => '37', '08' => '30', '09' => '23', '10' => '44', '11' => '36', '12' => '34',
334+
'13' => '13', '14' => '20', '15' => '38', '16' => '04', '17' => '42', '18' => '15',
335+
'19' => '06', '20' => '14', '21' => '31', '22' => '40', '23' => '33', '24' => '11',
336+
'25' => '19', '26' => '26', '27' => '43', '28' => '03', '29' => '16', '30' => '12',
337+
'31' => '09', '32' => '41', '33' => '05', '34' => '07', '35' => '25', '36' => '32',
338+
'37' => '39', '38' => '21', '39' => '22', '40' => '29', '41' => '17', '42' => '18',
339+
'43' => '28', '44' => '24', '45' => '46', '46' => '10', '47' => '35', '48' => '01'
340+
];
341+
342+
// Sélection des articles concernés
343+
$articles = Defi::where('user_id', 1)
344+
->where('titre_enseignant', 'like', '%[EP23]%')
345+
->get();
346+
347+
foreach ($articles as $article) {
348+
349+
$newTitle = preg_replace_callback('/\[EP23\] - (\d{2})\.(1|2)/', function ($matches) use ($conversion) {
350+
$oldNumber = $matches[1]; // Nombre avant le point (ex: '04')
351+
$decimal = $matches[2]; // Partie après le point (ex: '1')
352+
// Remplacer le nombre avant le point selon la conversion
353+
$newNumber = $conversion[$oldNumber] ?? $oldNumber;
354+
// Retourner le nouveau titre avec la partie décimale inchangée
355+
356+
return "[EP25] - {$newNumber}.{$decimal}";
357+
}, $article->title);
358+
359+
// Mise à jour du titre
360+
if ($newTitle !== $article->title) {
361+
echo $newTitle . "<br />";
362+
/*
363+
do {
364+
$codeError = '';
365+
$chars = '23456789abcdefghjklmnpqrstuvwxyz';
366+
$jeton = substr(str_shuffle($chars), 0, 4);
367+
368+
try {
369+
Defi::create([
370+
'user_id' => $article->user_id,
371+
'jeton' => $jeton,
372+
'titre_enseignant' => $newTitle,
373+
'sous_titre_enseignant' => $article->sous_titre_enseignant,
374+
'titre_eleve' => $newTitle,
375+
'consignes_eleve' => $article->consignes_eleve,
376+
'tests' => $article->tests,
377+
'lang' => $article->lang,
378+
'with_chrono' => $article->with_chrono,
379+
'with_nbverif' => $article->with_nbverif,
380+
'with_message' => $article->with_message,
381+
'with_console' => $article->with_console,
382+
'uuid' => Str::orderedUuid()->getHex(),
383+
'code' => $article->code,
384+
'code_pre_tests' => $article->code_pre_tests,
385+
'solution' => $article->solution,
386+
]);
387+
}
388+
389+
catch(Exception $e) {
390+
$codeError = $e->errorInfo[1];
391+
}
392+
393+
} while ($codeError === 1062);
394+
*/
395+
}
396+
}
397+
398+
return "Mise à jour terminée !";
399+
})->middleware('auth');
400+
401+
318402
// ============================================================================
319403
// == HUB
320404
// ============================================================================

0 commit comments

Comments
 (0)