|
8 | 8 | use App\Http\Controllers\Auth\VerificationController;
|
9 | 9 | use Illuminate\Support\Facades\Session;
|
10 | 10 |
|
| 11 | +use App\Models\Defi; |
| 12 | + |
11 | 13 |
|
12 | 14 | // ============================================================================
|
13 | 15 | // == SETLOCALE & PREFIX BASED ON URL OR PREVIOUS URL
|
|
315 | 317 | });
|
316 | 318 |
|
317 | 319 |
|
| 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 | + |
318 | 402 | // ============================================================================
|
319 | 403 | // == HUB
|
320 | 404 | // ============================================================================
|
|
0 commit comments