memories/lib/Db/TimelineQueryFolders.php

44 lines
1017 B
PHP
Raw Normal View History

2022-11-07 04:48:10 +00:00
<?php
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\Files\Folder;
use OCP\IDBConnection;
trait TimelineQueryFolders
{
protected IDBConnection $connection;
public function getFolderPreviews(Folder &$folder)
{
$query = $this->connection->getQueryBuilder();
// SELECT all photos
$query->select('f.fileid', 'f.etag')->from('memories', 'm');
// WHERE these photos are in the user's requested folder recursively
2022-11-16 07:45:01 +00:00
$root = new TimelineRoot();
$root->addFolder($folder);
$query = $this->joinFilecache($query, $root, true, false);
2022-11-07 04:48:10 +00:00
// ORDER descending by fileid
$query->orderBy('f.fileid', 'DESC');
// MAX 4
$query->setMaxResults(4);
// FETCH tag previews
$cursor = $this->executeQueryWithCTEs($query);
$ans = $cursor->fetchAll();
// Post-process
foreach ($ans as &$row) {
$row['fileid'] = (int) $row['fileid'];
}
return $ans;
}
}