- Correct getChoices() docblock to reflect translated label => enum backing value order instead of value => label - Re-indent Smart Links menu config to match actual array nesting - Align assignment operators in RefreshStatsCommand - Add missing newline at end of RefreshStatsCommand.php
213 lines
5.3 KiB
PHP
213 lines
5.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\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\Constraints\NotNull;
|
|
use Symfony\Component\Validator\Constraints\Range;
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
|
|
/**
|
|
* An objective of a plan. Program::$objectives owns the lifecycle: objectives are saved and deleted with
|
|
* their plan, and are ordered by position.
|
|
*/
|
|
class ProgramObjective
|
|
{
|
|
public const TABLE_NAME = 'mt3s_mp_program_objectives';
|
|
|
|
public const TYPE_MAX_LENGTH = 64;
|
|
|
|
public const PRIORITY_MIN = 1;
|
|
public const PRIORITY_MAX = 99;
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Program $program = null;
|
|
|
|
private ?string $type = 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;
|
|
|
|
/**
|
|
* Importance of the objective, from 1 (highest) to 99 (lowest). Edited by hand.
|
|
*/
|
|
private ?int $priority = null;
|
|
|
|
/**
|
|
* Toggled by hand for now.
|
|
*/
|
|
private bool $isAchieved = false;
|
|
|
|
public function __clone()
|
|
{
|
|
$this->id = null;
|
|
$this->program = null;
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(ProgramObjectiveRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('program', Program::class)
|
|
->inversedBy('objectives')
|
|
->addJoinColumn('program_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createField('type', Types::STRING)
|
|
->length(self::TYPE_MAX_LENGTH)
|
|
->nullable()
|
|
->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();
|
|
|
|
$builder->createField('priority', Types::INTEGER)
|
|
->option('default', self::PRIORITY_MIN)
|
|
->build();
|
|
}
|
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
|
{
|
|
$metadata->addPropertyConstraint('title', new NotBlank(message: 'mt3s.marketing_program.objective.title.required'));
|
|
$metadata->addPropertyConstraint('title', new Length(max: 255));
|
|
$metadata->addPropertyConstraint('type', new NotBlank(message: 'mt3s.marketing_program.objective.type.required'));
|
|
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
|
|
$metadata->addPropertyConstraint('priority', new NotNull(message: 'mt3s.marketing_program.objective.priority.range'));
|
|
$metadata->addPropertyConstraint('priority', new Range(
|
|
notInRangeMessage: 'mt3s.marketing_program.objective.priority.range',
|
|
min: self::PRIORITY_MIN,
|
|
max: self::PRIORITY_MAX,
|
|
));
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getProgram(): ?Program
|
|
{
|
|
return $this->program;
|
|
}
|
|
|
|
public function setProgram(?Program $program): static
|
|
{
|
|
$this->program = $program;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getType(): ?string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(?string $type): static
|
|
{
|
|
$this->type = $type;
|
|
|
|
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 getPriority(): ?int
|
|
{
|
|
return $this->priority;
|
|
}
|
|
|
|
/**
|
|
* An objective without a priority yet (column added by Version_0_10_1) becomes
|
|
* self::PRIORITY_MIN once set. Null is refused by validation.
|
|
*/
|
|
public function setPriority(?int $priority): static
|
|
{
|
|
$this->priority = $priority;
|
|
|
|
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;
|
|
}
|
|
}
|