Allow wildcard day query
parent
66f479844e
commit
68a40ffbc7
|
@ -208,10 +208,21 @@ class ApiController extends Controller {
|
||||||
}
|
}
|
||||||
$uid = $user->getUID();
|
$uid = $user->getUID();
|
||||||
|
|
||||||
// Split at commas and convert all parts to int
|
// Check for wildcard
|
||||||
$day_ids = array_map(function ($part) {
|
$day_ids = [];
|
||||||
return intval($part);
|
if ($id === "*") {
|
||||||
}, explode(",", $id));
|
$day_ids = null;
|
||||||
|
} else {
|
||||||
|
// Split at commas and convert all parts to int
|
||||||
|
$day_ids = array_map(function ($part) {
|
||||||
|
return intval($part);
|
||||||
|
}, explode(",", $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if $day_ids is empty
|
||||||
|
if (!is_null($day_ids) && count($day_ids) === 0) {
|
||||||
|
return new JSONResponse([], Http::STATUS_OK);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the folder to show
|
// Get the folder to show
|
||||||
$folder = $this->getRequestFolder();
|
$folder = $this->getRequestFolder();
|
||||||
|
|
|
@ -147,7 +147,7 @@ trait TimelineQueryDays {
|
||||||
public function getDay(
|
public function getDay(
|
||||||
Folder &$folder,
|
Folder &$folder,
|
||||||
string $uid,
|
string $uid,
|
||||||
array $day_ids,
|
$day_ids,
|
||||||
bool $recursive,
|
bool $recursive,
|
||||||
bool $archive,
|
bool $archive,
|
||||||
array $queryTransforms = []
|
array $queryTransforms = []
|
||||||
|
@ -162,8 +162,15 @@ trait TimelineQueryDays {
|
||||||
// when using DISTINCT on selected fields
|
// when using DISTINCT on selected fields
|
||||||
$query->select($fileid, 'f.etag', 'm.isvideo', 'vco.categoryid', 'm.datetaken', 'm.dayid')
|
$query->select($fileid, 'f.etag', 'm.isvideo', 'vco.categoryid', 'm.datetaken', 'm.dayid')
|
||||||
->from('memories', 'm')
|
->from('memories', 'm')
|
||||||
->innerJoin('m', 'filecache', 'f', $this->getFilecacheJoinQuery($query, $folder, $recursive, $archive))
|
->innerJoin('m', 'filecache', 'f', $this->getFilecacheJoinQuery($query, $folder, $recursive, $archive));
|
||||||
->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY)));
|
|
||||||
|
// Filter by dayid unless wildcard
|
||||||
|
if (!is_null($day_ids)) {
|
||||||
|
$query->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY)));
|
||||||
|
} else {
|
||||||
|
// Limit wildcard to 100 results
|
||||||
|
$query->setMaxResults(100);
|
||||||
|
}
|
||||||
|
|
||||||
// Add favorite field
|
// Add favorite field
|
||||||
$this->addFavoriteTag($query, $uid);
|
$this->addFavoriteTag($query, $uid);
|
||||||
|
|
|
@ -46,6 +46,10 @@ trait TimelineQueryFilters {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transformLimitDay(IQueryBuilder &$query, string $userId, int $limit) {
|
public function transformLimitDay(IQueryBuilder &$query, string $userId, int $limit) {
|
||||||
|
// The valid range for limit is 1 - 100; otherwise abort
|
||||||
|
if ($limit < 1 || $limit > 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$query->setMaxResults($limit);
|
$query->setMaxResults($limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue