2023-03-10 17:30:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\Memories\Db;
|
|
|
|
|
2023-03-28 01:53:01 +00:00
|
|
|
use OCA\Memories\ClustersBackend\PlacesBackend;
|
|
|
|
use OCA\Memories\Util;
|
2023-03-10 17:30:56 +00:00
|
|
|
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'));
|
|
|
|
|
2023-03-25 14:58:03 +00:00
|
|
|
// FETCH the photo
|
|
|
|
$photo = $query->executeQuery()->fetch();
|
|
|
|
|
|
|
|
// Post process the record
|
|
|
|
$this->processDayPhoto($photo);
|
|
|
|
|
|
|
|
return $photo;
|
2023-03-10 17:30:56 +00:00
|
|
|
}
|
2023-03-23 23:58:49 +00:00
|
|
|
|
|
|
|
public function getInfoById(int $id, bool $basic): array
|
|
|
|
{
|
|
|
|
$qb = $this->connection->getQueryBuilder();
|
|
|
|
$qb->select('fileid', 'dayid', 'datetaken', 'w', 'h')
|
|
|
|
->from('memories')
|
|
|
|
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!$basic) {
|
|
|
|
$qb->addSelect('exif');
|
|
|
|
}
|
|
|
|
|
2023-03-24 01:12:39 +00:00
|
|
|
$row = $qb->executeQuery()->fetch();
|
2023-03-23 23:58:49 +00:00
|
|
|
|
2023-04-16 18:27:40 +00:00
|
|
|
// Basic information to return
|
|
|
|
$info = [
|
|
|
|
'fileid' => (int) $row['fileid'],
|
|
|
|
'dayid' => (int) $row['dayid'],
|
|
|
|
'w' => (int) $row['w'],
|
|
|
|
'h' => (int) $row['h'],
|
|
|
|
'datetaken' => (int) $row['datetaken'],
|
|
|
|
];
|
2023-03-23 23:58:49 +00:00
|
|
|
|
2023-04-16 18:27:40 +00:00
|
|
|
// Attempt to get the date in the correct timezone
|
2023-03-23 23:58:49 +00:00
|
|
|
try {
|
|
|
|
$utcDate = new \DateTime($row['datetaken'], new \DateTimeZone('UTC'));
|
2023-04-16 18:27:40 +00:00
|
|
|
$info['datetaken'] = $utcDate->getTimestamp();
|
2023-03-23 23:58:49 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-04-16 18:27:40 +00:00
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return if only basic info is needed
|
|
|
|
if ($basic) {
|
|
|
|
return $info;
|
2023-03-23 23:58:49 +00:00
|
|
|
}
|
|
|
|
|
2023-04-16 18:27:40 +00:00
|
|
|
// Get exif data for metadata
|
|
|
|
if (!empty($row['exif'])) {
|
2023-03-23 23:58:49 +00:00
|
|
|
try {
|
2023-04-16 18:27:40 +00:00
|
|
|
$info['exif'] = json_decode($row['exif'], true);
|
2023-03-23 23:58:49 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-04-16 18:27:40 +00:00
|
|
|
// Ignore
|
2023-03-23 23:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-28 01:53:01 +00:00
|
|
|
// Get address from places
|
2023-04-16 18:27:40 +00:00
|
|
|
if (Util::placesGISType() > 0) {
|
2023-03-23 23:58:49 +00:00
|
|
|
$qb = $this->connection->getQueryBuilder();
|
2023-03-28 01:53:01 +00:00
|
|
|
$qb->select('e.name', 'e.other_names')
|
2023-03-23 23:58:49 +00:00
|
|
|
->from('memories_places', 'mp')
|
|
|
|
->innerJoin('mp', 'memories_planet', 'e', $qb->expr()->eq('mp.osm_id', 'e.osm_id'))
|
|
|
|
->where($qb->expr()->eq('mp.fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
|
2023-04-25 05:07:58 +00:00
|
|
|
->andWhere($qb->expr()->gt('e.admin_level', $qb->expr()->literal(0, \PDO::PARAM_INT)))
|
2023-03-23 23:58:49 +00:00
|
|
|
->orderBy('e.admin_level', 'DESC')
|
|
|
|
;
|
2023-03-28 01:53:01 +00:00
|
|
|
|
|
|
|
$places = $qb->executeQuery()->fetchAll();
|
|
|
|
$lang = Util::getUserLang();
|
2023-03-23 23:58:49 +00:00
|
|
|
if (\count($places) > 0) {
|
2023-03-28 01:53:01 +00:00
|
|
|
$places = array_map(fn ($p) => PlacesBackend::choosePlaceLang($p, $lang)['name'], $places);
|
2023-04-16 18:27:40 +00:00
|
|
|
$info['address'] = implode(', ', $places);
|
2023-03-23 23:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-16 18:27:40 +00:00
|
|
|
return $info;
|
2023-03-23 23:58:49 +00:00
|
|
|
}
|
2023-03-10 17:30:56 +00:00
|
|
|
}
|