mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Rename Liens étudiant·e, add link name + edit dialog
- Rename 'Accès étudiant·e' → 'Liens étudiant·e' in acces.php - Add 'name' column to share_links (schema.sql + ALTER TABLE migration) - ShareLink::create() now accepts optional parameter - Add ShareLink::update() method for name/password/expiration - Add 'update' action to acces-etudiante.php controller - Remove Visiter (play) button; row click opens link in new tab - Add edit dialog with name, password, expiration fields - Add pen icon button to open edit dialog per row - Add Nom column to table (also in archived links section)
This commit is contained in:
@@ -49,7 +49,7 @@ class ShareLink
|
||||
* @param string|null $expiresAt ISO-8601 expiration date, null = never expires
|
||||
* @return array|null The created link row
|
||||
*/
|
||||
public function create(int $createdBy, ?string $password = null, ?string $expiresAt = null, ?string $objetRestriction = null): ?array
|
||||
public function create(int $createdBy, ?string $password = null, ?string $expiresAt = null, ?string $objetRestriction = null, ?string $name = null): ?array
|
||||
{
|
||||
$slug = self::generateSlug();
|
||||
$passwordHash = $password !== null ? password_hash($password, PASSWORD_BCRYPT) : null;
|
||||
@@ -62,10 +62,10 @@ class ShareLink
|
||||
}
|
||||
|
||||
$stmt = $this->db->getConnection()->prepare(
|
||||
'INSERT INTO share_links (slug, objet_restriction, password_hash, is_active, created_by, expires_at)
|
||||
VALUES (?, ?, ?, 1, ?, ?)'
|
||||
'INSERT INTO share_links (slug, name, objet_restriction, password_hash, is_active, created_by, expires_at)
|
||||
VALUES (?, ?, ?, ?, 1, ?, ?)'
|
||||
);
|
||||
$stmt->execute([$slug, $objetRestriction, $passwordHash, $createdBy, $expiresAt]);
|
||||
$stmt->execute([$slug, $name, $objetRestriction, $passwordHash, $createdBy, $expiresAt]);
|
||||
|
||||
return $this->findBySlug($slug);
|
||||
}
|
||||
@@ -185,6 +185,35 @@ class ShareLink
|
||||
)->execute([$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a share link (name, password, expiration).
|
||||
*/
|
||||
public function update(int $id, ?string $name = null, ?string $password = null, ?string $expiresAt = null): void
|
||||
{
|
||||
$pdo = $this->db->getConnection();
|
||||
$fields = [];
|
||||
$params = [];
|
||||
|
||||
if ($name !== null) {
|
||||
$fields[] = 'name = ?';
|
||||
$params[] = $name;
|
||||
}
|
||||
if ($password !== null) {
|
||||
$fields[] = 'password_hash = ?';
|
||||
$params[] = $password !== '' ? password_hash($password, PASSWORD_BCRYPT) : null;
|
||||
}
|
||||
if ($expiresAt !== null) {
|
||||
$expiresAtVal = $expiresAt !== '' ? date('Y-m-d H:i:s', strtotime($expiresAt)) : null;
|
||||
$fields[] = 'expires_at = ?';
|
||||
$params[] = $expiresAtVal;
|
||||
}
|
||||
|
||||
if (!empty($fields)) {
|
||||
$params[] = $id;
|
||||
$pdo->prepare('UPDATE share_links SET ' . implode(', ', $fields) . ' WHERE id = ?')->execute($params);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Validation ────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user