Files
mautic-marketing-program-bu…/Model/TaskModel.php
T
Alexandre Gain ea88b7a772 refactor(plugin): rebrand as MT3SMarketingProgram, release 0.17.0
Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle):

- ProgramBundle -> MT3SMarketingProgramBundle; extension, integration,
  config support, permissions, events and twig extension renamed likewise
- Initiative* -> Program*: controller (InitiativeController ->
  ProgramController), model, entities, repositories, form types and views
  (new _tabs/_task_table/_tab_table_filter partials, details page)
- Settings config form theme -> _config_mt3smarketingprogramconfig_widget;
  routes and translations re-prefixed (mt3s_marketing_program_*)
- Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js
  (OnLoad hooks renamed mt3sMpProgram*)
- Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames
  the tables to mt3s_mp_program_*
2026-11-15 17:48:01 +01:00

80 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Model;
use Mautic\CoreBundle\Model\FormModel;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Program;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskRepository;
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\TaskType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
/**
* Available as mt3s.marketing_program.model.task, or getModel('mt3smp.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 'mt3smarketingprogram: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 program'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(Program $program): array
{
$rows = [];
foreach ($this->getRepository()->findByProgram($program) 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);
}
}