mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
formulaire: default interne, unpublished, contact toggle, settings section
This commit is contained in:
@@ -809,21 +809,24 @@ class Database {
|
||||
/**
|
||||
* Find or create an author
|
||||
*/
|
||||
public function findOrCreateAuthor($name, $email = null) {
|
||||
public function findOrCreateAuthor($name, $email = null, bool $showContact = false) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM authors WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$author = $stmt->fetch();
|
||||
|
||||
if ($author) {
|
||||
if ($email && $email !== '') {
|
||||
$updateStmt = $this->pdo->prepare("UPDATE authors SET email = ? WHERE id = ?");
|
||||
$updateStmt->execute([$email, $author['id']]);
|
||||
$updateStmt = $this->pdo->prepare("UPDATE authors SET email = ?, show_contact = ? WHERE id = ?");
|
||||
$updateStmt->execute([$email, $showContact ? 1 : 0, $author['id']]);
|
||||
} else {
|
||||
$updateStmt = $this->pdo->prepare("UPDATE authors SET show_contact = ? WHERE id = ?");
|
||||
$updateStmt->execute([$showContact ? 1 : 0, $author['id']]);
|
||||
}
|
||||
return $author['id'];
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare("INSERT INTO authors (name, email) VALUES (?, ?)");
|
||||
$stmt->execute([$name, $email]);
|
||||
$stmt = $this->pdo->prepare("INSERT INTO authors (name, email, show_contact) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$name, $email, $showContact ? 1 : 0]);
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
@@ -1048,6 +1051,77 @@ class Database {
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// SITE SETTINGS
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Get a single site setting value by key. Returns $default if not found.
|
||||
*/
|
||||
public function getSetting(string $key, string $default = ''): string {
|
||||
$stmt = $this->pdo->prepare("SELECT value FROM site_settings WHERE key = ? LIMIT 1");
|
||||
$stmt->execute([$key]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ? (string) $row['value'] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all site settings as an associative array [ key => value ].
|
||||
*/
|
||||
public function getAllSettings(): array {
|
||||
$stmt = $this->pdo->query("SELECT key, value FROM site_settings");
|
||||
$rows = $stmt->fetchAll();
|
||||
$out = [];
|
||||
foreach ($rows as $r) {
|
||||
$out[$r['key']] = $r['value'];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a site setting.
|
||||
*/
|
||||
public function setSetting(string $key, string $value): void {
|
||||
$this->pdo->prepare(
|
||||
"INSERT INTO site_settings (key, value, updated_at)
|
||||
VALUES (?, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP"
|
||||
)->execute([$key, $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return access types that are enabled in the add-thesis form,
|
||||
* filtered by site_settings toggles.
|
||||
* 'Libre' (id=1) is excluded unless access_type_libre_enabled = '1'.
|
||||
* 'Interne' (id=2) is excluded unless access_type_interne_enabled = '1'.
|
||||
* 'Interdit' (id=3) is excluded unless access_type_interdit_enabled = '1'.
|
||||
*/
|
||||
public function getEnabledFormAccessTypes(): array {
|
||||
$settings = $this->getAllSettings();
|
||||
$all = $this->getAccessTypes();
|
||||
$map = [
|
||||
'Libre' => $settings['access_type_libre_enabled'] ?? '0',
|
||||
'Interne' => $settings['access_type_interne_enabled'] ?? '1',
|
||||
'Interdit' => $settings['access_type_interdit_enabled'] ?? '1',
|
||||
];
|
||||
return array_values(array_filter($all, fn($at) => ($map[$at['name']] ?? '0') === '1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the show_contact flag for the first author of a thesis.
|
||||
*/
|
||||
public function setAuthorShowContact(int $thesisId, bool $show): void {
|
||||
$stmt = $this->pdo->prepare(
|
||||
"UPDATE authors SET show_contact = ?
|
||||
WHERE id = (
|
||||
SELECT author_id FROM thesis_authors
|
||||
WHERE thesis_id = ?
|
||||
ORDER BY author_order LIMIT 1
|
||||
)"
|
||||
);
|
||||
$stmt->execute([$show ? 1 : 0, $thesisId]);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// JURY METHODS
|
||||
// ========================================================================
|
||||
@@ -1439,7 +1513,8 @@ class Database {
|
||||
foreach ($authors as $index => $author) {
|
||||
$name = trim($author['name'] ?? '');
|
||||
if ($name === '') continue;
|
||||
$authorId = $this->findOrCreateAuthor($name, $author['email'] ?? null);
|
||||
$showContact = !empty($author['show_contact']);
|
||||
$authorId = $this->findOrCreateAuthor($name, $author['email'] ?? null, $showContact);
|
||||
$stmt->execute([$thesisId, $authorId, $index + 1]);
|
||||
}
|
||||
}
|
||||
@@ -1453,8 +1528,10 @@ class Database {
|
||||
orientation_id, ap_program_id, finality_id,
|
||||
synopsis, file_size_info,
|
||||
baiu_link, license_id,
|
||||
access_type_id,
|
||||
is_published,
|
||||
submitted_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, CURRENT_TIMESTAMP)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
@@ -1469,6 +1546,7 @@ class Database {
|
||||
!empty($data['file_size_info']) ? $data['file_size_info'] : null,
|
||||
!empty($data['baiu_link']) ? $data['baiu_link'] : null,
|
||||
isset($data['license_id']) ? $data['license_id'] : null,
|
||||
isset($data['access_type_id']) ? (int)$data['access_type_id'] : 2, // default: Interne
|
||||
]);
|
||||
|
||||
$thesisId = (int)$this->pdo->lastInsertId();
|
||||
|
||||
Reference in New Issue
Block a user