Files
Alexandre Gain b138056e43 style: fix indentation, alignment, and docblock annotations
- Correct getChoices() docblock to reflect translated label => enum
  backing value order instead of value => label
- Re-indent Smart Links menu config to match actual array nesting
- Align assignment operators in RefreshStatsCommand
- Add missing newline at end of RefreshStatsCommand.php
2026-11-21 11:23:33 +01:00

108 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;
}
}