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.
155 lines
3.8 KiB
PHP
155 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\ProgramBundle\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 = 'initiative_task_raci';
|
|
|
|
/**
|
|
* The join table carrying the stakeholders of a RACI row (TaskRaci -> Stakeholder).
|
|
*/
|
|
public const JOIN_TABLE_NAME = 'initiative_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;
|
|
}
|
|
}
|