support more complex metafield queries (#3228)
This commit is contained in:
@@ -16,6 +16,7 @@ use App\Entity\ProjectRate;
|
||||
use App\Entity\RateInterface;
|
||||
use App\Entity\Team;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Model\Statistic\Day;
|
||||
use App\Model\Statistic\Month;
|
||||
@@ -41,6 +42,8 @@ use Pagerfanta\Pagerfanta;
|
||||
*/
|
||||
class TimesheetRepository extends EntityRepository
|
||||
{
|
||||
use RepositorySearchTrait;
|
||||
|
||||
public const STATS_QUERY_DURATION = 'duration';
|
||||
public const STATS_QUERY_RATE = 'rate';
|
||||
public const STATS_QUERY_USER = 'users';
|
||||
@@ -1001,33 +1004,7 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
$requiresTeams = $this->addPermissionCriteria($qb, $query->getCurrentUser(), $query->getTeams());
|
||||
|
||||
if ($query->hasSearchTerm()) {
|
||||
$searchAnd = $qb->expr()->andX();
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
|
||||
foreach ($searchTerm->getSearchFields() as $metaName => $metaValue) {
|
||||
$qb->leftJoin('t.meta', 'meta');
|
||||
$searchAnd->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('meta.name', ':metaName'),
|
||||
$qb->expr()->like('meta.value', ':metaValue')
|
||||
)
|
||||
);
|
||||
$qb->setParameter('metaName', $metaName);
|
||||
$qb->setParameter('metaValue', '%' . $metaValue . '%');
|
||||
}
|
||||
|
||||
if ($searchTerm->hasSearchTerm()) {
|
||||
$searchAnd->add(
|
||||
$qb->expr()->like('t.description', ':searchTerm')
|
||||
);
|
||||
$qb->setParameter('searchTerm', '%' . $searchTerm->getSearchTerm() . '%');
|
||||
}
|
||||
|
||||
if ($searchAnd->count() > 0) {
|
||||
$qb->andWhere($searchAnd);
|
||||
}
|
||||
}
|
||||
$this->addSearchTerm($qb, $query);
|
||||
|
||||
if ($requiresCustomer || $requiresProject || $requiresTeams) {
|
||||
$qb->leftJoin('t.project', 'p');
|
||||
@@ -1048,6 +1025,24 @@ class TimesheetRepository extends EntityRepository
|
||||
return $qb;
|
||||
}
|
||||
|
||||
private function getMetaFieldClass(): string
|
||||
{
|
||||
return TimesheetMeta::class;
|
||||
}
|
||||
|
||||
private function getMetaFieldName(): string
|
||||
{
|
||||
return 'timesheet';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
private function getSearchableFields(): array
|
||||
{
|
||||
return ['t.description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|null $user
|
||||
* @param DateTime|null $startFrom
|
||||
|
||||
Reference in New Issue
Block a user