mirror of
https://github.com/michaelstaake/mainty.git
synced 2026-04-16 19:40:13 +00:00
Initial version upload
This commit is contained in:
33
models/QuickTask.php
Normal file
33
models/QuickTask.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class QuickTask {
|
||||
private PDO $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = Database::getInstance();
|
||||
}
|
||||
|
||||
public function getAll(): array {
|
||||
$stmt = $this->db->query("SELECT * FROM quick_tasks ORDER BY name ASC");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function create(string $name): int {
|
||||
try {
|
||||
$stmt = $this->db->prepare("INSERT INTO quick_tasks (name) VALUES (?)");
|
||||
$stmt->execute([$name]);
|
||||
return (int)$this->db->lastInsertId();
|
||||
} catch (PDOException $e) {
|
||||
// Handle duplicate entry
|
||||
if ($e->getCode() == 23000) {
|
||||
return 0;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(int $id): bool {
|
||||
$stmt = $this->db->prepare("DELETE FROM quick_tasks WHERE id = ?");
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user