Files
mautic-marketing-program-bu…/Service/AudienceAttributes.php
T
Alexandre Gain ea88b7a772 refactor(plugin): rebrand as MT3SMarketingProgram, release 0.17.0
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_*
2026-11-15 17:48:01 +01:00

107 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Service;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
/**
* Reads the Audience attributes set up in Settings > Configuration > Program Settings.
*
* Which attributes of an audience persona are offered on the forms is chosen there, one toggle per
* attribute, so a b2b install and a b2c install define their personas differently. Each toggle is
* a local.php parameter (default enabled; an admin turns off what they don't use):
* - mt3s_marketing_program_audience_attribute_tagline (Tagline)
* - mt3s_marketing_program_audience_attribute_profile (Profile criteria)
* - mt3s_marketing_program_audience_attribute_motivations (Motivations)
* - mt3s_marketing_program_audience_attribute_barriers (Barriers)
* - mt3s_marketing_program_audience_attribute_frustrations (Frustrations)
* - mt3s_marketing_program_audience_attribute_triggers (Triggers)
* - mt3s_marketing_program_audience_attribute_decision_role (Decision-making role; values mt3s_marketing_program_audience_decision_roles)
* - mt3s_marketing_program_audience_attribute_tones (Preferred tones; values mt3s_marketing_program_audience_tones)
* - mt3s_marketing_program_audience_attribute_channels (Preferred channels)
* - mt3s_marketing_program_audience_attribute_stages (Stages)
* - mt3s_marketing_program_audience_attribute_size (Estimated size)
*
* The values of the decision roles and the tones are lists edited in the same place, with a name
* per language — read through ItemTypeProvider (kinds "audience_decision_role" and "audience_tone").
*
* The segments are NOT part of this: every audience offers them (always, purely informational).
*/
class AudienceAttributes
{
/**
* Attribute key => form field name. The keys name the local.php toggle parameters; the values
* are the Audience entity's fields. The order is the order of the forms and of the tables.
*/
public const ATTRIBUTES = [
'tagline' => 'tagline',
'profile' => 'profileCriteria',
'motivations' => 'motivations',
'barriers' => 'barriers',
'frustrations' => 'frustrations',
'triggers' => 'triggers',
'decision_role' => 'decisionRole',
'tones' => 'preferredTones',
'channels' => 'preferredChannels',
'stages' => 'stages',
'size' => 'estimatedSize',
];
public function __construct(
private CoreParametersHelper $coreParametersHelper,
) {
}
/**
* True when an attribute is offered on the audience forms. The toggle defaults to enabled, so
* an install that never touches the settings gets every attribute; turning it off stores false.
*/
public function isEnabled(string $attribute): bool
{
if (!isset(self::ATTRIBUTES[$attribute])) {
return false;
}
// Null (parameter never set) and true both mean enabled; only an explicit false turns it off.
return false !== $this->coreParametersHelper->get(self::toggleParameter($attribute));
}
/**
* The enabled attribute keys, in canonical order.
*
* @return list<string>
*/
public function getEnabled(): array
{
$enabled = [];
foreach (array_keys(self::ATTRIBUTES) as $attribute) {
if ($this->isEnabled($attribute)) {
$enabled[] = $attribute;
}
}
return $enabled;
}
/**
* The form field name of an attribute ('tagline', 'profileCriteria', …).
*/
public function getField(string $attribute): string
{
if (!isset(self::ATTRIBUTES[$attribute])) {
throw new \InvalidArgumentException('Unknown audience attribute: '.$attribute);
}
return self::ATTRIBUTES[$attribute];
}
/**
* The local.php parameter holding an attribute's toggle.
*/
public static function toggleParameter(string $attribute): string
{
return 'mt3s_marketing_program_audience_attribute_'.$attribute;
}
}