memories/lib/Db/TimelineQuery.php

51 lines
1.1 KiB
PHP
Raw Normal View History

2022-08-20 02:53:21 +00:00
<?php
2022-10-19 17:10:36 +00:00
2022-08-20 02:53:21 +00:00
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\IDBConnection;
2022-10-19 17:10:36 +00:00
class TimelineQuery
{
2022-10-26 23:20:28 +00:00
use TimelineQueryAlbums;
2022-09-11 02:05:04 +00:00
use TimelineQueryDays;
2022-10-19 17:10:36 +00:00
use TimelineQueryFaces;
2022-09-13 07:55:32 +00:00
use TimelineQueryFilters;
2022-10-06 21:37:18 +00:00
use TimelineQueryTags;
2022-09-11 02:05:04 +00:00
2022-09-09 07:31:42 +00:00
protected IDBConnection $connection;
2022-08-20 02:53:21 +00:00
2022-10-19 17:10:36 +00:00
public function __construct(IDBConnection $connection)
{
2022-09-09 07:31:42 +00:00
$this->connection = $connection;
}
2022-09-25 13:21:40 +00:00
2022-10-19 17:10:36 +00:00
public function getInfoById(int $id): array
{
2022-09-25 13:21:40 +00:00
$qb = $this->connection->getQueryBuilder();
2022-09-27 21:36:23 +00:00
$qb->select('fileid', 'dayid', 'datetaken')
2022-09-25 13:21:40 +00:00
->from('memories')
2022-10-19 17:10:36 +00:00
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
;
2022-09-25 13:21:40 +00:00
$result = $qb->executeQuery();
$row = $result->fetch();
$result->closeCursor();
2022-09-27 21:36:23 +00:00
$utcTs = 0;
2022-10-19 17:10:36 +00:00
2022-09-27 21:36:23 +00:00
try {
$utcDate = new \DateTime($row['datetaken'], new \DateTimeZone('UTC'));
$utcTs = $utcDate->getTimestamp();
2022-10-19 17:10:36 +00:00
} catch (\Throwable $e) {
}
2022-09-27 21:36:23 +00:00
2022-09-25 13:21:40 +00:00
return [
2022-10-19 17:15:14 +00:00
'fileid' => (int) $row['fileid'],
'dayid' => (int) $row['dayid'],
2022-09-27 21:36:23 +00:00
'datetaken' => $utcTs,
2022-09-25 13:21:40 +00:00
];
}
2022-10-19 17:10:36 +00:00
}