Files
mautic-marketing-program-bu…/Entity/TaskRepository.php
T
Alexandre Gain 8268fad886 feat: Rework task management in PlanBundle
- Introduced migration Version_0_13_0 to update task schema:
  - Changed start_date and end_date to DATE type, truncating time.
  - Added new columns: task_kind, definition_of_done, planned_work.
  - Removed parent_id and its index, replacing with a dependency graph.
  - Created new tables: plan_task_dependencies and plan_task_raci, including a join table for stakeholders.

- Updated Version_0_4_0 migration to remove references to parent_id.

- Refactored TaskModel to return tasks as flat rows with dependencies and RACI assignments.

- Modified task table view to display tasks without hierarchical structure, adding badges for milestones and phases.

- Enhanced task form to include dependencies and RACI roles, with appropriate macros for rendering.

- Updated task list view to reflect new task structure and display status based on task kind.

- Added new validation constraints for task dependencies and dates, ensuring no cycles or self-references.

- Removed obsolete ValidTaskParent validation as parent-child relationships are no longer supported.

- Updated translations to reflect changes in task management and new fields.

- Revised documentation to describe new task handling and features.
2026-11-13 21:58:45 +01:00

86 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<Task>
*/
class TaskRepository extends CommonRepository
{
use CountsItemsByTypeTrait;
public function getTableAlias(): string
{
return 't';
}
/**
* Loads the plan, the dependencies (with their depends-on task) and the RACI rows (with their
* stakeholders) 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', 'dep', 'depTask', 'raci', 'raciStakeholder')
->leftJoin($alias.'.plan', 'pl')
->leftJoin($alias.'.dependencies', 'dep')
->leftJoin('dep.dependsOn', 'depTask')
->leftJoin($alias.'.raci', 'raci')
->leftJoin('raci.stakeholders', 'raciStakeholder');
return parent::getEntities($args);
}
/**
* All tasks of a plan, ordered by name, with their dependencies and RACI rows loaded.
*
* @return Task[]
*/
public function findByPlan(Plan $plan): array
{
return $this->createQueryBuilder('t')
->select('t', 'dep', 'depTask', 'raci', 'raciStakeholder')
->leftJoin('t.dependencies', 'dep')
->leftJoin('dep.dependsOn', 'depTask')
->leftJoin('t.raci', 'raci')
->leftJoin('raci.stakeholders', 'raciStakeholder')
->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'],
];
}
}