2022-08-20 02:53:21 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\Memories\Db;
|
|
|
|
|
|
|
|
use OCA\Memories\Exif;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
class TimelineQuery {
|
|
|
|
protected IDBConnection $connection;
|
|
|
|
|
|
|
|
public function __construct(IDBConnection $connection) {
|
|
|
|
$this->connection = $connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the days response
|
|
|
|
* @param array $days
|
|
|
|
*/
|
|
|
|
private function processDays(&$days) {
|
|
|
|
foreach($days as &$row) {
|
2022-08-20 21:28:41 +00:00
|
|
|
$row["dayid"] = intval($row["dayid"]);
|
2022-08-20 02:53:21 +00:00
|
|
|
$row["count"] = intval($row["count"]);
|
|
|
|
}
|
|
|
|
return $days;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the days response from the database for the timeline
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param string $userId
|
|
|
|
*/
|
|
|
|
public function getDays(
|
|
|
|
IConfig &$config,
|
2022-08-22 18:48:35 +00:00
|
|
|
string &$user): array {
|
|
|
|
|
2022-08-20 21:28:41 +00:00
|
|
|
$sql = 'SELECT `*PREFIX*memories`.`dayid`, COUNT(`*PREFIX*memories`.`fileid`) AS count
|
2022-08-20 02:53:21 +00:00
|
|
|
FROM `*PREFIX*memories`
|
|
|
|
INNER JOIN `*PREFIX*filecache`
|
2022-08-20 21:28:41 +00:00
|
|
|
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
|
2022-08-20 02:53:21 +00:00
|
|
|
AND `*PREFIX*filecache`.`path` LIKE ?
|
2022-08-20 21:28:41 +00:00
|
|
|
WHERE uid=?
|
|
|
|
GROUP BY `*PREFIX*memories`.`dayid`
|
|
|
|
ORDER BY `*PREFIX*memories`.`dayid` DESC';
|
2022-08-20 02:53:21 +00:00
|
|
|
|
|
|
|
$path = "files" . Exif::getPhotosPath($config, $user) . "%";
|
|
|
|
$rows = $this->connection->executeQuery($sql, [$path, $user], [
|
|
|
|
\PDO::PARAM_STR, \PDO::PARAM_STR,
|
|
|
|
])->fetchAll();
|
|
|
|
return $this->processDays($rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the days response from the database for one folder
|
|
|
|
* @param int $folderId
|
|
|
|
*/
|
|
|
|
public function getDaysFolder(int &$folderId) {
|
2022-08-20 21:28:41 +00:00
|
|
|
$sql = 'SELECT `*PREFIX*memories`.`dayid`, COUNT(`*PREFIX*memories`.`fileid`) AS count
|
2022-08-20 02:53:21 +00:00
|
|
|
FROM `*PREFIX*memories`
|
|
|
|
INNER JOIN `*PREFIX*filecache`
|
2022-08-20 21:28:41 +00:00
|
|
|
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
|
2022-08-20 02:53:21 +00:00
|
|
|
AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?)
|
2022-08-20 21:28:41 +00:00
|
|
|
GROUP BY dayid
|
|
|
|
ORDER BY dayid DESC';
|
2022-08-20 02:53:21 +00:00
|
|
|
$rows = $this->connection->executeQuery($sql, [$folderId, $folderId], [
|
|
|
|
\PDO::PARAM_INT, \PDO::PARAM_INT,
|
|
|
|
])->fetchAll();
|
|
|
|
return $this->processDays($rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the single day response
|
|
|
|
* @param array $day
|
|
|
|
*/
|
|
|
|
private function processDay(&$day) {
|
|
|
|
foreach($day as &$row) {
|
2022-08-20 21:28:41 +00:00
|
|
|
$row["fileid"] = intval($row["fileid"]);
|
|
|
|
$row["isvideo"] = intval($row["isvideo"]);
|
|
|
|
if (!$row["isvideo"]) {
|
|
|
|
unset($row["isvideo"]);
|
2022-08-20 02:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $day;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a day response from the database for the timeline
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param string $userId
|
|
|
|
* @param int $dayId
|
|
|
|
*/
|
|
|
|
public function getDay(
|
|
|
|
IConfig &$config,
|
|
|
|
string &$user,
|
2022-08-22 18:48:35 +00:00
|
|
|
int &$dayId): array {
|
|
|
|
|
2022-08-20 21:28:41 +00:00
|
|
|
$sql = 'SELECT `*PREFIX*memories`.`fileid`, *PREFIX*filecache.etag, `*PREFIX*memories`.`isvideo`
|
2022-08-20 02:53:21 +00:00
|
|
|
FROM *PREFIX*memories
|
|
|
|
INNER JOIN *PREFIX*filecache
|
2022-08-20 21:28:41 +00:00
|
|
|
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
|
2022-08-20 02:53:21 +00:00
|
|
|
AND `*PREFIX*filecache`.`path` LIKE ?
|
2022-08-20 21:28:41 +00:00
|
|
|
WHERE `*PREFIX*memories`.`uid` = ? AND `*PREFIX*memories`.`dayid` = ?
|
|
|
|
ORDER BY `*PREFIX*memories`.`datetaken` DESC';
|
2022-08-20 02:53:21 +00:00
|
|
|
|
|
|
|
$path = "files" . Exif::getPhotosPath($config, $user) . "%";
|
|
|
|
$rows = $this->connection->executeQuery($sql, [$path, $user, $dayId], [
|
|
|
|
\PDO::PARAM_STR, \PDO::PARAM_STR, \PDO::PARAM_INT,
|
|
|
|
])->fetchAll();
|
|
|
|
return $this->processDay($rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a day response from the database for one folder
|
|
|
|
* @param int $folderId
|
|
|
|
* @param int $dayId
|
|
|
|
*/
|
|
|
|
public function getDayFolder(
|
|
|
|
int &$folderId,
|
2022-08-22 18:48:35 +00:00
|
|
|
int &$dayId): array {
|
|
|
|
|
2022-08-20 21:28:41 +00:00
|
|
|
$sql = 'SELECT `*PREFIX*memories`.`fileid`, `*PREFIX*filecache`.`etag`, `*PREFIX*memories`.`isvideo`
|
2022-08-20 02:53:21 +00:00
|
|
|
FROM `*PREFIX*memories`
|
|
|
|
INNER JOIN `*PREFIX*filecache`
|
2022-08-20 21:28:41 +00:00
|
|
|
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
|
2022-08-20 02:53:21 +00:00
|
|
|
AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?)
|
2022-08-23 09:59:56 +00:00
|
|
|
WHERE `*PREFIX*memories`.`dayid`=?
|
|
|
|
ORDER BY `*PREFIX*memories`.`datetaken` DESC';
|
2022-08-20 02:53:21 +00:00
|
|
|
$rows = $this->connection->executeQuery($sql, [$folderId, $folderId, $dayId], [
|
|
|
|
\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT,
|
|
|
|
])->fetchAll();
|
|
|
|
return $this->processDay($rows);
|
|
|
|
}
|
|
|
|
}
|