memories/lib/Db/TimelineQuerySingleItem.php

31 lines
881 B
PHP
Raw Normal View History

2023-03-10 17:30:56 +00:00
<?php
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
trait TimelineQuerySingleItem
{
protected IDBConnection $connection;
public function getSingleItem(int $fileId)
{
$query = $this->connection->getQueryBuilder();
$query->select('m.fileid', ...TimelineQuery::TIMELINE_SELECT)
->from('memories', 'm')
->where($query->expr()->eq('m.fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
;
// JOIN filecache for etag
$query->innerJoin('m', 'filecache', 'f', $query->expr()->eq('f.fileid', 'm.fileid'));
// JOIN with mimetypes to get the mimetype
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
return $query->executeQuery()->fetch();
}
}