mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: extract MediaController, wire into Dispatcher, delete media.php
This commit is contained in:
39
app/templates/partials/form/checkbox-list.php
Normal file
39
app/templates/partials/form/checkbox-list.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Checkbox list partial — renders a group of checkboxes (e.g. languages, formats).
|
||||
*
|
||||
* The group label uses a visible <span> as the first column (matching other form
|
||||
* rows), while a <fieldset>/<legend> in the second column provides the accessible
|
||||
* grouping required by WCAG 1.3.1. The <legend> is visually hidden (sr-only) to
|
||||
* avoid duplicating the visible label text.
|
||||
*
|
||||
* Variables consumed:
|
||||
* string $name — input name attribute (will be posted as array: name[])
|
||||
* string $label — group label text
|
||||
* array $options — each element must have 'id' and 'name' keys
|
||||
* array $checked — array of 'id' values that are currently checked
|
||||
*/
|
||||
|
||||
$checked = $checked ?? [];
|
||||
?>
|
||||
<div>
|
||||
<span class="admin-row-label"><?= htmlspecialchars($label) ?></span>
|
||||
<fieldset class="admin-checkbox-group">
|
||||
<legend class="sr-only"><?= htmlspecialchars($label) ?></legend>
|
||||
<ul>
|
||||
<?php foreach ($options as $opt): ?>
|
||||
<li>
|
||||
<label class="admin-checkbox-label">
|
||||
<input type="checkbox"
|
||||
name="<?= htmlspecialchars($name) ?>[]"
|
||||
value="<?= htmlspecialchars((string)$opt['id']) ?>"
|
||||
<?= in_array((string)$opt['id'], array_map('strval', $checked)) ? 'checked' : '' ?>>
|
||||
<?= htmlspecialchars($opt['name']) ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php
|
||||
unset($checked);
|
||||
33
app/templates/partials/form/file-field.php
Normal file
33
app/templates/partials/form/file-field.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* File input partial.
|
||||
*
|
||||
* Variables consumed:
|
||||
* string $name — input name attribute (used for id too unless $id set)
|
||||
* string $label — visible label text
|
||||
* string $accept — MIME types / extensions for the accept attribute (e.g. 'image/jpeg,image/png')
|
||||
* string|null $hint — optional hint shown in <small> below the input
|
||||
* bool $multiple — whether to allow multiple file selection; default false
|
||||
* string|null $id — override the id attribute (defaults to $name)
|
||||
*/
|
||||
|
||||
$accept = $accept ?? '';
|
||||
$hint = $hint ?? null;
|
||||
$multiple = $multiple ?? false;
|
||||
$id = $id ?? $name;
|
||||
?>
|
||||
<div>
|
||||
<label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?></label>
|
||||
<div class="admin-file-input">
|
||||
<input type="file"
|
||||
id="<?= htmlspecialchars($id) ?>"
|
||||
name="<?= htmlspecialchars($name) ?><?= $multiple ? '[]' : '' ?>"
|
||||
<?= $accept ? 'accept="' . htmlspecialchars($accept) . '"' : '' ?>
|
||||
<?= $multiple ? 'multiple' : '' ?>>
|
||||
<?php if ($hint): ?>
|
||||
<small><?= htmlspecialchars($hint) ?></small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
unset($accept, $hint, $multiple, $id);
|
||||
115
app/templates/partials/form/jury-fieldset.php
Normal file
115
app/templates/partials/form/jury-fieldset.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Jury composition fieldset partial.
|
||||
*
|
||||
* Variables consumed (all optional — defaults to empty/add-mode):
|
||||
* $juryPresident string|null President name
|
||||
* $juryPromoteur string|null Promoteur name
|
||||
* $juryPromoteurExt int 1 if promoteur is external, 0 otherwise
|
||||
* $juryLecteurs array Each element: ['name' => string, 'is_external' => int]
|
||||
*
|
||||
* In "add" mode (no existing jury data), callers should pass nulls/empty arrays and
|
||||
* may rely on the $formData repopulation helpers (old/wasSelected) defined in add.php.
|
||||
* When those helpers exist and no explicit values are set, the partial uses them.
|
||||
*/
|
||||
|
||||
$juryPresident = $juryPresident ?? null;
|
||||
$juryPromoteur = $juryPromoteur ?? null;
|
||||
$juryPromoteurExt = $juryPromoteurExt ?? 0;
|
||||
$juryLecteurs = $juryLecteurs ?? [];
|
||||
|
||||
// In add-mode, repopulate from flash form data when helpers are available.
|
||||
$addMode = ($juryPresident === null && $juryPromoteur === null && empty($juryLecteurs));
|
||||
if ($addMode && function_exists('old')) {
|
||||
$juryPresident = old('jury_president') ?: null;
|
||||
$juryPromoteur = old('jury_promoteur') ?: null;
|
||||
$juryPromoteurExt = function_exists('wasSelected') && wasSelected('jury_promoteur_ext', '1') ? 1 : 0;
|
||||
}
|
||||
|
||||
$juryIdx = max(count($juryLecteurs), 1);
|
||||
?>
|
||||
<!-- Composition du jury -->
|
||||
<fieldset>
|
||||
<legend>Composition du jury</legend>
|
||||
|
||||
<!-- Président·e -->
|
||||
<div>
|
||||
<label for="jury_president">Président·e :</label>
|
||||
<input type="text" id="jury_president" name="jury_president"
|
||||
value="<?= htmlspecialchars($juryPresident ?? '') ?>"
|
||||
placeholder="Nom du/de la président·e (interne)">
|
||||
</div>
|
||||
|
||||
<!-- Promoteur·ice -->
|
||||
<div>
|
||||
<label for="jury_promoteur">Promoteur·ice :</label>
|
||||
<div class="admin-jury-row">
|
||||
<input type="text" id="jury_promoteur" name="jury_promoteur"
|
||||
value="<?= htmlspecialchars($juryPromoteur ?? '') ?>" placeholder="Nom">
|
||||
<label class="admin-checkbox-label admin-jury-ext">
|
||||
<input type="checkbox" name="jury_promoteur_ext" value="1"
|
||||
<?= $juryPromoteurExt ? 'checked' : '' ?>
|
||||
aria-label="Promoteur·ice — externe"> Externe
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Lecteur·ices (dynamic list) -->
|
||||
<fieldset class="admin-jury-lecteurs">
|
||||
<legend>Lecteur·ices</legend>
|
||||
<div id="jury-lecteurs-list" class="admin-jury-list">
|
||||
<?php if (empty($juryLecteurs)): ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_lecteurs[]" placeholder="Nom"
|
||||
id="jury_lecteur_0" aria-label="Lecteur·ice 1 — nom">
|
||||
<label class="admin-checkbox-label admin-jury-ext">
|
||||
<input type="checkbox" name="jury_lecteurs_ext[0]" value="1"
|
||||
aria-label="Lecteur·ice 1 — externe"> Externe
|
||||
</label>
|
||||
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)"
|
||||
aria-label="Supprimer le lecteur·ice 1"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php foreach ($juryLecteurs as $li => $lm): ?>
|
||||
<?php $lNum = $li + 1; ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_lecteurs[]"
|
||||
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom"
|
||||
id="jury_lecteur_<?= $li ?>" aria-label="Lecteur·ice <?= $lNum ?> — nom">
|
||||
<label class="admin-checkbox-label admin-jury-ext">
|
||||
<input type="checkbox" name="jury_lecteurs_ext[<?= $li ?>]" value="1"
|
||||
<?= $lm['is_external'] ? 'checked' : '' ?>
|
||||
aria-label="Lecteur·ice <?= $lNum ?> — externe"> Externe
|
||||
</label>
|
||||
<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)"
|
||||
aria-label="Supprimer le lecteur·ice <?= $lNum ?>"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<button type="button" class="admin-btn-secondary admin-add-jury-btn"
|
||||
onclick="addJuryRow()">+ Ajouter un·e lecteur·ice</button>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
<script>
|
||||
var juryIdx = <?= $juryIdx ?>;
|
||||
function addJuryRow() {
|
||||
var list = document.getElementById('jury-lecteurs-list');
|
||||
var n = list.querySelectorAll('.admin-jury-entry').length + 1;
|
||||
var div = document.createElement('div');
|
||||
div.className = 'admin-jury-entry';
|
||||
div.innerHTML = '<input type="text" name="jury_lecteurs[]" placeholder="Nom"'
|
||||
+ ' aria-label="Lecteur\u00b7ice ' + n + ' \u2014 nom">'
|
||||
+ '<label class="admin-checkbox-label admin-jury-ext">'
|
||||
+ '<input type="checkbox" name="jury_lecteurs_ext[' + juryIdx + ']" value="1"'
|
||||
+ ' aria-label="Lecteur\u00b7ice ' + n + ' \u2014 externe"> Externe'
|
||||
+ '</label>'
|
||||
+ '<button type="button" class="admin-btn-remove" onclick="removeJuryRow(this)"'
|
||||
+ ' aria-label="Supprimer le lecteur\u00b7ice ' + n + '"><span aria-hidden="true">\u2715</span></button>';
|
||||
list.appendChild(div);
|
||||
juryIdx++;
|
||||
}
|
||||
function removeJuryRow(btn) {
|
||||
btn.closest('.admin-jury-entry').remove();
|
||||
}
|
||||
</script>
|
||||
61
app/templates/partials/form/select-field.php
Normal file
61
app/templates/partials/form/select-field.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Select field partial.
|
||||
*
|
||||
* Variables consumed:
|
||||
* string $name — select name attribute (also used for id)
|
||||
* string $label — visible label text
|
||||
* array $options — each element must have 'id' and 'name' keys;
|
||||
* may optionally have 'code' for display suffix
|
||||
* mixed $selected — currently selected value (compared to option 'id');
|
||||
* pass null or '' for no selection
|
||||
* bool $required — whether the field is required; default false
|
||||
* string $placeholder — text for the leading empty <option>; default ''
|
||||
* set to null to suppress the empty option entirely
|
||||
* string|null $id — override the id attribute (defaults to $name)
|
||||
* string|null $hint — optional hint shown in <small> below the select
|
||||
*/
|
||||
|
||||
$required = $required ?? false;
|
||||
$placeholder = array_key_exists('placeholder', get_defined_vars()) ? $placeholder : '';
|
||||
$id = $id ?? $name;
|
||||
$hint = $hint ?? null;
|
||||
$attrs = $attrs ?? [];
|
||||
?>
|
||||
<div>
|
||||
<label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?></label>
|
||||
<?php
|
||||
$selectAttrStr = '';
|
||||
foreach ($attrs as $k => $v) {
|
||||
if ($v === true) {
|
||||
$selectAttrStr .= ' ' . htmlspecialchars($k);
|
||||
} else {
|
||||
$selectAttrStr .= ' ' . htmlspecialchars($k) . '="' . htmlspecialchars((string)$v) . '"';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<select id="<?= htmlspecialchars($id) ?>"
|
||||
name="<?= htmlspecialchars($name) ?>"
|
||||
<?= $required ? 'required' : '' ?>
|
||||
<?= $selectAttrStr ?>>
|
||||
<?php if ($placeholder !== null): ?>
|
||||
<option value=""><?= htmlspecialchars($placeholder) ?></option>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($options as $opt): ?>
|
||||
<?php
|
||||
// Match by id (numeric FK) or by name string (when the view returns the name).
|
||||
$isSelected = ((string)$selected === (string)$opt['id'])
|
||||
|| ($selected !== null && $selected !== '' && isset($opt['name']) && (string)$selected === (string)$opt['name']);
|
||||
?>
|
||||
<option value="<?= htmlspecialchars((string)$opt['id']) ?>"
|
||||
<?= $isSelected ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($opt['name']) ?><?php if (!empty($opt['code'])): ?> (<?= htmlspecialchars($opt['code']) ?>)<?php endif; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($hint): ?>
|
||||
<small><?= htmlspecialchars($hint) ?></small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
unset($required, $placeholder, $id, $hint, $attrs, $selectAttrStr, $k, $v);
|
||||
60
app/templates/partials/form/text-field.php
Normal file
60
app/templates/partials/form/text-field.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Text field partial — single-line text / number / url / email input.
|
||||
*
|
||||
* Variables consumed:
|
||||
* string $name — input name attribute (also used for id)
|
||||
* string $label — visible label text
|
||||
* string $value — current value (already htmlspecialchars'd by caller, or raw)
|
||||
* string $type — input type; default 'text'
|
||||
* bool $required — whether the field is required; default false
|
||||
* string $placeholder — placeholder text; default ''
|
||||
* string|null $hint — optional hint shown in <small> below the input
|
||||
* string|null $id — override the id attribute (defaults to $name)
|
||||
* array $attrs — extra HTML attributes as key=>value pairs (e.g. min/max for number)
|
||||
*
|
||||
* The partial does NOT call htmlspecialchars on $value — the caller is responsible.
|
||||
*/
|
||||
|
||||
$type = $type ?? 'text';
|
||||
$required = $required ?? false;
|
||||
$placeholder = $placeholder ?? '';
|
||||
$hint = $hint ?? null;
|
||||
$id = $id ?? $name;
|
||||
$attrs = $attrs ?? [];
|
||||
|
||||
$attrStr = '';
|
||||
foreach ($attrs as $k => $v) {
|
||||
if ($v === true) {
|
||||
$attrStr .= ' ' . htmlspecialchars($k);
|
||||
} else {
|
||||
$attrStr .= ' ' . htmlspecialchars($k) . '="' . htmlspecialchars((string)$v) . '"';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="<?= htmlspecialchars($id) ?>"><?= htmlspecialchars($label) ?></label>
|
||||
<?php if ($hint): ?>
|
||||
<div>
|
||||
<input type="<?= htmlspecialchars($type) ?>"
|
||||
id="<?= htmlspecialchars($id) ?>"
|
||||
name="<?= htmlspecialchars($name) ?>"
|
||||
value="<?= $value ?>"
|
||||
<?= $required ? 'required' : '' ?>
|
||||
<?= $placeholder ? 'placeholder="' . htmlspecialchars($placeholder) . '"' : '' ?>
|
||||
<?= $attrStr ?>>
|
||||
<small><?= htmlspecialchars($hint) ?></small>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<input type="<?= htmlspecialchars($type) ?>"
|
||||
id="<?= htmlspecialchars($id) ?>"
|
||||
name="<?= htmlspecialchars($name) ?>"
|
||||
value="<?= $value ?>"
|
||||
<?= $required ? 'required' : '' ?>
|
||||
<?= $placeholder ? 'placeholder="' . htmlspecialchars($placeholder) . '"' : '' ?>
|
||||
<?= $attrStr ?>>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
// Reset consumed variables so includes in a loop don't bleed state.
|
||||
unset($type, $required, $placeholder, $hint, $id, $attrs, $attrStr, $k, $v);
|
||||
Reference in New Issue
Block a user