aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Timeline/GlobalTimeline.php
blob: 278b557cae32b589373105e15bdfe838dc621087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
namespace Digitigrade\Timeline;

use Digitigrade\Db;
use Digitigrade\Model\Note;
use Digitigrade\Timeline;
use Digitigrade\TimelineItem;

class GlobalTimeline extends Timeline {
    protected function getItems(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 AND note.deleted = false
        ORDER BY note.created DESC LIMIT ? OFFSET ?
        END);
        $stmt->execute([$limit, $offset]);
        $ids = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
        return array_map(fn($id) => new TimelineItem(Note::find($id)), $ids);
    }
}