154 lines
3.5 KiB
PHP
154 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\PlanBundle\Entity;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
|
|
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
|
|
use Symfony\Component\Validator\Constraints\Length;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
|
|
/**
|
|
* An objective of a plan. Plan::$objectives owns the lifecycle: objectives are saved and deleted with
|
|
* their plan, and are ordered by position.
|
|
*/
|
|
class PlanObjective
|
|
{
|
|
public const TABLE_NAME = 'plan_objectives';
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Plan $plan = null;
|
|
|
|
private ?string $title = null;
|
|
|
|
private ?string $description = null;
|
|
|
|
/**
|
|
* Display order within the plan, from 0. Set by drag and drop in the form.
|
|
*/
|
|
private int $position = 0;
|
|
|
|
/**
|
|
* Toggled by hand for now.
|
|
*/
|
|
private bool $isAchieved = false;
|
|
|
|
public function __clone()
|
|
{
|
|
$this->id = null;
|
|
$this->plan = null;
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(PlanObjectiveRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('plan', Plan::class)
|
|
->inversedBy('objectives')
|
|
->addJoinColumn('plan_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createField('title', Types::STRING)
|
|
->length(255)
|
|
->build();
|
|
|
|
$builder->createField('description', Types::TEXT)
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createField('position', Types::INTEGER)
|
|
->option('default', 0)
|
|
->build();
|
|
|
|
$builder->createField('isAchieved', Types::BOOLEAN)
|
|
->columnName('is_achieved')
|
|
->option('default', false)
|
|
->build();
|
|
}
|
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
|
{
|
|
$metadata->addPropertyConstraint('title', new NotBlank(message: 'mautic.plan.objective.title.required'));
|
|
$metadata->addPropertyConstraint('title', new Length(max: 255));
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getPlan(): ?Plan
|
|
{
|
|
return $this->plan;
|
|
}
|
|
|
|
public function setPlan(?Plan $plan): static
|
|
{
|
|
$this->plan = $plan;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTitle(): ?string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(?string $title): static
|
|
{
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(?string $description): static
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return $this->position;
|
|
}
|
|
|
|
public function setPosition(?int $position): static
|
|
{
|
|
$this->position = $position ?? 0;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isAchieved(): bool
|
|
{
|
|
return $this->isAchieved;
|
|
}
|
|
|
|
public function getIsAchieved(): bool
|
|
{
|
|
return $this->isAchieved;
|
|
}
|
|
|
|
public function setIsAchieved(bool $isAchieved): static
|
|
{
|
|
$this->isAchieved = $isAchieved;
|
|
|
|
return $this;
|
|
}
|
|
}
|