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;
|
|
|
|
|
2023-10-13 23:18:37 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
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
|
2023-03-23 23:58:49 +00:00
|
|
|
$rows = $this->executeQueryWithCTEs($query)->fetchAll();
|
2022-11-07 04:48:10 +00:00
|
|
|
|
|
|
|
// Post-process
|
2023-03-23 23:58:49 +00:00
|
|
|
foreach ($rows as &$row) {
|
2022-11-07 04:48:10 +00:00
|
|
|
$row['fileid'] = (int) $row['fileid'];
|
|
|
|
}
|
|
|
|
|
2023-03-23 23:58:49 +00:00
|
|
|
return $rows;
|
2022-11-07 04:48:10 +00:00
|
|
|
}
|
|
|
|
}
|