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 */ 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 */ 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; } }