memories/lib/Db/TimelineQueryFavorites.php

35 lines
1.5 KiB
PHP
Raw Normal View History

2022-09-12 01:33:38 +00:00
<?php
declare(strict_types=1);
namespace OCA\Memories\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
2022-09-12 03:03:04 +00:00
use OCP\ITags;
2022-09-12 01:33:38 +00:00
trait TimelineQueryFavorites {
2022-09-12 03:03:04 +00:00
public function transformFavoriteFilter(IQueryBuilder $query, string $userId) {
// Inner join will filter only the favorites
2022-09-12 03:46:31 +00:00
$query->innerJoin('m', 'vcategory_to_object', 'fvco', $query->expr()->eq('fvco.objid', 'm.fileid'));
2022-09-12 03:03:04 +00:00
// Get the favorites category only
2022-09-12 03:46:31 +00:00
$query->innerJoin('fvco', 'vcategory', 'fvc', $query->expr()->andX(
$query->expr()->eq('fvc.id', 'fvco.categoryid'),
$query->expr()->eq('fvc.type', $query->createNamedParameter("files")),
$query->expr()->eq('fvc.uid', $query->createNamedParameter($userId)),
$query->expr()->eq('fvc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)),
));
}
public function addFavoriteTag(IQueryBuilder $query, string $userId) {
// Inner join will filter only the favorites
$query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid'));
// Get the favorites category only
$query->leftJoin('vco', 'vcategory', 'vc', $query->expr()->andX(
2022-09-12 03:03:04 +00:00
$query->expr()->eq('vc.id', 'vco.categoryid'),
2022-09-12 03:46:31 +00:00
$query->expr()->eq('vc.type', $query->createNamedParameter("files")),
2022-09-12 03:03:04 +00:00
$query->expr()->eq('vc.uid', $query->createNamedParameter($userId)),
$query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)),
));
2022-09-12 01:33:38 +00:00
}
}