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.
This commit is contained in:
Alexandre Gain committed 2026-11-13 21:58:45 +01:00
1 parent 8696acd01c
commit 8268fad886
33 files changed
+1454 -251

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use MauticPlugin\PlanBundle\Entity\DependencyType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskDependency;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the dependencies collection in TaskType: the task this one depends on, and the type of
* the relation. Only the tasks of the same plan are offered; cycles and self-edges are refused by
* ValidTaskDependency.
*
* @extends AbstractType<TaskDependency>
*/
class TaskDependencyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var Plan|null $plan */
$plan = $options['plan'];
/** @var Task|null $task */
$task = $options['task'];
$builder->add('dependsOn', EntityType::class, [
'label' => 'mautic.plan.task.dependency.field.depends_on',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Task::class,
'choice_label' => 'name',
'query_builder' => function (EntityRepository $er) use ($plan, $task) {
$qb = $er->createQueryBuilder('t')
->orderBy('t.name', 'ASC');
if (null !== $plan) {
$qb->andWhere('t.plan = :plan')->setParameter('plan', $plan);
}
if (null !== $task?->getId()) {
$qb->andWhere('t.id != :self')->setParameter('self', $task->getId());
}
return $qb;
},
'placeholder' => 'mautic.core.form.chooseone',
'required' => true,
]);
$builder->add('dependencyType', EnumType::class, [
'label' => 'mautic.plan.task.dependency.field.type',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => DependencyType::class,
'choice_label' => fn (DependencyType $type): string => $type->getLabelKey(),
]);
// The row's order in the collection, rewritten by plan.js after each change.
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => TaskDependency::class,
]);
$resolver->setDefined(['plan', 'task']);
$resolver->setAllowedTypes('plan', [Plan::class, 'null']);
$resolver->setAllowedTypes('task', [Task::class, 'null']);
}
public function getBlockPrefix(): string
{
return 'plan_task_dependency';
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\RaciRole;
use MauticPlugin\PlanBundle\Entity\Stakeholder;
use MauticPlugin\PlanBundle\Entity\TaskRaci;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the RACI collection in TaskType: a role (R/A/C/I) and the stakeholders carrying it.
* The stakeholders are picked from the plan's assigned stakeholders; several may share a role.
*
* @extends AbstractType<TaskRaci>
*/
class TaskRaciType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var Plan|null $plan */
$plan = $options['plan'];
$builder->add('role', EnumType::class, [
'label' => 'mautic.plan.task.raci.field.role',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => RaciRole::class,
'choice_label' => fn (RaciRole $role): string => $role->getLabelKey(),
]);
$builder->add('stakeholders', EntityType::class, [
'label' => 'mautic.plan.task.raci.field.stakeholders',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Stakeholder::class,
'choice_label' => 'name',
'query_builder' => function (EntityRepository $er) use ($plan) {
$qb = $er->createQueryBuilder('s')
->orderBy('s.name', 'ASC');
// The plan's assigned stakeholders, when the plan is known.
if (null !== $plan) {
$qb->join('s.planLinks', 'l')
->andWhere('l.plan = :plan')
->setParameter('plan', $plan);
}
return $qb;
},
'multiple' => true,
'expanded' => false,
'required' => false,
]);
// The row's order in the collection, rewritten by plan.js after each change.
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => TaskRaci::class,
]);
$resolver->setDefined(['plan']);
$resolver->setAllowedTypes('plan', [Plan::class, 'null']);
}
public function getBlockPrefix(): string
{
return 'plan_task_raci';
}
}
+87 -40
View File
@@ -6,22 +6,31 @@ namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber;
use Mautic\CoreBundle\Form\Type\DatePickerType;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskKind;
use MauticPlugin\PlanBundle\Entity\TaskStatus;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* The create and edit form of a task (Planning > Tasks).
*
* Kind rules: a milestone's end date is enslaved to its start date (the entity's setTaskKind copies
* the start onto the end, and the TaskDates validator keeps it in step); a phase has no status
* field — its state comes from its tasks.
*
* @extends AbstractType<Task>
*/
class TaskType extends AbstractType
@@ -41,6 +50,17 @@ class TaskType extends AbstractType
$kind = ItemTypeProvider::KIND_TASK;
// The kind drives what the form offers: milestones enslave the end date, phases have no status.
$taskKind = $task->getTaskKind();
$builder->add('taskKind', EnumType::class, [
'label' => 'mautic.plan.task.field.kind',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TaskKind::class,
'choice_label' => fn (TaskKind $k): string => $k->getLabelKey(),
]);
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.task.field.type',
'label_attr' => ['class' => 'control-label'],
@@ -79,51 +99,78 @@ class TaskType extends AbstractType
'required' => true,
]);
// Offers the tasks of the task's plan when it is known, otherwise all tasks grouped by plan.
// ValidTaskParent rejects a parent from another plan, and loops.
$builder->add('parent', EntityType::class, [
'label' => 'mautic.plan.task.field.parent',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Task::class,
'choice_label' => 'name',
'group_by' => null === $plan ? fn (Task $t): string => (string) $t->getPlan()?->getName() : null,
'query_builder' => function (EntityRepository $er) use ($task, $plan) {
$qb = $er->createQueryBuilder('t')
->leftJoin('t.plan', 'p')
->addSelect('p')
->orderBy('p.name', 'ASC')
->addOrderBy('t.name', 'ASC');
if (null !== $plan) {
$qb->andWhere('t.plan = :plan')->setParameter('plan', $plan);
}
if (null !== $task->getId()) {
$qb->andWhere('t.id != :self')->setParameter('self', $task->getId());
}
return $qb;
},
'placeholder' => 'mautic.plan.task.parent.none',
'required' => false,
// Simple dates, no time (the columns are DATE since 0.13.0).
$builder->add('startDate', DateType::class, [
'label' => 'mautic.plan.task.field.start_date',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd',
'html5' => true,
'attr' => ['class' => 'form-control', 'data-toggle' => 'date'],
]);
// Dropdown in the order of the TaskStatus cases: New, To do, In progress, Done.
$builder->add('status', EnumType::class, [
'label' => 'mautic.plan.task.field.status',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TaskStatus::class,
'choice_label' => fn (TaskStatus $status): string => $status->getLabelKey(),
// End date: a milestone's is enslaved to the start date (same day), so it stays read-only.
$isMilestone = TaskKind::Milestone === $task->getTaskKind();
$isPhase = TaskKind::Phase === $task->getTaskKind();
$builder->add('endDate', DateType::class, [
'label' => 'mautic.plan.task.field.end_date',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd',
'html5' => true,
'disabled' => $isMilestone,
'attr' => ['class' => 'form-control', 'data-toggle' => 'date'],
]);
$builder->add('startDate', DatePickerType::class, [
'label' => 'mautic.plan.task.field.start_date',
// Status: a phase has none of its own — it comes from its tasks.
if (!$isPhase) {
$builder->add('status', EnumType::class, [
'label' => 'mautic.plan.task.field.status',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TaskStatus::class,
'choice_label' => fn (TaskStatus $status): string => $status->getLabelKey(),
]);
}
$builder->add('definitionOfDone', TextareaType::class, [
'label' => 'mautic.plan.task.field.definition_of_done',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 3],
'required' => false,
]);
$builder->add('endDate', DatePickerType::class, [
'label' => 'mautic.plan.task.field.end_date',
$builder->add('plannedWork', IntegerType::class, [
'label' => 'mautic.plan.task.field.planned_work',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'min' => 0, 'step' => 1, 'postaddon_text' => 'h'],
'required' => false,
]);
// Dependencies: several edges, each another task of the plan with the relation type. The
// rows are added and removed by the form template; cycles and self-edges are refused by
// ValidTaskDependency.
$builder->add('dependencies', CollectionType::class, [
'label' => 'mautic.plan.task.field.dependencies',
'entry_type' => TaskDependencyType::class,
'entry_options' => ['label' => false, 'plan' => $plan, 'task' => $task],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__dependency__',
'required' => false,
]);
// RACI: one row per role, several stakeholders per role, picked from the plan's stakeholders.
$builder->add('raci', CollectionType::class, [
'label' => 'mautic.plan.task.field.raci',
'entry_type' => TaskRaciType::class,
'entry_options' => ['label' => false, 'plan' => $plan],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__raci__',
'required' => false,
]);
$builder->add('buttons', FormButtonsType::class);