mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Remove required from all admin add/edit form inputs
- Skip required-field validation for orientation/ap/finality/licence/jury in admin add+edit
This commit is contained in:
@@ -139,10 +139,10 @@ class ThesisCreateController
|
||||
* @return int The newly created thesis ID.
|
||||
* @throws Exception On validation or DB error.
|
||||
*/
|
||||
public function submit(array $post, array $files): int
|
||||
public function submit(array $post, array $files, bool $adminMode = false): int
|
||||
{
|
||||
// ── 1. Validate + sanitise ────────────────────────────────────────────
|
||||
$data = $this->validateAndSanitise($post);
|
||||
$data = $this->validateAndSanitise($post, $adminMode);
|
||||
|
||||
// ── 1b. Duplicate detection ───────────────────────────────────────────
|
||||
require_once APP_ROOT . '/src/DuplicateThesisException.php';
|
||||
@@ -293,7 +293,7 @@ class ThesisCreateController
|
||||
* @return array<string, mixed>
|
||||
* @throws Exception on validation failure.
|
||||
*/
|
||||
private function validateAndSanitise(array $post): array
|
||||
private function validateAndSanitise(array $post, bool $adminMode = false): array
|
||||
{
|
||||
// Split authors by comma, trim, filter empty, sort alphabetically.
|
||||
$authorRaw = $this->sanitiseString($post['auteurice'] ?? '');
|
||||
@@ -321,18 +321,18 @@ class ThesisCreateController
|
||||
throw new Exception('Année invalide. Veuillez entrer une année valide.');
|
||||
}
|
||||
|
||||
$orientationId = filter_var($post['orientation'] ?? '', FILTER_VALIDATE_INT);
|
||||
if ($orientationId === false) {
|
||||
$orientationId = filter_var($post['orientation'] ?? '', FILTER_VALIDATE_INT) ?: null;
|
||||
if (!$adminMode && !$orientationId) {
|
||||
throw new Exception('Veuillez sélectionner une orientation.');
|
||||
}
|
||||
|
||||
$apProgramId = filter_var($post['ap'] ?? '', FILTER_VALIDATE_INT);
|
||||
if ($apProgramId === false) {
|
||||
$apProgramId = filter_var($post['ap'] ?? '', FILTER_VALIDATE_INT) ?: null;
|
||||
if (!$adminMode && !$apProgramId) {
|
||||
throw new Exception('Veuillez sélectionner un Atelier Pratique.');
|
||||
}
|
||||
|
||||
$finalityId = filter_var($post['finality'] ?? '', FILTER_VALIDATE_INT);
|
||||
if ($finalityId === false) {
|
||||
$finalityId = filter_var($post['finality'] ?? '', FILTER_VALIDATE_INT) ?: null;
|
||||
if (!$adminMode && !$finalityId) {
|
||||
throw new Exception('Veuillez sélectionner une finalité.');
|
||||
}
|
||||
|
||||
@@ -412,13 +412,13 @@ class ThesisCreateController
|
||||
$juryMembers[] = ['name' => trim($post['jury_president']), 'role' => 'president', 'is_external' => 0];
|
||||
}
|
||||
|
||||
if (!$hasPromoteur) {
|
||||
if (!$adminMode && !$hasPromoteur) {
|
||||
throw new Exception('Veuillez indiquer au moins un·e promoteur·ice interne.');
|
||||
}
|
||||
if (!$hasLecteurInt) {
|
||||
if (!$adminMode && !$hasLecteurInt) {
|
||||
throw new Exception('Veuillez indiquer au moins un·e lecteur·ice interne.');
|
||||
}
|
||||
if (!$hasLecteurExt) {
|
||||
if (!$adminMode && !$hasLecteurExt) {
|
||||
throw new Exception('Veuillez indiquer au moins un·e lecteur·ice externe.');
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ class ThesisCreateController
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($languageIds)) {
|
||||
if (!$adminMode && empty($languageIds)) {
|
||||
throw new Exception('Veuillez sélectionner au moins une langue.');
|
||||
}
|
||||
|
||||
@@ -449,13 +449,13 @@ class ThesisCreateController
|
||||
$formatIds = isset($post['formats']) && is_array($post['formats'])
|
||||
? array_map('intval', $post['formats'])
|
||||
: [];
|
||||
if (empty($formatIds)) {
|
||||
if (!$adminMode && empty($formatIds)) {
|
||||
throw new Exception('Veuillez sélectionner au moins un format.');
|
||||
}
|
||||
|
||||
$licenseId = filter_var($post['license_id'] ?? '', FILTER_VALIDATE_INT) ?: null;
|
||||
$licenseCustom = trim($post['license_custom'] ?? '');
|
||||
if (!$licenseId && $licenseCustom === '') {
|
||||
if (!$adminMode && !$licenseId && $licenseCustom === '') {
|
||||
throw new Exception('Veuillez sélectionner une licence ou en préciser une.');
|
||||
}
|
||||
|
||||
|
||||
@@ -181,62 +181,8 @@ class ThesisEditController
|
||||
$errors[] = "L'année est invalide.";
|
||||
}
|
||||
$orientationId = intval($post['orientation'] ?? 0);
|
||||
if ($orientationId <= 0) {
|
||||
$errors[] = "L'orientation est requise.";
|
||||
}
|
||||
$apProgramId = intval($post['ap'] ?? 0);
|
||||
if ($apProgramId <= 0) {
|
||||
$errors[] = "L'atelier pluridisciplinaire est requis.";
|
||||
}
|
||||
$finalityId = intval($post['finality'] ?? 0);
|
||||
if ($finalityId <= 0) {
|
||||
$errors[] = 'La finalité est requise.';
|
||||
}
|
||||
|
||||
// Languages
|
||||
$langIds = isset($post['languages']) && is_array($post['languages']) ? $post['languages'] : [];
|
||||
if (empty($langIds)) {
|
||||
$errors[] = 'Au moins une langue est requise.';
|
||||
}
|
||||
|
||||
// Formats
|
||||
$fmtIds = isset($post['formats']) && is_array($post['formats']) ? $post['formats'] : [];
|
||||
if (empty($fmtIds)) {
|
||||
$errors[] = 'Au moins un format est requis.';
|
||||
}
|
||||
|
||||
// Licence
|
||||
$licenseId = filter_var($post['license_id'] ?? '', FILTER_VALIDATE_INT) ?: null;
|
||||
$licenseCustom = trim($post['license_custom'] ?? '');
|
||||
if (!$licenseId && $licenseCustom === '') {
|
||||
$errors[] = 'Une licence est requise.';
|
||||
}
|
||||
|
||||
// Jury
|
||||
$hasPromoteur = !empty(trim($post['jury_promoteur'] ?? ''));
|
||||
$hasLecteurInt = false;
|
||||
$hasLecteurExt = false;
|
||||
foreach ($post['jury_lecteur_interne'] ?? [] as $n) {
|
||||
if (trim((string)$n) !== '') {
|
||||
$hasLecteurInt = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($post['jury_lecteur_externe'] ?? [] as $n) {
|
||||
if (trim((string)$n) !== '') {
|
||||
$hasLecteurExt = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$hasPromoteur) {
|
||||
$errors[] = 'Un·e promoteur·ice interne est requis.';
|
||||
}
|
||||
if (!$hasLecteurInt) {
|
||||
$errors[] = 'Au moins un·e lecteur·ice interne est requis.';
|
||||
}
|
||||
if (!$hasLecteurExt) {
|
||||
$errors[] = 'Au moins un·e lecteur·ice externe est requis.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
throw new RuntimeException(implode(' ', $errors));
|
||||
|
||||
Reference in New Issue
Block a user