aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade
diff options
context:
space:
mode:
authorwinter2024-12-23 16:48:58 +0000
committerwinter2024-12-23 16:48:58 +0000
commit094b1d010253f1a9a114303d823739e513834742 (patch)
treebe6a420fb695c4ab45b4e257dfb84e8cbcbadaa4 /Digitigrade
parent3272de09352d1583ea817187d13a7a548e360296 (diff)
better timeline system
Diffstat (limited to 'Digitigrade')
-rw-r--r--Digitigrade/Timeline.php29
-rw-r--r--Digitigrade/Timeline/GlobalTimeline.php18
2 files changed, 47 insertions, 0 deletions
diff --git a/Digitigrade/Timeline.php b/Digitigrade/Timeline.php
new file mode 100644
index 0000000..67708ab
--- /dev/null
+++ b/Digitigrade/Timeline.php
@@ -0,0 +1,29 @@
+<?php
+namespace Digitigrade;
+
+use Digitigrade\Model\Note;
+
+abstract class Timeline {
+ // TODO: currently making this number up. probably should be modifiable somewhere
+ private const RESULTS_PER_PAGE = 50;
+
+ /**
+ * Gets a pageful of note IDs to be included in this timeline
+ * @param int $limit maximum number of results to return
+ * @param int $offset number of results to skip (i.e. results from previous pages)
+ * @return int[]
+ */
+ protected abstract function getNoteIds(int $limit, int $offset): array;
+
+ /**
+ * Gets a pageful of notes that are included in this timeline
+ * @param int $page page number to return (0-indexed)
+ * @return Note[]
+ */
+ public function getNotes(int $page = 0): array {
+ $ids = $this->getNoteIds(self::RESULTS_PER_PAGE, self::RESULTS_PER_PAGE * $page);
+ return array_map(function (int $id) {
+ return Note::find($id);
+ }, $ids);
+ }
+} \ No newline at end of file
diff --git a/Digitigrade/Timeline/GlobalTimeline.php b/Digitigrade/Timeline/GlobalTimeline.php
new file mode 100644
index 0000000..b495174
--- /dev/null
+++ b/Digitigrade/Timeline/GlobalTimeline.php
@@ -0,0 +1,18 @@
+<?php
+namespace Digitigrade\Timeline;
+
+use Digitigrade\Db;
+use Digitigrade\Timeline;
+
+class GlobalTimeline extends Timeline {
+ protected function getNoteIds(int $limit, int $offset): array {
+ $db = Db::getInstance()->getPdo();
+ $stmt = $db->prepare(<<<END
+ SELECT note.id FROM note LEFT JOIN note_privacy ON note_privacy.note_id = note.id
+ WHERE note_privacy.scope = 'public' AND note_privacy.indexable = true
+ ORDER BY note.created DESC LIMIT ? OFFSET ?
+ END);
+ $stmt->execute([$limit, $offset]);
+ return $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
+ }
+} \ No newline at end of file