Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle): - ProgramBundle -> MT3SMarketingProgramBundle; extension, integration, config support, permissions, events and twig extension renamed likewise - Initiative* -> Program*: controller (InitiativeController -> ProgramController), model, entities, repositories, form types and views (new _tabs/_task_table/_tab_table_filter partials, details page) - Settings config form theme -> _config_mt3smarketingprogramconfig_widget; routes and translations re-prefixed (mt3s_marketing_program_*) - Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js (OnLoad hooks renamed mt3sMpProgram*) - Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames the tables to mt3s_mp_program_*
135 lines
3.6 KiB
PHP
135 lines
3.6 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\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.
|
|
*
|
|
* Program::$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 ProgramStakeholder
|
|
{
|
|
public const TABLE_NAME = 'mt3s_mp_program_stakeholders_program';
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Program $program = null;
|
|
|
|
private ?Stakeholder $stakeholder = null;
|
|
|
|
/**
|
|
* The stakeholder's role in this plan, free text.
|
|
*/
|
|
private ?string $roleInProgram = 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->program = null;
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(ProgramStakeholderRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('program', Program::class)
|
|
->inversedBy('stakeholders')
|
|
->addJoinColumn('program_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createManyToOne('stakeholder', Stakeholder::class)
|
|
->addJoinColumn('stakeholder_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createField('roleInProgram', Types::STRING)
|
|
->columnName('role_in_program')
|
|
->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: 'mt3s.marketing_program.stakeholder_link.stakeholder.required'));
|
|
$metadata->addPropertyConstraint('roleInProgram', new Length(max: 191));
|
|
}
|
|
|
|
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 getStakeholder(): ?Stakeholder
|
|
{
|
|
return $this->stakeholder;
|
|
}
|
|
|
|
public function setStakeholder(?Stakeholder $stakeholder): static
|
|
{
|
|
$this->stakeholder = $stakeholder;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRoleInProgram(): ?string
|
|
{
|
|
return $this->roleInProgram;
|
|
}
|
|
|
|
public function setRoleInProgram(?string $roleInProgram): static
|
|
{
|
|
$this->roleInProgram = $roleInProgram;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return $this->position;
|
|
}
|
|
|
|
public function setPosition(?int $position): static
|
|
{
|
|
$this->position = $position ?? 0;
|
|
|
|
return $this;
|
|
}
|
|
}
|