diff options
| author | winter | 2025-03-22 19:41:55 +0000 |
|---|---|---|
| committer | winter | 2025-03-22 19:41:55 +0000 |
| commit | 39fcc5d52ac4c6e76ff87d95ef5b4b63300fe071 (patch) | |
| tree | 75b83a228906064e80160359a76fa3820a9449eb /Digitigrade | |
| parent | b535baf69b9a2525bc8a33b9c96460b84af8e6e2 (diff) | |
implement editing pages
Diffstat (limited to 'Digitigrade')
| -rw-r--r-- | Digitigrade/Model/Note.php | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 9a7aa4c..0f75f5b 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -197,25 +197,30 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return $notes; } - public static function findAllWithExtension(string $extensionUri, ?int $limit = null, int $offset = 0): array { + public static function findAllWithExtension(string $extensionUri, ?int $limit = null, int $offset = 0, bool $includeDeleted = false): array { $pdo = Db::getInstance()->getPdo(); - $query = 'SELECT note_id FROM note_extension LEFT JOIN note ON note.id = note_id ' - . 'WHERE note_extension.uri = ? ORDER BY note.created DESC'; + $query = 'SELECT note.* FROM note_extension LEFT JOIN note ON note.id = note_id ' + . 'WHERE note_extension.uri = ?'; + if (!$includeDeleted) { + $query .= ' AND note.deleted = false'; + } + $query .= ' ORDER BY note.created DESC'; if ($limit != null) { $query .= " LIMIT $limit OFFSET $offset"; } $stmt = $pdo->prepare($query); $stmt->execute([$extensionUri]); $notes = []; - while ($id = $stmt->fetchColumn(0)) { - $notes[] = self::find($id); + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $notes[] = self::fromDbRow($row); } return $notes; } - public static function countWithExtension(string $extensionUri): int { + public static function countWithExtension(string $extensionUri, bool $includeDeleted = false): int { $pdo = Db::getInstance()->getPdo(); - $stmt = $pdo->prepare('SELECT COUNT(*) FROM note_extension WHERE uri = ?'); + $stmt = $pdo->prepare('SELECT COUNT(*) FROM note_extension LEFT JOIN note ON note_id = note.id WHERE note_extension.uri = ?' + . ($includeDeleted ? '' : ' AND note.deleted = false')); $stmt->execute([$extensionUri]); return $stmt->fetchColumn(0); } |
