Add systemtag transform
parent
4c38124ac8
commit
90ccce5477
|
@ -78,7 +78,13 @@ class ApiController extends Controller {
|
|||
|
||||
// Filter only videos
|
||||
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;
|
||||
|
|
|
@ -126,9 +126,7 @@ trait TimelineQueryDays {
|
|||
->orderBy('m.dayid', 'DESC');
|
||||
|
||||
// Apply all transformations
|
||||
foreach ($queryTransforms as &$transform) {
|
||||
$transform($query, $uid);
|
||||
}
|
||||
$this->applyAllTransforms($queryTransforms, $query, $uid);
|
||||
|
||||
$cursor = $query->executeQuery();
|
||||
$rows = $cursor->fetchAll();
|
||||
|
@ -174,9 +172,7 @@ trait TimelineQueryDays {
|
|||
$query->orderBy('m.datetaken', 'DESC');
|
||||
|
||||
// Apply all transformations
|
||||
foreach ($queryTransforms as &$transform) {
|
||||
$transform($query, $uid);
|
||||
}
|
||||
$this->applyAllTransforms($queryTransforms, $query, $uid);
|
||||
|
||||
$cursor = $query->executeQuery();
|
||||
$rows = $cursor->fetchAll();
|
||||
|
|
|
@ -7,14 +7,24 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
|||
use OCP\ITags;
|
||||
|
||||
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->expr()->eq('vcoi.objid', 'm.fileid'),
|
||||
$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->expr()->eq('vco.objid', 'm.fileid'),
|
||||
$query->expr()->in('vco.categoryid', $this->getFavoriteVCategoryFun($query, $userId)),
|
||||
|
@ -31,7 +41,29 @@ trait TimelineQueryFilters {
|
|||
))->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')));
|
||||
}
|
||||
|
||||
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