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:
1 parent
8c8d7a6f95
commit
8696acd01c
52 files changed
+3178
-125
No files matched your search
+130
-7
@@ -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());
|
||||
|
||||
|
||||
Reference in new issue
Block a user