Add systemtag transform
parent
4c38124ac8
commit
90ccce5477
|
@ -78,7 +78,13 @@ class ApiController extends Controller {
|
||||||
|
|
||||||
// Filter only videos
|
// Filter only videos
|
||||||
if ($this->request->getParam('vid')) {
|
if ($this->request->getParam('vid')) {
|
||||||
$transforms[] = array($this->timelineQuery, 'videoFilter');
|
$transforms[] = array($this->timelineQuery, 'transformVideoFilter');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter only for one tag
|
||||||
|
$tagName = $this->request->getParam('tag');
|
||||||
|
if ($tagName) {
|
||||||
|
$transforms[] = array($this->timelineQuery, 'transformTagFilter', $tagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $transforms;
|
return $transforms;
|
||||||
|
|
|
@ -126,9 +126,7 @@ trait TimelineQueryDays {
|
||||||
->orderBy('m.dayid', 'DESC');
|
->orderBy('m.dayid', 'DESC');
|
||||||
|
|
||||||
// Apply all transformations
|
// Apply all transformations
|
||||||
foreach ($queryTransforms as &$transform) {
|
$this->applyAllTransforms($queryTransforms, $query, $uid);
|
||||||
$transform($query, $uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cursor = $query->executeQuery();
|
$cursor = $query->executeQuery();
|
||||||
$rows = $cursor->fetchAll();
|
$rows = $cursor->fetchAll();
|
||||||
|
@ -174,9 +172,7 @@ trait TimelineQueryDays {
|
||||||
$query->orderBy('m.datetaken', 'DESC');
|
$query->orderBy('m.datetaken', 'DESC');
|
||||||
|
|
||||||
// Apply all transformations
|
// Apply all transformations
|
||||||
foreach ($queryTransforms as &$transform) {
|
$this->applyAllTransforms($queryTransforms, $query, $uid);
|
||||||
$transform($query, $uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cursor = $query->executeQuery();
|
$cursor = $query->executeQuery();
|
||||||
$rows = $cursor->fetchAll();
|
$rows = $cursor->fetchAll();
|
||||||
|
|
|
@ -7,14 +7,24 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\ITags;
|
use OCP\ITags;
|
||||||
|
|
||||||
trait TimelineQueryFilters {
|
trait TimelineQueryFilters {
|
||||||
public function transformFavoriteFilter(IQueryBuilder $query, string $userId) {
|
private function applyAllTransforms(array $transforms, IQueryBuilder &$query, string $uid): void {
|
||||||
|
foreach ($transforms as &$transform) {
|
||||||
|
$fun = array_slice($transform, 0, 2);
|
||||||
|
$params = array_slice($transform, 2);
|
||||||
|
array_unshift($params, $uid);
|
||||||
|
array_unshift($params, $query);
|
||||||
|
$fun(...$params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformFavoriteFilter(IQueryBuilder &$query, string $userId) {
|
||||||
$query->innerJoin('m', 'vcategory_to_object', 'vcoi', $query->expr()->andX(
|
$query->innerJoin('m', 'vcategory_to_object', 'vcoi', $query->expr()->andX(
|
||||||
$query->expr()->eq('vcoi.objid', 'm.fileid'),
|
$query->expr()->eq('vcoi.objid', 'm.fileid'),
|
||||||
$query->expr()->in('vcoi.categoryid', $this->getFavoriteVCategoryFun($query, $userId)),
|
$query->expr()->in('vcoi.categoryid', $this->getFavoriteVCategoryFun($query, $userId)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFavoriteTag(IQueryBuilder $query, string $userId) {
|
public function addFavoriteTag(IQueryBuilder &$query, string $userId) {
|
||||||
$query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->andX(
|
$query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->andX(
|
||||||
$query->expr()->eq('vco.objid', 'm.fileid'),
|
$query->expr()->eq('vco.objid', 'm.fileid'),
|
||||||
$query->expr()->in('vco.categoryid', $this->getFavoriteVCategoryFun($query, $userId)),
|
$query->expr()->in('vco.categoryid', $this->getFavoriteVCategoryFun($query, $userId)),
|
||||||
|
@ -31,7 +41,29 @@ trait TimelineQueryFilters {
|
||||||
))->getSQL());
|
))->getSQL());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function videoFilter(IQueryBuilder $query, string $userId) {
|
public function transformVideoFilter(IQueryBuilder &$query, string $userId) {
|
||||||
$query->andWhere($query->expr()->eq('m.isvideo', $query->createNamedParameter('1')));
|
$query->andWhere($query->expr()->eq('m.isvideo', $query->createNamedParameter('1')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSystemTagId(IQueryBuilder &$query, string $tagName) {
|
||||||
|
$sqb = $query->getConnection()->getQueryBuilder();
|
||||||
|
return $sqb->select('id')->from('systemtag')->where(
|
||||||
|
$sqb->expr()->andX(
|
||||||
|
$sqb->expr()->eq('name', $sqb->createNamedParameter($tagName)),
|
||||||
|
$sqb->expr()->eq('visibility', $sqb->createNamedParameter(1)),
|
||||||
|
))->executeQuery()->fetchOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformTagFilter(IQueryBuilder &$query, string $userId, string $tagName) {
|
||||||
|
$tagId = $this->getSystemTagId($query, $tagName);
|
||||||
|
if ($tagId === FALSE) {
|
||||||
|
$tagId = 0; // cannot abort here; that will show up everything in the response
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->innerJoin('m', 'systemtag_object_mapping', 'stom', $query->expr()->andX(
|
||||||
|
$query->expr()->eq('stom.objecttype', $query->createNamedParameter("files")),
|
||||||
|
$query->expr()->eq('stom.objectid', 'm.fileid'),
|
||||||
|
$query->expr()->eq('stom.systemtagid', $query->createNamedParameter($tagId)),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue