Stages) this target maps to; a target can have any * number of them, or none. Deleting a stage removes the link (join table row), not the target. */ class Target { public const TABLE_NAME = 'plan_targets'; /** * Keys offered for preferredChannels, in display order. */ public const CHANNELS = [ 'email' => 'mautic.plan.target.channel.email', 'sms' => 'mautic.plan.target.channel.sms', 'web' => 'mautic.plan.target.channel.web', 'social_organic' => 'mautic.plan.target.channel.social_organic', 'paid_social' => 'mautic.plan.target.channel.paid_social', 'paid_search' => 'mautic.plan.target.channel.paid_search', 'events_webinar' => 'mautic.plan.target.channel.events_webinar', 'outbound_sales' => 'mautic.plan.target.channel.outbound_sales', 'partners' => 'mautic.plan.target.channel.partners', ]; private ?int $id = null; private ?Plan $plan = null; private ?string $name = null; private TargetType $targetType = TargetType::Persona; private TargetPriority $priority = TargetPriority::Primary; /** * @var Collection */ private Collection $stages; /** * Estimated number of people or accounts, or null when unknown. */ private ?int $estimatedSize = null; /** * Demographics, firmographics, job titles, geography. */ private ?string $profileCriteria = null; /** * Problems, triggers, motivations. */ private ?string $painPoints = null; /** * Key message / hook for this target in this plan. */ private ?string $valueProposition = null; /** * Keys of self::CHANNELS the plan means to use for this target. * * @var list|null */ private ?array $preferredChannels = null; /** * Display order within the plan, from 0. Set by drag and drop in the form. */ private int $position = 0; public function __construct() { $this->stages = new ArrayCollection(); } public function __clone() { $this->id = null; $this->plan = null; $this->stages = new ArrayCollection(); } public static function loadMetadata(OrmClassMetadata $metadata): void { $builder = new ClassMetadataBuilder($metadata); $builder->setTable(self::TABLE_NAME) ->setCustomRepositoryClass(TargetRepository::class); $builder->addId(); $builder->createManyToOne('plan', Plan::class) ->inversedBy('targets') ->addJoinColumn('plan_id', 'id', false, false, 'CASCADE') ->build(); // Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191). $metadata->mapField([ 'fieldName' => 'name', 'type' => Types::STRING, 'length' => 191, ]); $metadata->mapField([ 'fieldName' => 'targetType', 'columnName' => 'target_type', 'type' => Types::STRING, 'length' => 30, 'enumType' => TargetType::class, 'options' => ['default' => TargetType::Persona->value], ]); $metadata->mapField([ 'fieldName' => 'priority', 'type' => Types::STRING, 'length' => 20, 'enumType' => TargetPriority::class, 'options' => ['default' => TargetPriority::Primary->value], ]); foreach (['profileCriteria' => 'profile_criteria', 'painPoints' => 'pain_points', 'valueProposition' => 'value_proposition'] as $field => $column) { $metadata->mapField([ 'fieldName' => $field, 'columnName' => $column, 'type' => Types::TEXT, 'nullable' => true, ]); } $builder->createManyToMany('stages', Stage::class) ->setJoinTable('plan_target_stages') ->addJoinColumn('target_id', 'id', false, false, 'CASCADE') ->addInverseJoinColumn('stage_id', 'id', false, false, 'CASCADE') ->build(); $builder->createField('estimatedSize', Types::INTEGER) ->columnName('estimated_size') ->nullable() ->option('unsigned', true) ->build(); $builder->createField('preferredChannels', Types::JSON) ->columnName('preferred_channels') ->nullable() ->build(); $builder->createField('position', Types::INTEGER) ->option('default', 0) ->build(); } public static function loadValidatorMetadata(ClassMetadata $metadata): void { $metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.plan.target.name.required')); $metadata->addPropertyConstraint('name', new Length(max: 191)); $metadata->addPropertyConstraint('estimatedSize', new PositiveOrZero(message: 'mautic.plan.target.estimated_size.invalid')); } 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 getName(): ?string { return $this->name; } public function setName(?string $name): static { $this->name = $name; return $this; } public function getTargetType(): TargetType { return $this->targetType; } public function setTargetType(TargetType $targetType): static { $this->targetType = $targetType; return $this; } public function getPriority(): TargetPriority { return $this->priority; } public function setPriority(TargetPriority $priority): static { $this->priority = $priority; return $this; } /** * @return Collection */ public function getStages(): Collection { return $this->stages; } public function addStage(Stage $stage): static { if (!$this->stages->contains($stage)) { $this->stages->add($stage); } return $this; } public function removeStage(Stage $stage): static { $this->stages->removeElement($stage); return $this; } public function getEstimatedSize(): ?int { return $this->estimatedSize; } public function setEstimatedSize(?int $estimatedSize): static { $this->estimatedSize = $estimatedSize; return $this; } public function getProfileCriteria(): ?string { return $this->profileCriteria; } public function setProfileCriteria(?string $profileCriteria): static { $this->profileCriteria = $profileCriteria; return $this; } public function getPainPoints(): ?string { return $this->painPoints; } public function setPainPoints(?string $painPoints): static { $this->painPoints = $painPoints; return $this; } public function getValueProposition(): ?string { return $this->valueProposition; } public function setValueProposition(?string $valueProposition): static { $this->valueProposition = $valueProposition; return $this; } /** * @return list|null */ public function getPreferredChannels(): ?array { return $this->preferredChannels; } /** * @param list|null $preferredChannels */ public function setPreferredChannels(?array $preferredChannels): static { $this->preferredChannels = $preferredChannels; return $this; } public function getPosition(): int { return $this->position; } public function setPosition(?int $position): static { $this->position = $position ?? 0; return $this; } }