Files
mautic-marketing-program-bu…/Entity/TaskRaci.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

155 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
/**
* One RACI assignment of a task: a role (R/A/C/I) and the stakeholders carrying it. Several
* stakeholders may share a role; each row is one role with its stakeholder list.
*
* The row is owned by the task it belongs to (Task::$raci); deleting the task or a stakeholder
* deletes the row (ON DELETE CASCADE both sides).
*/
class TaskRaci
{
public const TABLE_NAME = 'mt3s_mp_program_task_raci';
/**
* The join table carrying the stakeholders of a RACI row (TaskRaci -> Stakeholder).
*/
public const JOIN_TABLE_NAME = 'mt3s_mp_program_task_raci_stakeholders';
private ?int $id = null;
private ?Task $task = null;
private RaciRole $role = RaciRole::Responsible;
/**
* @var Collection<int, Stakeholder>
*/
private Collection $stakeholders;
/**
* Display order within the task's RACI list, from 0.
*/
private int $position = 0;
public function __construct()
{
$this->stakeholders = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->task = null;
$this->stakeholders = new ArrayCollection();
}
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(TaskRaciRepository::class);
$builder->addId();
$builder->createManyToOne('task', Task::class)
->inversedBy('raci')
->addJoinColumn('task_id', 'id', false, false, 'CASCADE')
->build();
$metadata->mapField([
'fieldName' => 'role',
'type' => Types::STRING,
'length' => 20,
'enumType' => RaciRole::class,
'options' => ['default' => RaciRole::Responsible->value],
]);
$builder->createManyToMany('stakeholders', Stakeholder::class)
->setJoinTable(self::JOIN_TABLE_NAME)
->addJoinColumn('raci_id', 'id', false, false, 'CASCADE')
->addInverseJoinColumn('stakeholder_id', 'id', false, false, 'CASCADE')
->build();
$builder->createField('position', Types::INTEGER)
->option('default', 0)
->build();
}
public function getId(): ?int
{
return $this->id;
}
public function getTask(): ?Task
{
return $this->task;
}
public function setTask(?Task $task): static
{
$this->task = $task;
return $this;
}
public function getRole(): RaciRole
{
return $this->role;
}
public function setRole(RaciRole $role): static
{
$this->role = $role;
return $this;
}
/**
* @return Collection<int, Stakeholder>
*/
public function getStakeholders(): Collection
{
return $this->stakeholders;
}
public function addStakeholder(Stakeholder $stakeholder): static
{
if (!$this->stakeholders->contains($stakeholder)) {
$this->stakeholders->add($stakeholder);
}
return $this;
}
public function removeStakeholder(Stakeholder $stakeholder): static
{
$this->stakeholders->removeElement($stakeholder);
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position ?? 0;
return $this;
}
}