feat: Add TargetType form and migration for plan targets

- 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.
This commit is contained in:
Alexandre Gain committed 2026-11-08 11:54:25 +01:00
1 parent 8c8d7a6f95
commit 8696acd01c
52 files changed
+3178 -125

No files matched your search

+10 -3
View File
@@ -5,12 +5,15 @@ declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* For repositories of typed plan items (description items, allocation items).
* For repositories of typed plan items (description items, allocation items, objectives, tasks).
*/
trait CountsItemsByTypeTrait
{
/**
* Number of items per type key, for the types that are in use.
* Number of items per type key, for the types that are in use. Rows without a type (legacy
* rows created before their kind got types) are skipped: they don't reference any configured
* type, so they must not block any save of the configuration; validation asks for a type on
* the next save of each of those items.
*
* @return array<string, int>
*/
@@ -25,7 +28,11 @@ trait CountsItemsByTypeTrait
$counts = [];
foreach ($rows as $row) {
$counts[(string) $row['type']] = (int) $row['total'];
$key = $row['type'];
if (null === $key || '' === trim((string) $key)) {
continue;
}
$counts[(string) $key] = (int) $row['total'];
}
return $counts;
+130 -7
View File
@@ -47,13 +47,29 @@ class Plan extends FormEntity implements DateRangeInterface
private Collection $descriptionItems;
/**
* The cost lines of the Allocation tab. Each item has a type set up by the admin in
* The cost lines of the Allocations tab. Each item has a type set up by the admin in
* Settings > Configuration > Plan.
*
* @var Collection<int, PlanAllocationItem>
*/
private Collection $allocationItems;
/**
* The audiences of the Targets tab. Each target has a fixed type (persona, ICP, …), not an
* admin-configured one.
*
* @var Collection<int, Target>
*/
private Collection $targets;
/**
* The links to the stakeholders of the global directory (Planning > Stakeholders), each with the
* stakeholder's role in this plan. See PlanStakeholder.
*
* @var Collection<int, PlanStakeholder>
*/
private Collection $stakeholders;
/**
* Tasks are managed on their own pages (TaskController). Read-only from the plan: deleting a plan
* deletes its tasks through the database (ON DELETE CASCADE).
@@ -90,6 +106,8 @@ class Plan extends FormEntity implements DateRangeInterface
$this->objectives = new ArrayCollection();
$this->descriptionItems = new ArrayCollection();
$this->allocationItems = new ArrayCollection();
$this->targets = new ArrayCollection();
$this->stakeholders = new ArrayCollection();
$this->tasks = new ArrayCollection();
}
@@ -118,6 +136,20 @@ class Plan extends FormEntity implements DateRangeInterface
$this->addAllocationItem(clone $allocationItem);
}
// A clone gets its own copies of the targets. The stages are shared (ManyToMany), not cloned.
$targets = $this->targets;
$this->targets = new ArrayCollection();
foreach ($targets as $target) {
$this->addTarget(clone $target);
}
// A clone keeps the same stakeholders (directory entries), with fresh links.
$stakeholders = $this->stakeholders;
$this->stakeholders = new ArrayCollection();
foreach ($stakeholders as $stakeholder) {
$this->addStakeholder(clone $stakeholder);
}
parent::__clone();
}
@@ -190,6 +222,24 @@ class Plan extends FormEntity implements DateRangeInterface
->fetchExtraLazy()
->build();
$builder->createOneToMany('targets', Target::class)
->mappedBy('plan')
->cascadePersist()
->cascadeRemove()
->orphanRemoval()
->setOrderBy(['position' => 'ASC'])
->fetchExtraLazy()
->build();
$builder->createOneToMany('stakeholders', PlanStakeholder::class)
->mappedBy('plan')
->cascadePersist()
->cascadeRemove()
->orphanRemoval()
->setOrderBy(['position' => 'ASC'])
->fetchExtraLazy()
->build();
$builder->createOneToMany('tasks', Task::class)
->mappedBy('plan')
->setOrderBy(['name' => 'ASC'])
@@ -208,6 +258,8 @@ class Plan extends FormEntity implements DateRangeInterface
$metadata->addPropertyConstraint('objectives', new Valid());
$metadata->addPropertyConstraint('descriptionItems', new Valid());
$metadata->addPropertyConstraint('allocationItems', new Valid());
$metadata->addPropertyConstraint('targets', new Valid());
$metadata->addPropertyConstraint('stakeholders', new Valid());
$metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.core.name.required'));
$metadata->addPropertyConstraint('owner', new NotBlank(message: 'mautic.plan.owner.required'));
$metadata->addConstraint(new EndDateAfterStartDate());
@@ -235,7 +287,8 @@ class Plan extends FormEntity implements DateRangeInterface
}
/**
* The objectives sorted by position, as a new collection (Doctrine itself reads the property).
* The objectives sorted by priority (1 first), then by position for ties, as a new collection
* (Doctrine itself reads the property).
*
* Sorted here, not only by the mapping's orderBy: after a reorder, positions change in memory while the
* loaded collection keeps its old order, and the page shown right after saving uses that collection.
@@ -244,7 +297,16 @@ class Plan extends FormEntity implements DateRangeInterface
*/
public function getObjectives(): Collection
{
return self::sortedByPosition($this->objectives);
$objectives = self::sortedByPosition($this->objectives)->toArray();
usort($objectives, function (PlanObjective $a, PlanObjective $b): int {
// An objective without a priority yet sorts last; ties keep the position order.
$pa = $a->getPriority() ?? PHP_INT_MAX;
$pb = $b->getPriority() ?? PHP_INT_MAX;
return $pa === $pb ? 0 : ($pa < $pb ? -1 : 1);
});
return new ArrayCollection($objectives);
}
/**
@@ -255,6 +317,67 @@ class Plan extends FormEntity implements DateRangeInterface
return $this->tasks;
}
/**
* The targets sorted by position, as a new collection; see getObjectives().
*
* @return Collection<int, Target>
*/
public function getTargets(): Collection
{
return self::sortedByPosition($this->targets);
}
public function addTarget(Target $target): static
{
if (!$this->targets->contains($target)) {
$target->setPlan($this);
$this->targets->add($target);
}
return $this;
}
/**
* Removing a target from the plan deletes it (orphanRemoval).
*/
public function removeTarget(Target $target): static
{
$this->targets->removeElement($target);
return $this;
}
/**
* The stakeholder links sorted by position, as a new collection; see getObjectives().
*
* @return Collection<int, PlanStakeholder>
*/
public function getStakeholders(): Collection
{
return self::sortedByPosition($this->stakeholders);
}
public function addStakeholder(PlanStakeholder $stakeholder): static
{
if (!$this->stakeholders->contains($stakeholder)) {
$stakeholder->setPlan($this);
$this->stakeholders->add($stakeholder);
}
return $this;
}
/**
* Removing a stakeholder link from the plan deletes it (orphanRemoval). The stakeholder itself
* stays in the global directory.
*/
public function removeStakeholder(PlanStakeholder $stakeholder): static
{
$this->stakeholders->removeElement($stakeholder);
return $this;
}
public function addObjective(PlanObjective $objective): static
{
if (!$this->objectives->contains($objective)) {
@@ -342,7 +465,7 @@ class Plan extends FormEntity implements DateRangeInterface
}
/**
* @template T of PlanObjective|PlanDescriptionItem|PlanAllocationItem
* @template T of PlanObjective|PlanDescriptionItem|PlanAllocationItem|Target|PlanStakeholder
*
* @param Collection<int, T> $collection
*
@@ -377,12 +500,12 @@ class Plan extends FormEntity implements DateRangeInterface
}
/**
* Renumbers objective, description item and allocation item positions 0..n-1 following their current positions,
* so that the order stays contiguous after rows are added, removed or moved.
* Renumbers objective, description item, allocation item and target positions 0..n-1 following their
* current positions, so that the order stays contiguous after rows are added, removed or moved.
*/
public function normalizePositions(): void
{
foreach ([$this->objectives, $this->descriptionItems, $this->allocationItems] as $collection) {
foreach ([$this->objectives, $this->descriptionItems, $this->allocationItems, $this->targets, $this->stakeholders] as $collection) {
$rows = $collection->toArray();
usort($rows, fn ($a, $b): int => $a->getPosition() <=> $b->getPosition());
+3 -3
View File
@@ -12,9 +12,9 @@ use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* One item of a plan's Allocation tab: a typed cost line with a planned and a real cost, both in the
* general currency (CurrencyProvider). Plan::$allocationItems owns the lifecycle: items are saved and
* deleted with their plan, and are ordered by position.
* One item of a plan's Allocations tab: a typed cost line with a planned and a real cost, both in
* the general currency (CurrencyProvider). Plan::$allocationItems owns the lifecycle: items are saved
* and deleted with their plan, and are ordered by position.
*
* The type is the key of an allocation item type set up in Settings > Configuration > Plan Settings
* (parameter plan_allocation_item_types); see ItemTypeProvider.
+59
View File
@@ -9,6 +9,8 @@ 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;
/**
@@ -19,10 +21,17 @@ class PlanObjective
{
public const TABLE_NAME = 'plan_objectives';
public const TYPE_MAX_LENGTH = 64;
public const PRIORITY_MIN = 1;
public const PRIORITY_MAX = 99;
private ?int $id = null;
private ?Plan $plan = null;
private ?string $type = null;
private ?string $title = null;
private ?string $description = null;
@@ -32,6 +41,11 @@ class PlanObjective
*/
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.
*/
@@ -57,6 +71,11 @@ class PlanObjective
->addJoinColumn('plan_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();
@@ -73,12 +92,24 @@ class PlanObjective
->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: 'mautic.plan.objective.title.required'));
$metadata->addPropertyConstraint('title', new Length(max: 255));
$metadata->addPropertyConstraint('type', new NotBlank(message: 'mautic.plan.objective.type.required'));
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
$metadata->addPropertyConstraint('priority', new NotNull(message: 'mautic.plan.objective.priority.range'));
$metadata->addPropertyConstraint('priority', new Range(
notInRangeMessage: 'mautic.plan.objective.priority.range',
min: self::PRIORITY_MIN,
max: self::PRIORITY_MAX,
));
}
public function getId(): ?int
@@ -98,6 +129,18 @@ class PlanObjective
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;
@@ -134,6 +177,22 @@ class PlanObjective
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;
+2
View File
@@ -11,6 +11,8 @@ use Mautic\CoreBundle\Entity\CommonRepository;
*/
class PlanObjectiveRepository extends CommonRepository
{
use CountsItemsByTypeTrait;
public function getTableAlias(): string
{
return 'po';
+134
View File
@@ -0,0 +1,134 @@
<?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\Mapping\ClassMetadata;
/**
* The link between a plan and a stakeholder of the global directory, with the stakeholder's role in
* that plan ("Approves budget", "Media buyer"): free text, because the same person can have a
* different role on each plan.
*
* Plan::$stakeholders owns the lifecycle: links are saved and deleted with their plan. Deleting a
* stakeholder deletes its links (ON DELETE CASCADE on both sides).
*/
class PlanStakeholder
{
public const TABLE_NAME = 'plan_stakeholders_plan';
private ?int $id = null;
private ?Plan $plan = null;
private ?Stakeholder $stakeholder = null;
/**
* The stakeholder's role in this plan, free text.
*/
private ?string $roleInPlan = null;
/**
* Display order within the plan, from 0. Set by drag and drop in the form.
*/
private int $position = 0;
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(PlanStakeholderRepository::class);
$builder->addId();
$builder->createManyToOne('plan', Plan::class)
->inversedBy('stakeholders')
->addJoinColumn('plan_id', 'id', false, false, 'CASCADE')
->build();
$builder->createManyToOne('stakeholder', Stakeholder::class)
->addJoinColumn('stakeholder_id', 'id', false, false, 'CASCADE')
->build();
$builder->createField('roleInPlan', Types::STRING)
->columnName('role_in_plan')
->length(191)
->nullable()
->build();
$builder->createField('position', Types::INTEGER)
->option('default', 0)
->build();
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('stakeholder', new \Symfony\Component\Validator\Constraints\NotBlank(message: 'mautic.plan.stakeholder_link.stakeholder.required'));
$metadata->addPropertyConstraint('roleInPlan', new Length(max: 191));
}
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 getStakeholder(): ?Stakeholder
{
return $this->stakeholder;
}
public function setStakeholder(?Stakeholder $stakeholder): static
{
$this->stakeholder = $stakeholder;
return $this;
}
public function getRoleInPlan(): ?string
{
return $this->roleInPlan;
}
public function setRoleInPlan(?string $roleInPlan): static
{
$this->roleInPlan = $roleInPlan;
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position ?? 0;
return $this;
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<PlanStakeholder>
*/
class PlanStakeholderRepository extends CommonRepository
{
public function getTableAlias(): string
{
return 'psh';
}
}
+197
View File
@@ -0,0 +1,197 @@
<?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 Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* A stakeholder of the planning: a person, a company or a team involved in the plans ("Agency XYZ",
* "Exec committee"). Stakeholders are a global directory (Planning > Stakeholders), independent of
* plans; a plan links to them through PlanStakeholder, which carries the stakeholder's role in that
* plan.
*
* The type is the key of a stakeholder type set up in Settings > Configuration > Plan Settings
* (parameter plan_stakeholder_types); see ItemTypeProvider (kind "stakeholder").
*
* isPublished (from FormEntity) means "active": an unpublished stakeholder is hidden from the plan
* form's stakeholder picker, but keeps its history on the plans it is already linked to.
*/
class Stakeholder extends FormEntity
{
public const TABLE_NAME = 'plan_stakeholders';
public const TYPE_MAX_LENGTH = 64;
private ?int $id = null;
private ?string $name = null;
private ?string $email = null;
/**
* Free input, normalized to E.164 on save when it parses (StakeholderModel); the raw input is
* kept when it doesn't.
*/
private ?string $phone = null;
private ?string $role = null;
private ?string $type = null;
/**
* The links to the plans this stakeholder is assigned to. Inverse side, read-only from here: the
* links are managed from the plans (Plan::addStakeholder/removeStakeholder).
*
* @var Collection<int, PlanStakeholder>
*/
private Collection $planLinks;
public function __construct()
{
$this->planLinks = new ArrayCollection();
}
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(StakeholderRepository::class);
$builder->addId();
$builder->createField('name', Types::STRING)
->length(191)
->build();
$builder->createField('email', Types::STRING)
->length(191)
->nullable()
->build();
// Indexed for duplicate detection.
$builder->createField('phone', Types::STRING)
->length(50)
->nullable()
->build();
$builder->createField('role', Types::STRING)
->length(191)
->nullable()
->build();
$builder->createField('type', Types::STRING)
->length(self::TYPE_MAX_LENGTH)
->nullable()
->build();
$builder->createOneToMany('planLinks', PlanStakeholder::class)
->mappedBy('stakeholder')
->fetchExtraLazy()
->build();
$builder->addIndex(['email'], 'plan_stakeholder_email');
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.core.name.required'));
$metadata->addPropertyConstraint('name', new Length(max: 191));
$metadata->addPropertyConstraint('email', new Email(mode: Email::VALIDATION_MODE_HTML5, message: 'mautic.plan.stakeholder.email.invalid'));
$metadata->addPropertyConstraint('email', new Length(max: 191));
$metadata->addPropertyConstraint('phone', new Length(max: 50));
$metadata->addPropertyConstraint('role', new Length(max: 191));
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->isChanged('name', $name);
$this->name = $name;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->isChanged('email', $email);
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->isChanged('phone', $phone);
$this->phone = $phone;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): static
{
$this->isChanged('role', $role);
$this->role = $role;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
/**
* The links to the plans this stakeholder is assigned to, each with its role in that plan.
*
* @return Collection<int, PlanStakeholder>
*/
public function getPlanLinks(): Collection
{
return $this->planLinks;
}
public function setType(?string $type): static
{
$this->isChanged('type', $type);
$this->type = $type;
return $this;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<Stakeholder>
*/
class StakeholderRepository extends CommonRepository
{
use CountsItemsByTypeTrait;
public function getTableAlias(): string
{
return 'ps';
}
/**
* The list's search box matches the name, email, role and type.
*
* @param array<int, mixed> $filter
*
* @return array<int, mixed>
*/
protected function addCatchAllWhereClause($q, $filter): array
{
return $this->addStandardCatchAllWhereClause($q, $filter, [
$this->getTableAlias().'.name',
$this->getTableAlias().'.email',
$this->getTableAlias().'.role',
$this->getTableAlias().'.type',
]);
}
/**
* @return array<array{0: string, 1: string}>
*/
protected function getDefaultOrder(): array
{
return [
[$this->getTableAlias().'.name', 'ASC'],
];
}
}
+333
View File
@@ -0,0 +1,333 @@
<?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\StageBundle\Entity\Stage;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\PositiveOrZero;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* One audience of a plan's Targets tab: who the plan is aimed at, and how. Plan::$targets owns the
* lifecycle: targets are saved and deleted with their plan, and are ordered by position.
*
* The stages are the Mautic stages (Settings > 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<int, Stage>
*/
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<string>|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<int, Stage>
*/
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<string>|null
*/
public function getPreferredChannels(): ?array
{
return $this->preferredChannels;
}
/**
* @param list<string>|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;
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* How important a plan's target is to the plan. The order of the cases is the order of the dropdown.
*/
enum TargetPriority: string
{
case Primary = 'primary';
case Secondary = 'secondary';
case Exclusion = 'exclusion';
public function getLabelKey(): string
{
return 'mautic.plan.target.priority.'.$this->value;
}
public function getLabelClass(): string
{
return match ($this) {
self::Primary => 'label-success',
self::Secondary => 'label-info',
self::Exclusion => 'label-danger',
};
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<Target>
*/
class TargetRepository extends CommonRepository
{
public function getTableAlias(): string
{
return 'pt';
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* The kind of audience a plan's target describes. The order of the cases is the order of the dropdown.
*/
enum TargetType: string
{
case Persona = 'persona';
case Icp = 'icp';
case BroadAudience = 'broad_audience';
case LifecycleCohort = 'lifecycle_cohort';
case PartnerInfluencer = 'partner_influencer';
public function getLabelKey(): string
{
return 'mautic.plan.target.type.'.$this->value;
}
/**
* A fixed pictogram per type, for the unlabeled first column of the Targets tab (like the other
* tabs' pictograms, from the Remix Icon set Mautic ships).
*/
public function getIcon(): string
{
return match ($this) {
self::Persona => 'ri-user-heart-line',
self::Icp => 'ri-building-line',
self::BroadAudience => 'ri-group-line',
self::LifecycleCohort => 'ri-time-line',
self::PartnerInfluencer => 'ri-hand-heart-line',
};
}
}
+30
View File
@@ -26,10 +26,18 @@ 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;
@@ -74,6 +82,11 @@ class Task extends FormEntity implements DateRangeInterface
->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();
@@ -112,6 +125,8 @@ class Task extends FormEntity implements DateRangeInterface
$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());
}
@@ -134,6 +149,21 @@ class Task extends FormEntity implements DateRangeInterface
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;
+2
View File
@@ -11,6 +11,8 @@ use Mautic\CoreBundle\Entity\CommonRepository;
*/
class TaskRepository extends CommonRepository
{
use CountsItemsByTypeTrait;
public function getTableAlias(): string
{
return 't';