Files
mautic-marketing-program-bu…/Model/TaskModel.php
T
Alexandre Gain 71ff11390b refactor(plugin): rename Plan to Program and add audience/UTM routes
Rename the Plan bundle to Program across config, routes, menus, and
controllers (Plan -> Initiative), bump version to 0.16.0, and introduce
new audience and UTM taxonomy routes and permissions to support the
expanded Programs feature set.
2026-11-13 22:01:32 +01:00

80 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Model;
use Mautic\CoreBundle\Model\FormModel;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\Task;
use MauticPlugin\ProgramBundle\Entity\TaskRepository;
use MauticPlugin\ProgramBundle\Form\Type\TaskType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
/**
* Available as mautic.program.model.task, or getModel('program.task').
*
* @extends FormModel<Task>
*/
class TaskModel extends FormModel
{
public function getRepository(): TaskRepository
{
$repository = $this->em->getRepository(Task::class);
\assert($repository instanceof TaskRepository);
return $repository;
}
public function getPermissionBase(): string
{
return 'program:tasks';
}
public function getEntity($id = null): ?Task
{
if (null === $id) {
return new Task();
}
$task = parent::getEntity($id);
return $task instanceof Task ? $task : null;
}
/**
* The plan's tasks as rows for the initiative's Tasks tab: the tasks ordered by name, each with its
* dependencies and RACI rows loaded. The former parent/child tree is gone; the tab lists the
* tasks flat, and the dependencies are shown per task.
*
* @return array<int, array{task: Task, depth: int}>
*/
public function getTaskTree(Initiative $initiative): array
{
$rows = [];
foreach ($this->getRepository()->findByInitiative($initiative) as $task) {
$rows[] = ['task' => $task, 'depth' => 0];
}
return $rows;
}
/**
* @param array<string, mixed> $options
*/
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
{
if (!$entity instanceof Task) {
throw new MethodNotAllowedHttpException(['Task']);
}
if (!empty($action)) {
$options['action'] = $action;
}
return $formFactory->create(TaskType::class, $entity, $options);
}
}