memories/lib/Db/TimelineQueryFolders.php

43 lines
996 B
PHP
Raw Permalink Normal View History

2022-11-07 04:48:10 +00:00
<?php
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\Files\FileInfo;
2022-11-07 04:48:10 +00:00
use OCP\IDBConnection;
trait TimelineQueryFolders
{
protected IDBConnection $connection;
public function getFolderPreviews(FileInfo $folder)
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
$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
$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
}
}