memories/lib/Db/TimelineQueryFolders.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2022-11-07 04:48:10 +00:00
<?php
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\IDBConnection;
trait TimelineQueryFolders
{
protected IDBConnection $connection;
/**
* Get the previews inside a given TimelineRoot.
* The root folder passed to this function must already be populated
* with the mount points recursively, if this is desired.
*
* @param TimelineRoot $root The root to use for the query
*/
public function getRootPreviews(TimelineRoot $root): array
2022-11-07 04:48:10 +00:00
{
$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
$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
$rows = $this->executeQueryWithCTEs($query)->fetchAll();
2022-11-07 04:48:10 +00:00
// Post-process
foreach ($rows as &$row) {
2022-11-07 04:48:10 +00:00
$row['fileid'] = (int) $row['fileid'];
}
return $rows;
2022-11-07 04:48:10 +00:00
}
}