Files
mautic-marketing-program-bu…/Entity/TaskRepository.php
T
2026-11-07 19:31:49 +01:00

75 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<Task>
*/
class TaskRepository extends CommonRepository
{
public function getTableAlias(): string
{
return 't';
}
/**
* Loads the plan and the parent with the tasks, so that the list doesn't query them one by one.
*
* @param array<string, mixed> $args
*/
public function getEntities(array $args = [])
{
$alias = $this->getTableAlias();
$args['qb'] = $this->createQueryBuilder($alias)
->select($alias, 'pl', 'pa')
->leftJoin($alias.'.plan', 'pl')
->leftJoin($alias.'.parent', 'pa');
return parent::getEntities($args);
}
/**
* All tasks of a plan, ordered by name.
*
* @return Task[]
*/
public function findByPlan(Plan $plan): array
{
return $this->createQueryBuilder('t')
->where('t.plan = :plan')
->setParameter('plan', $plan)
->orderBy('t.name', 'ASC')
->addOrderBy('t.id', 'ASC')
->getQuery()
->getResult();
}
/**
* The list's search box matches the name and the description.
*
* @return array<int, mixed>
*/
protected function addCatchAllWhereClause($q, $filter): array
{
return $this->addStandardCatchAllWhereClause($q, $filter, [
$this->getTableAlias().'.name',
$this->getTableAlias().'.description',
]);
}
/**
* @return array<array{0: string, 1: string}>
*/
protected function getDefaultOrder(): array
{
return [
[$this->getTableAlias().'.name', 'ASC'],
];
}
}