mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: student name popover preview on /repertoire via htmx
This commit is contained in:
@@ -203,6 +203,30 @@ class SearchController
|
||||
* Render the repertoire index partial and exit (for HTMX swaps).
|
||||
* Never returns.
|
||||
*/
|
||||
/**
|
||||
* HTMX endpoint: returns a popover snippet for a student name.
|
||||
* Renders directly and exits.
|
||||
*/
|
||||
public function handleStudentPreview(): never {
|
||||
$name = trim($_GET['name'] ?? '');
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
if ($name === '') {
|
||||
echo '';
|
||||
exit();
|
||||
}
|
||||
|
||||
$theses = $this->db->getThesesByAuthorName($name);
|
||||
|
||||
if (empty($theses)) {
|
||||
echo '';
|
||||
exit();
|
||||
}
|
||||
|
||||
include APP_ROOT . '/templates/partials/student-preview.php';
|
||||
exit();
|
||||
}
|
||||
|
||||
private function renderRepertoirePartial(
|
||||
array $repData,
|
||||
array $activeFilters,
|
||||
|
||||
@@ -455,6 +455,24 @@ class Database {
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all published theses for a given author name.
|
||||
* Returns rows of [id => int, title => string].
|
||||
*/
|
||||
public function getThesesByAuthorName(string $name): array {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"SELECT t.id, t.title
|
||||
FROM theses t
|
||||
JOIN thesis_authors ta ON ta.thesis_id = t.id
|
||||
JOIN authors a ON a.id = ta.author_id
|
||||
WHERE t.is_published = 1
|
||||
AND a.name = ?
|
||||
ORDER BY t.year DESC, t.title ASC"
|
||||
);
|
||||
$stmt->execute([$name]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function getAvailableYears() {
|
||||
$sql = "SELECT DISTINCT year FROM theses WHERE is_published = 1 ORDER BY year DESC";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
|
||||
@@ -107,6 +107,17 @@ class Dispatcher {
|
||||
};
|
||||
}
|
||||
|
||||
// /repertoire/student-preview (HTMX popover)
|
||||
if ($path === '/repertoire/student-preview') {
|
||||
return function() {
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/RateLimit.php';
|
||||
require_once APP_ROOT . '/src/Controllers/SearchController.php';
|
||||
$controller = SearchController::create();
|
||||
$controller->handleStudentPreview();
|
||||
};
|
||||
}
|
||||
|
||||
// /partage/*
|
||||
if (preg_match('#^/partage(/.*)?$#', $path)) {
|
||||
return function() {
|
||||
|
||||
Reference in New Issue
Block a user