api: add hidden day option
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/807/merge
parent
5820c53857
commit
51b096c194
|
@ -94,6 +94,7 @@ class DaysController extends GenericApiController
|
||||||
$dayIds,
|
$dayIds,
|
||||||
$this->isRecursive(),
|
$this->isRecursive(),
|
||||||
$this->isArchive(),
|
$this->isArchive(),
|
||||||
|
$this->isHidden(),
|
||||||
$this->getTransformations(),
|
$this->getTransformations(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ class DaysController extends GenericApiController
|
||||||
$preloadDayIds,
|
$preloadDayIds,
|
||||||
$this->isRecursive(),
|
$this->isRecursive(),
|
||||||
$this->isArchive(),
|
$this->isArchive(),
|
||||||
|
$this->isHidden(),
|
||||||
$transforms,
|
$transforms,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -276,6 +278,11 @@ class DaysController extends GenericApiController
|
||||||
return null !== $this->request->getParam('archive');
|
return null !== $this->request->getParam('archive');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isHidden()
|
||||||
|
{
|
||||||
|
return null !== $this->request->getParam('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
private function isMonthView()
|
private function isMonthView()
|
||||||
{
|
{
|
||||||
return null !== $this->request->getParam('monthView');
|
return null !== $this->request->getParam('monthView');
|
||||||
|
|
|
@ -60,6 +60,7 @@ trait TimelineQueryDays
|
||||||
* @param int[] $day_ids The day ids to fetch
|
* @param int[] $day_ids The day ids to fetch
|
||||||
* @param bool $recursive If the query should be recursive
|
* @param bool $recursive If the query should be recursive
|
||||||
* @param bool $archive If the query should include only the archive folder
|
* @param bool $archive If the query should include only the archive folder
|
||||||
|
* @param bool $hidden If the query should include hidden files
|
||||||
* @param array $queryTransforms The query transformations to apply
|
* @param array $queryTransforms The query transformations to apply
|
||||||
*
|
*
|
||||||
* @return array An array of day responses
|
* @return array An array of day responses
|
||||||
|
@ -68,6 +69,7 @@ trait TimelineQueryDays
|
||||||
?array $day_ids,
|
?array $day_ids,
|
||||||
bool $recursive,
|
bool $recursive,
|
||||||
bool $archive,
|
bool $archive,
|
||||||
|
bool $hidden,
|
||||||
array $queryTransforms = []
|
array $queryTransforms = []
|
||||||
): array {
|
): array {
|
||||||
$query = $this->connection->getQueryBuilder();
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
@ -82,6 +84,11 @@ trait TimelineQueryDays
|
||||||
->from('memories', 'm')
|
->from('memories', 'm')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// Add hidden field
|
||||||
|
if ($hidden) {
|
||||||
|
$query->addSelect('cte_f.hidden');
|
||||||
|
}
|
||||||
|
|
||||||
// JOIN with mimetypes to get the mimetype
|
// JOIN with mimetypes to get the mimetype
|
||||||
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
|
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
|
||||||
|
|
||||||
|
@ -104,7 +111,7 @@ trait TimelineQueryDays
|
||||||
$this->applyAllTransforms($queryTransforms, $query, false);
|
$this->applyAllTransforms($queryTransforms, $query, false);
|
||||||
|
|
||||||
// JOIN with filecache for existing files
|
// JOIN with filecache for existing files
|
||||||
$query = $this->joinFilecache($query, null, $recursive, $archive);
|
$query = $this->joinFilecache($query, null, $recursive, $archive, $hidden);
|
||||||
|
|
||||||
// FETCH all photos in this day
|
// FETCH all photos in this day
|
||||||
$day = $this->executeQueryWithCTEs($query)->fetchAll();
|
$day = $this->executeQueryWithCTEs($query)->fetchAll();
|
||||||
|
@ -124,9 +131,9 @@ trait TimelineQueryDays
|
||||||
$types = $query->getParameterTypes();
|
$types = $query->getParameterTypes();
|
||||||
|
|
||||||
// Get SQL
|
// Get SQL
|
||||||
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params) && $params['cteFoldersArchive']
|
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params)
|
||||||
? self::CTE_FOLDERS_ARCHIVE()
|
? self::CTE_FOLDERS_ARCHIVE()
|
||||||
: self::CTE_FOLDERS(false);
|
: self::CTE_FOLDERS(\array_key_exists('cteIncludeHidden', $params));
|
||||||
|
|
||||||
// Add WITH clause if needed
|
// Add WITH clause if needed
|
||||||
if (false !== strpos($sql, 'cte_folders')) {
|
if (false !== strpos($sql, 'cte_folders')) {
|
||||||
|
@ -143,12 +150,14 @@ trait TimelineQueryDays
|
||||||
* @param TimelineRoot $root Either the top folder or null for all
|
* @param TimelineRoot $root Either the top folder or null for all
|
||||||
* @param bool $recursive Whether to get the days recursively
|
* @param bool $recursive Whether to get the days recursively
|
||||||
* @param bool $archive Whether to get the days only from the archive folder
|
* @param bool $archive Whether to get the days only from the archive folder
|
||||||
|
* @param bool $hidden Whether to include hidden files
|
||||||
*/
|
*/
|
||||||
public function joinFilecache(
|
public function joinFilecache(
|
||||||
IQueryBuilder $query,
|
IQueryBuilder $query,
|
||||||
?TimelineRoot $root = null,
|
?TimelineRoot $root = null,
|
||||||
bool $recursive = true,
|
bool $recursive = true,
|
||||||
bool $archive = false
|
bool $archive = false,
|
||||||
|
bool $hidden = false
|
||||||
): IQueryBuilder {
|
): IQueryBuilder {
|
||||||
// This will throw if the root is illegally empty
|
// This will throw if the root is illegally empty
|
||||||
$root = $this->root($root);
|
$root = $this->root($root);
|
||||||
|
@ -163,7 +172,7 @@ trait TimelineQueryDays
|
||||||
$pathOp = null;
|
$pathOp = null;
|
||||||
if ($recursive) {
|
if ($recursive) {
|
||||||
// Join with folders CTE
|
// Join with folders CTE
|
||||||
$this->addSubfolderJoinParams($query, $root, $archive);
|
$this->addSubfolderJoinParams($query, $root, $archive, $hidden);
|
||||||
$query->innerJoin('f', 'cte_folders', 'cte_f', $query->expr()->eq('f.parent', 'cte_f.fileid'));
|
$query->innerJoin('f', 'cte_folders', 'cte_f', $query->expr()->eq('f.parent', 'cte_f.fileid'));
|
||||||
} else {
|
} else {
|
||||||
// If getting non-recursively folder only check for parent
|
// If getting non-recursively folder only check for parent
|
||||||
|
@ -230,6 +239,11 @@ trait TimelineQueryDays
|
||||||
// compute AUID and discard epoch and size
|
// compute AUID and discard epoch and size
|
||||||
$row['auid'] = Exif::getAUID($epoch, $size);
|
$row['auid'] = Exif::getAUID($epoch, $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get hidden field if present
|
||||||
|
if (\array_key_exists('hidden', $row)) {
|
||||||
|
$row['hidden'] = (bool) $row['hidden'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,10 +252,18 @@ trait TimelineQueryDays
|
||||||
private function addSubfolderJoinParams(
|
private function addSubfolderJoinParams(
|
||||||
IQueryBuilder &$query,
|
IQueryBuilder &$query,
|
||||||
TimelineRoot &$root,
|
TimelineRoot &$root,
|
||||||
bool $archive
|
bool $archive,
|
||||||
|
bool $hidden
|
||||||
) {
|
) {
|
||||||
// Add query parameters
|
// Add query parameters
|
||||||
$query->setParameter('topFolderIds', $root->getIds(), IQueryBuilder::PARAM_INT_ARRAY);
|
$query->setParameter('topFolderIds', $root->getIds(), IQueryBuilder::PARAM_INT_ARRAY);
|
||||||
$query->setParameter('cteFoldersArchive', $archive, IQueryBuilder::PARAM_BOOL);
|
|
||||||
|
if ($archive) {
|
||||||
|
$query->setParameter('cteFoldersArchive', true, IQueryBuilder::PARAM_BOOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hidden) {
|
||||||
|
$query->setParameter('cteIncludeHidden', true, IQueryBuilder::PARAM_BOOL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue