- Implemented TargetType form for managing target details including name, type, priority, stages, estimated size, profile criteria, pain points, value proposition, and preferred channels. - Created migration scripts for adding type and priority columns to plan objectives and tasks. - Added migration for creating plan targets and plan target stages tables, including foreign key constraints. - Introduced stakeholder management with forms and views for creating, editing, and listing stakeholders. - Enhanced UI with read more functionality for long text descriptions and filtering options in plan tab tables.
282 lines
7.6 KiB
PHP
282 lines
7.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\PlanBundle\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
|
|
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
|
|
use Mautic\CoreBundle\Entity\FormEntity;
|
|
use MauticPlugin\PlanBundle\Validator\Constraints\EndDateAfterStartDate;
|
|
use MauticPlugin\PlanBundle\Validator\Constraints\ValidTaskParent;
|
|
use Symfony\Component\Validator\Constraints\Length;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
|
|
/**
|
|
* A task of a plan. Every task belongs to exactly one plan, and may have a parent task in the same plan.
|
|
*
|
|
* Database rules: deleting the plan deletes its tasks (ON DELETE CASCADE); deleting a task makes its
|
|
* sub-tasks top-level (parent ON DELETE SET NULL).
|
|
*/
|
|
class Task extends FormEntity implements DateRangeInterface
|
|
{
|
|
public const TABLE_NAME = 'plan_tasks';
|
|
|
|
public const TYPE_MAX_LENGTH = 64;
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Plan $plan = null;
|
|
|
|
/**
|
|
* Key of a task type set up in Settings > Configuration > Plan Settings (parameter plan_task_types);
|
|
* see ItemTypeProvider (kind "task") for its name, description and pictogram.
|
|
*/
|
|
private ?string $type = null;
|
|
|
|
private ?string $name = null;
|
|
|
|
private ?string $description = null;
|
|
|
|
private ?Task $parent = null;
|
|
|
|
private ?\DateTime $startDate = null;
|
|
|
|
private ?\DateTime $endDate = null;
|
|
|
|
private TaskStatus $status = TaskStatus::New;
|
|
|
|
/**
|
|
* @var Collection<int, Task>
|
|
*/
|
|
private Collection $children;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->children = new ArrayCollection();
|
|
}
|
|
|
|
public function __clone()
|
|
{
|
|
$this->id = null;
|
|
$this->children = new ArrayCollection();
|
|
|
|
parent::__clone();
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(TaskRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('plan', Plan::class)
|
|
->inversedBy('tasks')
|
|
->addJoinColumn('plan_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createField('type', Types::STRING)
|
|
->length(self::TYPE_MAX_LENGTH)
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createField('name', Types::STRING)
|
|
->length(255)
|
|
->build();
|
|
|
|
$builder->createField('description', Types::TEXT)
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createManyToOne('parent', self::class)
|
|
->inversedBy('children')
|
|
->addJoinColumn('parent_id', 'id', true, false, 'SET NULL')
|
|
->build();
|
|
|
|
$builder->createOneToMany('children', self::class)
|
|
->mappedBy('parent')
|
|
->setOrderBy(['name' => 'ASC'])
|
|
->fetchExtraLazy()
|
|
->build();
|
|
|
|
$builder->addNamedField('startDate', Types::DATETIME_MUTABLE, 'start_date', true);
|
|
$builder->addNamedField('endDate', Types::DATETIME_MUTABLE, 'end_date', true);
|
|
|
|
// Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191).
|
|
$metadata->mapField([
|
|
'fieldName' => 'status',
|
|
'type' => Types::STRING,
|
|
'length' => 20,
|
|
'enumType' => TaskStatus::class,
|
|
'options' => ['default' => TaskStatus::New->value],
|
|
]);
|
|
$builder->addIndex(['status'], 'plan_task_status');
|
|
}
|
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
|
{
|
|
$metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.core.name.required'));
|
|
$metadata->addPropertyConstraint('name', new Length(max: 255));
|
|
$metadata->addPropertyConstraint('plan', new NotBlank(message: 'mautic.plan.task.plan.required'));
|
|
$metadata->addPropertyConstraint('type', new NotBlank(message: 'mautic.plan.task.type.required'));
|
|
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
|
|
$metadata->addConstraint(new ValidTaskParent());
|
|
$metadata->addConstraint(new EndDateAfterStartDate());
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getPlan(): ?Plan
|
|
{
|
|
return $this->plan;
|
|
}
|
|
|
|
public function setPlan(?Plan $plan): static
|
|
{
|
|
$this->isChanged('plan', $plan);
|
|
$this->plan = $plan;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getType(): ?string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(?string $type): static
|
|
{
|
|
// FormEntity logs changes for the audit log; enums aren't stringable, plain strings are fine.
|
|
$this->isChanged('type', $type);
|
|
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(?string $name): static
|
|
{
|
|
$this->isChanged('name', $name);
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(?string $description): static
|
|
{
|
|
$this->isChanged('description', $description);
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getParent(): ?Task
|
|
{
|
|
return $this->parent;
|
|
}
|
|
|
|
public function setParent(?Task $parent): static
|
|
{
|
|
$this->isChanged('parent', $parent);
|
|
$this->parent = $parent;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStartDate(): ?\DateTime
|
|
{
|
|
return $this->startDate;
|
|
}
|
|
|
|
public function setStartDate(?\DateTime $startDate): static
|
|
{
|
|
$this->isChanged('startDate', $startDate);
|
|
$this->startDate = $startDate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEndDate(): ?\DateTime
|
|
{
|
|
return $this->endDate;
|
|
}
|
|
|
|
public function setEndDate(?\DateTime $endDate): static
|
|
{
|
|
$this->isChanged('endDate', $endDate);
|
|
$this->endDate = $endDate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStatus(): TaskStatus
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function setStatus(TaskStatus $status): static
|
|
{
|
|
if ($status !== $this->status) {
|
|
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
|
$this->addChange('status', [$this->status->value, $status->value]);
|
|
$this->status = $status;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Task>
|
|
*/
|
|
public function getChildren(): Collection
|
|
{
|
|
return $this->children;
|
|
}
|
|
|
|
/**
|
|
* True when $task is this task or one of its ancestors.
|
|
*/
|
|
public function hasAncestorOrSelf(Task $task): bool
|
|
{
|
|
$seen = [];
|
|
$current = $this;
|
|
|
|
while (null !== $current) {
|
|
if ($current === $task || (null !== $task->getId() && $current->getId() === $task->getId())) {
|
|
return true;
|
|
}
|
|
|
|
// Guard against a cycle that is already stored.
|
|
$key = null !== $current->getId() ? 'id'.$current->getId() : spl_object_id($current);
|
|
if (isset($seen[$key])) {
|
|
return false;
|
|
}
|
|
$seen[$key] = true;
|
|
|
|
$current = $current->getParent();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|