+{% endmacro %}
+
+{# One editable list of types (one per kind of plan item). #}
+{% macro type_section(types, titleKey, helpKey) %}
+ {% import _self as plan %}
+
{{ titleKey|trans }}
+
{{ helpKey|trans }}
+ {{ form_errors(types) }}
+
+
+ {{ 'mautic.plan.config.types.empty'|trans }}
+
+
+ {% for type in types %}
+ {{ plan.type_row(type) }}
+ {% endfor %}
+
+
+
+ {% do types.setRendered %}
+{% endmacro %}
+
+{% block _config_planconfig_widget %}
+{% import _self as plan %}
+
{{ 'mautic.plan.config.description'|trans }}
+
+
{{ 'mautic.plan.config.section.general'|trans }}
+
+
{{ form_row(form.children.plan_currency) }}
+
+
{{ 'mautic.plan.config.currency.help'|trans }}
+
+{{ plan.type_section(form.children.plan_description_item_types,
+ 'mautic.plan.config.section.description_item_types',
+ 'mautic.plan.config.section.description_item_types.help') }}
+
+{{ plan.type_section(form.children.plan_allocation_item_types,
+ 'mautic.plan.config.section.allocation_item_types',
+ 'mautic.plan.config.section.allocation_item_types.help') }}
+{% endblock %}
diff --git a/Resources/views/Plan/_tabs.html.twig b/Resources/views/Plan/_tabs.html.twig
new file mode 100644
index 0000000..f5f0f09
--- /dev/null
+++ b/Resources/views/Plan/_tabs.html.twig
@@ -0,0 +1,31 @@
+{#
+ # Tab bar shared by the plan form and the plan detail page.
+ #
+ # Parameters:
+ # planId: the plan's id (null for a new plan)
+ # counts (optional): tab id => number shown next to the tab name
+ #
+ # The tab panes use the ids plan-tab-. Assets/js/plan.js reopens the tab last used for this plan
+ # (so Edit, Save and Cancel keep the same tab), and on the form marks the tabs whose pane contains a
+ # validation error and opens the first of them.
+ #}
+{% set planTabs = {
+ 'details': 'mautic.plan.tab.details',
+ 'description': 'mautic.plan.tab.description',
+ 'objectives': 'mautic.plan.tab.objectives',
+ 'allocation': 'mautic.plan.tab.allocation',
+ 'targets': 'mautic.plan.tab.targets',
+ 'tasks': 'mautic.plan.tab.tasks',
+} %}
+
diff --git a/Resources/views/Plan/_task_table.html.twig b/Resources/views/Plan/_task_table.html.twig
new file mode 100644
index 0000000..b420c90
--- /dev/null
+++ b/Resources/views/Plan/_task_table.html.twig
@@ -0,0 +1,78 @@
+{#
+ # The plan's tasks, for the Tasks tab of the plan detail page and form. Same columns as the task list
+ # (Planning > Tasks): ID, Name, Description, Start date, End date, Status. Rows are in tree order:
+ # each task is followed by its sub-tasks, indented under it.
+ #
+ # Parameters:
+ # plan: the Plan
+ # taskTree: rows from TaskModel::getTaskTree(): {task, depth}, in display order
+ # readOnly: true on the plan form: no links, so that following one can't drop unsaved changes
+ # taskPermissions: plan:tasks:* permissions (create, editown, editother), when not read-only
+ #
+ # Links carry returnTo=plan, so that Save and Cancel on the task form come back to this plan
+ # (see TaskController). Opened from Planning > Tasks, the task form goes back to the task list.
+ #}
+{% set readOnly = readOnly|default(false) %}
+{% set taskPermissions = taskPermissions|default({}) %}
+{% set canCreate = not readOnly and plan.id and taskPermissions['plan:tasks:create']|default(false) %}
+
+{% if canCreate %}
+
+{% endblock %}
diff --git a/Security/Permissions/PlanPermissions.php b/Security/Permissions/PlanPermissions.php
new file mode 100644
index 0000000..315a303
--- /dev/null
+++ b/Security/Permissions/PlanPermissions.php
@@ -0,0 +1,45 @@
+ Roles. Core discovers this class from Security/Permissions/.
+ */
+class PlanPermissions extends AbstractPermissions
+{
+ /**
+ * @param mixed[] $params
+ */
+ public function __construct(array $params)
+ {
+ parent::__construct($params);
+
+ $this->addStandardPermissions('categories');
+ $this->addExtendedPermissions('plans');
+ $this->addExtendedPermissions('tasks');
+ }
+
+ public function getName(): string
+ {
+ return 'plan';
+ }
+
+ /**
+ * @param array $options
+ * @param array $data
+ */
+ public function buildForm(FormBuilderInterface &$builder, array $options, array $data): void
+ {
+ $this->addStandardFormFields('plan', 'categories', $builder, $data);
+ $this->addExtendedFormFields('plan', 'plans', $builder, $data);
+ $this->addExtendedFormFields('plan', 'tasks', $builder, $data);
+ }
+}
diff --git a/Service/CurrencyProvider.php b/Service/CurrencyProvider.php
new file mode 100644
index 0000000..4416c47
--- /dev/null
+++ b/Service/CurrencyProvider.php
@@ -0,0 +1,71 @@
+ Configuration > Plan Settings and
+ * stored in the local.php parameter plan_currency; users don't pick a currency. Amounts aren't converted
+ * when it changes: they are simply shown with the new currency.
+ */
+class CurrencyProvider
+{
+ public const CONFIG_PARAMETER = 'plan_currency';
+
+ public const DEFAULT_CURRENCY = 'EUR';
+
+ /**
+ * The main world currencies offered in the settings (ISO 4217), most traded first.
+ */
+ public const MAIN_CURRENCIES = [
+ 'USD', 'EUR', 'JPY', 'GBP', 'CNY', 'AUD', 'CAD', 'CHF', 'HKD', 'SGD',
+ 'SEK', 'NOK', 'DKK', 'NZD', 'KRW', 'INR', 'BRL', 'MXN', 'ZAR', 'PLN',
+ 'CZK', 'HUF', 'RON', 'TRY', 'AED', 'SAR', 'ILS', 'THB', 'MYR', 'IDR',
+ 'PHP', 'TWD', 'RUB', 'MAD', 'EGP', 'NGN', 'CLP', 'COP', 'ARS', 'PEN',
+ ];
+
+ public function __construct(
+ private CoreParametersHelper $coreParametersHelper,
+ private TranslatorInterface $translator,
+ ) {
+ }
+
+ /**
+ * The general currency code, e.g. "EUR".
+ */
+ public function getCurrency(): string
+ {
+ $currency = $this->coreParametersHelper->get(self::CONFIG_PARAMETER);
+
+ return is_string($currency) && in_array($currency, self::MAIN_CURRENCIES, true) ? $currency : self::DEFAULT_CURRENCY;
+ }
+
+ /**
+ * Dropdown choices: "EUR - Euro" => "EUR", names in the user's language.
+ *
+ * @return array
+ */
+ public function getChoices(): array
+ {
+ $locale = $this->translator->getLocale();
+ $choices = [];
+
+ foreach (self::MAIN_CURRENCIES as $code) {
+ try {
+ $name = Currencies::getName($code, $locale);
+ } catch (\Throwable) {
+ $name = Currencies::exists($code) ? Currencies::getName($code) : $code;
+ }
+ $choices[$code.' - '.$name] = $code;
+ }
+
+ return $choices;
+ }
+}
diff --git a/Service/ItemTypeProvider.php b/Service/ItemTypeProvider.php
new file mode 100644
index 0000000..4e766c3
--- /dev/null
+++ b/Service/ItemTypeProvider.php
@@ -0,0 +1,214 @@
+ Configuration > Plan. There is one list of types per kind of
+ * plan item:
+ * - KIND_DESCRIPTION: types of description items (Description tab), parameter plan_description_item_types;
+ * - KIND_ALLOCATION: types of allocation items (Allocation tab), parameter plan_allocation_item_types.
+ *
+ * Each list is stored in local.php, in display order:
+ *
+ * [
+ * ['key' => 'type_1a2b3c4d', 'names' => ['en_US' => 'Context', 'fr' => 'Contexte'],
+ * 'descriptions' => ['en_US' => 'Why this plan exists', 'fr' => '…'], 'icon' => 'ri-lightbulb-line'],
+ * …
+ * ]
+ *
+ * Names and descriptions fall back from the user's language to the default language (the "locale"
+ * parameter), then to the first one filled in. The key is what items store; it never changes once the
+ * type is created.
+ */
+class ItemTypeProvider
+{
+ public const KIND_DESCRIPTION = 'description';
+ public const KIND_ALLOCATION = 'allocation';
+
+ /**
+ * Kind => local.php parameter.
+ */
+ public const PARAMETERS = [
+ self::KIND_DESCRIPTION => 'plan_description_item_types',
+ self::KIND_ALLOCATION => 'plan_allocation_item_types',
+ ];
+
+ public function __construct(
+ private CoreParametersHelper $coreParametersHelper,
+ private LanguageHelper $languageHelper,
+ private TranslatorInterface $translator,
+ ) {
+ }
+
+ public static function getParameter(string $kind): string
+ {
+ return self::PARAMETERS[$kind] ?? throw new \InvalidArgumentException('Unknown item kind: '.$kind);
+ }
+
+ /**
+ * The types as stored, cleaned up: only entries with a key, names/descriptions as locale => text.
+ *
+ * @return array, descriptions: array, icon?: string}>
+ */
+ public function getTypes(string $kind): array
+ {
+ $types = $this->coreParametersHelper->get(self::getParameter($kind));
+
+ return self::normalize(is_array($types) ? $types : []);
+ }
+
+ /**
+ * Dropdown choices for an item form: localized name => key, in configured order.
+ *
+ * @return array
+ */
+ public function getChoices(string $kind, ?string $locale = null): array
+ {
+ $choices = [];
+ foreach ($this->getTypes($kind) as $type) {
+ $name = $this->pick($type['names'], $locale) ?: $type['key'];
+ // Two types with the same name would collide as choice labels; tell them apart.
+ $label = isset($choices[$name]) ? $name.' ('.$type['key'].')' : $name;
+
+ $choices[$label] = $type['key'];
+ }
+
+ return $choices;
+ }
+
+ /**
+ * Localized name of a type, or null when the key isn't a configured type of this kind.
+ */
+ public function getName(string $kind, ?string $key, ?string $locale = null): ?string
+ {
+ $type = $this->find($kind, $key);
+
+ return null === $type ? null : ($this->pick($type['names'], $locale) ?: $type['key']);
+ }
+
+ /**
+ * Localized description of a type ('' when none), or null when the key isn't a configured type.
+ */
+ public function getDescription(string $kind, ?string $key, ?string $locale = null): ?string
+ {
+ $type = $this->find($kind, $key);
+
+ return null === $type ? null : $this->pick($type['descriptions'], $locale, '');
+ }
+
+ /**
+ * Pictogram of a type (a Remix Icon class such as "ri-lightbulb-line"), or null when it has none or
+ * the key isn't a configured type. Only description item types have pictograms.
+ */
+ public function getIcon(string $kind, ?string $key): ?string
+ {
+ return $this->find($kind, $key)['icon'] ?? null;
+ }
+
+ /**
+ * Languages the admin can fill in: the languages installed in Mautic, default language first.
+ *
+ * @return array locale => language name
+ */
+ public function getLanguages(): array
+ {
+ $languages = $this->languageHelper->getSupportedLanguages();
+ $default = $this->getDefaultLocale();
+
+ if (isset($languages[$default])) {
+ $languages = [$default => $languages[$default]] + $languages;
+ }
+
+ return $languages;
+ }
+
+ public function getDefaultLocale(): string
+ {
+ $locale = $this->coreParametersHelper->get('locale');
+
+ return is_string($locale) && '' !== $locale ? $locale : 'en_US';
+ }
+
+ /**
+ * @param array $types
+ *
+ * @return array, descriptions: array, icon?: string}>
+ */
+ public static function normalize(array $types): array
+ {
+ $clean = [];
+ foreach ($types as $type) {
+ if (!is_array($type) || !isset($type['key']) || !is_string($type['key']) || '' === trim($type['key'])) {
+ continue;
+ }
+
+ $entry = [
+ 'key' => trim($type['key']),
+ 'names' => self::texts($type['names'] ?? []),
+ 'descriptions' => self::texts($type['descriptions'] ?? []),
+ ];
+
+ // Pictogram (description item types only); kept only when it's one of the offered icons.
+ if (isset($type['icon']) && is_string($type['icon']) && Pictograms::isValid($type['icon'])) {
+ $entry['icon'] = $type['icon'];
+ }
+
+ $clean[] = $entry;
+ }
+
+ return $clean;
+ }
+
+ /**
+ * @param mixed $texts
+ *
+ * @return array
+ */
+ private static function texts($texts): array
+ {
+ if (!is_array($texts)) {
+ return [];
+ }
+
+ $clean = [];
+ foreach ($texts as $locale => $text) {
+ if (is_string($locale) && is_string($text) && '' !== trim($text)) {
+ $clean[$locale] = trim($text);
+ }
+ }
+
+ return $clean;
+ }
+
+ /**
+ * @return array{key: string, names: array, descriptions: array, icon?: string}|null
+ */
+ private function find(string $kind, ?string $key): ?array
+ {
+ foreach ($this->getTypes($kind) as $type) {
+ if ($type['key'] === $key) {
+ return $type;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param array $texts
+ */
+ private function pick(array $texts, ?string $locale, ?string $empty = null): string
+ {
+ $locale ??= $this->translator->getLocale();
+
+ return $texts[$locale]
+ ?? $texts[$this->getDefaultLocale()]
+ ?? (reset($texts) ?: ($empty ?? ''));
+ }
+}
diff --git a/Service/Pictograms.php b/Service/Pictograms.php
new file mode 100644
index 0000000..d38c38d
--- /dev/null
+++ b/Service/Pictograms.php
@@ -0,0 +1,64 @@
+ Configuration > Plan
+ * Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*" classes); each one was
+ * checked against Mautic 7's icon stylesheet.
+ */
+final class Pictograms
+{
+ public const ICONS = [
+ // Ideas, goals, guidance
+ 'ri-lightbulb-line', 'ri-focus-3-line', 'ri-compass-3-line', 'ri-route-line', 'ri-flag-line',
+ 'ri-rocket-line', 'ri-trophy-line', 'ri-award-line', 'ri-medal-line', 'ri-star-line',
+ 'ri-sparkling-line', 'ri-magic-line', 'ri-key-2-line',
+ // Creative, style, tone
+ 'ri-palette-line', 'ri-brush-line', 'ri-quill-pen-line', 'ri-pencil-line', 'ri-emotion-line',
+ 'ri-emotion-happy-line', 'ri-heart-line', 'ri-thumb-up-line', 'ri-image-line', 'ri-camera-line',
+ 'ri-video-line', 'ri-mic-line', 'ri-music-line', 'ri-layout-line', 'ri-pages-line',
+ 'ri-presentation-line', 'ri-slideshow-line',
+ // Messages, content
+ 'ri-chat-quote-line', 'ri-chat-3-line', 'ri-volume-up-line', 'ri-megaphone-line', 'ri-mail-line',
+ 'ri-newspaper-line', 'ri-article-line', 'ri-file-text-line', 'ri-file-list-3-line',
+ 'ri-book-open-line', 'ri-bookmark-line', 'ri-links-line',
+ // People, market
+ 'ri-team-line', 'ri-group-line', 'ri-user-line', 'ri-user-heart-line', 'ri-customer-service-2-line',
+ 'ri-hand-heart-line', 'ri-building-line', 'ri-briefcase-line', 'ri-store-2-line',
+ 'ri-shopping-cart-line', 'ri-price-tag-3-line', 'ri-gift-line', 'ri-truck-line',
+ 'ri-global-line', 'ri-earth-line', 'ri-map-pin-line',
+ // Figures, time
+ 'ri-money-euro-circle-line', 'ri-wallet-3-line', 'ri-bar-chart-line', 'ri-pie-chart-line',
+ 'ri-line-chart-line', 'ri-calendar-line', 'ri-time-line', 'ri-timer-line',
+ // Rules, status, structure
+ 'ri-information-line', 'ri-question-line', 'ri-error-warning-line', 'ri-shield-check-line',
+ 'ri-scales-3-line', 'ri-lock-line', 'ri-checkbox-circle-line', 'ri-list-check', 'ri-search-line',
+ 'ri-eye-line', 'ri-tools-line', 'ri-settings-3-line', 'ri-stack-line', 'ri-node-tree', 'ri-leaf-line',
+ ];
+
+ public static function isValid(?string $icon): bool
+ {
+ return null !== $icon && in_array($icon, self::ICONS, true);
+ }
+
+ /**
+ * Dropdown choices: readable name => icon class, e.g. "Lightbulb" => "ri-lightbulb-line".
+ *
+ * @return array
+ */
+ public static function getChoices(): array
+ {
+ $choices = [];
+ foreach (self::ICONS as $icon) {
+ $name = preg_replace(['/^ri-/', '/-line$/'], '', $icon);
+ $name = ucfirst(str_replace('-', ' ', (string) $name));
+
+ $choices[$name] = $icon;
+ }
+
+ return $choices;
+ }
+}
diff --git a/Translations/en_US/messages.ini b/Translations/en_US/messages.ini
new file mode 100644
index 0000000..fd5d64e
--- /dev/null
+++ b/Translations/en_US/messages.ini
@@ -0,0 +1,151 @@
+mautic.plugin.plan.name="Plan"
+mautic.plan.menu.root="Planning"
+mautic.plan.menu.index="Plans"
+
+mautic.plan.tab.details="Details"
+mautic.plan.tab.description="Description"
+mautic.plan.tab.objectives="Objectives"
+mautic.plan.tab.allocation="Allocation"
+mautic.plan.tab.targets="Targets"
+mautic.plan.tab.tasks="Tasks"
+
+mautic.plan.value.none="None"
+mautic.plan.target.empty="No targets yet."
+mautic.plan.task.empty="No tasks yet."
+
+mautic.plan.header.index="Plans"
+mautic.plan.header.new="New plan"
+mautic.plan.header.edit="Edit plan - %name%"
+
+mautic.plan.onboarding.heading="No plans yet"
+mautic.plan.onboarding.subheading="Create your first plan to get started."
+mautic.plan.onboarding.copy="Use the New button above to create a plan, then track its status, dates and budget here."
+
+; Used by core's standard CRUD controller and buttons (translation base mautic.plan).
+mautic.plan.error.notfound="No plan with the ID %id% was found."
+mautic.plan.form.confirmdelete="Delete the plan, %name%? Its objectives and tasks are deleted too."
+mautic.plan.form.confirmbatchdelete="Delete the selected plans? Their objectives and tasks are deleted too."
+
+; Category type label (Settings > Categories).
+mautic.plan.category.type="Plan"
+
+; Settings > Roles.
+mautic.plan.permissions.header="Plan Permissions"
+mautic.plan.permissions.plans="Plans - User has access to"
+mautic.plan.permissions.tasks="Tasks - User has access to"
+
+; Tasks (Planning > Tasks). Translation base mautic.plan.task.
+mautic.plan.task.menu.index="Tasks"
+mautic.plan.task.header.index="Tasks"
+mautic.plan.task.header.new="New task"
+mautic.plan.task.header.edit="Edit task - %name%"
+mautic.plan.task.error.notfound="No task with the ID %id% was found."
+mautic.plan.task.form.confirmdelete="Delete the task, %name%? Its sub-tasks are kept and become top-level tasks."
+mautic.plan.task.form.confirmbatchdelete="Delete the selected tasks? Their sub-tasks are kept and become top-level tasks."
+mautic.plan.task.onboarding.heading="No tasks yet"
+mautic.plan.task.onboarding.subheading="Tasks break a plan down into work to do."
+mautic.plan.task.onboarding.copy="Use the New button above, or Add task on a plan's Tasks tab. A task belongs to one plan and can be a sub-task of another task in the same plan."
+mautic.plan.task.field.name="Name"
+mautic.plan.task.field.description="Description"
+mautic.plan.task.field.plan="Plan"
+mautic.plan.task.field.parent="Parent task"
+mautic.plan.task.field.start_date="Start date"
+mautic.plan.task.field.end_date="End date"
+mautic.plan.task.field.status="Status"
+mautic.plan.task.status.new="New"
+mautic.plan.task.status.todo="To do"
+mautic.plan.task.status.in_progress="In progress"
+mautic.plan.task.status.done="Done"
+mautic.plan.task.parent.none="None (top-level task)"
+mautic.plan.task.parent.help="A parent task must be in the same plan."
+mautic.plan.task.add="Add task"
+mautic.plan.task.save_plan_first="Save the plan first, then add tasks from its page."
+mautic.plan.task.manage_from_plan_page="Add and edit tasks from the plan's page, after saving."
+
+mautic.plan.field.name="Name"
+mautic.plan.field.status="Status"
+mautic.plan.field.owner="Owner"
+mautic.plan.field.start_date="Start date"
+mautic.plan.field.end_date="End date"
+mautic.plan.field.completed_at="Completed at"
+mautic.plan.field.budget_planned="Planned budget"
+mautic.plan.field.version="Version"
+mautic.plan.field.objectives="Objectives"
+mautic.plan.field.description_items="Description items"
+mautic.plan.field.allocation_items="Allocation items"
+
+mautic.plan.objective.field.title="Title"
+mautic.plan.objective.field.description="Description"
+mautic.plan.objective.field.is_achieved="Achieved"
+mautic.plan.objective.add="Add objective"
+mautic.plan.objective.remove="Remove objective"
+mautic.plan.objective.drag="Drag to reorder"
+mautic.plan.objective.empty="No objectives yet."
+mautic.plan.objective.progress="%achieved% of %total% achieved"
+mautic.plan.objective.achieved="Achieved"
+mautic.plan.objective.not_achieved="Not achieved"
+
+mautic.plan.owner.none="No owner"
+
+mautic.plan.status.draft="Draft"
+mautic.plan.status.planned="Planned"
+mautic.plan.status.active="Active"
+mautic.plan.status.paused="Paused"
+mautic.plan.status.completed="Completed"
+mautic.plan.status.archived="Archived"
+
+; Description items (the plan's Description tab).
+mautic.plan.description_item.field.type="Type"
+mautic.plan.description_item.field.description="Description"
+mautic.plan.description_item.add="Add description item"
+mautic.plan.description_item.remove="Remove description item"
+mautic.plan.description_item.drag="Drag to reorder"
+mautic.plan.description_item.empty="No description items yet."
+mautic.plan.description_item.no_types="No description item types are set up yet. An administrator can add them in Settings > Configuration > Plan Settings."
+mautic.plan.description_item.type.unknown="Unknown type (%key%)"
+
+; Settings > Configuration > Plan. Core builds the tab title key from the form alias.
+mautic.config.tab.planconfig="Plan Settings"
+mautic.plan.config.description="Settings of the Plan plugin."
+mautic.plan.config.section.description_item_types="Description item types"
+mautic.plan.config.section.description_item_types.help="The types offered for the items of a plan's Description tab, in this order. Give each type a name and a description in each language; the default language is required. Users see their own language, or the default language when it's empty."
+mautic.plan.config.types.empty="No types yet."
+mautic.plan.config.type.add="Add type"
+mautic.plan.config.type.remove="Remove type"
+mautic.plan.config.type.language="Language"
+mautic.plan.config.type.name="Name"
+mautic.plan.config.type.description="Description"
+
+; Allocation items (the plan's Allocation tab).
+mautic.plan.allocation_item.field.type="Type"
+mautic.plan.allocation_item.field.name="Name"
+mautic.plan.allocation_item.field.description="Description"
+mautic.plan.allocation_item.field.planned_cost="Planned cost"
+mautic.plan.allocation_item.field.real_cost="Real cost"
+mautic.plan.allocation_item.add="Add allocation item"
+mautic.plan.allocation_item.remove="Remove allocation item"
+mautic.plan.allocation_item.drag="Drag to reorder"
+mautic.plan.allocation_item.empty="No allocation items yet."
+mautic.plan.allocation_item.no_types="No allocation item types are set up yet. An administrator can add them in Settings > Configuration > Plan Settings."
+mautic.plan.allocation.total="Total"
+
+; Plan page header: total costs of the allocation items, in the general currency.
+mautic.plan.header.total_planned="Planned: %amount% %currency%"
+mautic.plan.header.total_planned.tooltip="Total planned cost of the allocation items"
+mautic.plan.header.total_real="Real: %amount% %currency%"
+mautic.plan.header.total_real.tooltip="Total real cost of the allocation items, within the planned cost"
+mautic.plan.header.total_real.over="Total real cost of the allocation items, above the planned cost"
+
+mautic.plan.task.subtask_of="Sub-task of %parent%"
+mautic.plan.task.subtasks="Number of sub-tasks"
+
+mautic.plan.config.section.allocation_item_types="Allocation item types"
+mautic.plan.config.section.allocation_item_types.help="The types offered for the cost lines of a plan's Allocation tab, in this order. Give each type a name and a description in each language; the default language is required. Users see their own language, or the default language when it's empty."
+
+mautic.plan.description_item.field.pictogram="Pictogram"
+mautic.plan.config.section.general="General"
+mautic.plan.config.currency="Currency"
+mautic.plan.config.currency.tooltip="The currency of every amount in plans: budgets, costs and totals."
+mautic.plan.config.currency.help="Users don't choose a currency: every budget, cost and total is in this currency. Changing it doesn't convert existing amounts."
+mautic.plan.config.type.icon="Pictogram"
+mautic.plan.config.type.icon.none="No pictogram"
diff --git a/Translations/en_US/validators.ini b/Translations/en_US/validators.ini
new file mode 100644
index 0000000..ae2483a
--- /dev/null
+++ b/Translations/en_US/validators.ini
@@ -0,0 +1,11 @@
+mautic.plan.owner.required="An owner is required."
+mautic.plan.end_date.before_start_date="The end date must be on or after the start date."
+mautic.plan.version.range="The version must be a whole number from 1 to 99."
+mautic.plan.objective.title.required="An objective needs a title."
+mautic.plan.task.plan.required="A task must be assigned to a plan."
+mautic.plan.task.parent.other_plan="The parent task must be in the same plan."
+mautic.plan.task.parent.loop="A task can't be its own parent, or a sub-task of one of its sub-tasks."
+mautic.plan.description_item.type.required="Choose a type."
+mautic.plan.config.type.name.required="A type needs a name in the default language."
+mautic.plan.config.type.in_use="These types are used by description items and can't be removed: %types%. Change those items to another type first."
+mautic.plan.allocation_item.type.required="Choose a type."
diff --git a/Twig/PlanExtension.php b/Twig/PlanExtension.php
new file mode 100644
index 0000000..d06a2f3
--- /dev/null
+++ b/Twig/PlanExtension.php
@@ -0,0 +1,38 @@
+ $this->typeProvider->getName($kind, $key)),
+ new TwigFunction('plan_item_type_description', fn (string $kind, ?string $key): ?string => $this->typeProvider->getDescription($kind, $key)),
+ new TwigFunction('plan_item_type_icon', fn (string $kind, ?string $key): ?string => $this->typeProvider->getIcon($kind, $key)),
+ new TwigFunction('plan_currency', fn (): string => $this->currencyProvider->getCurrency()),
+ new TwigFunction('plan_money', fn ($amount): string => number_format((float) $amount, 2)),
+ ];
+ }
+}
diff --git a/Validator/Constraints/EndDateAfterStartDate.php b/Validator/Constraints/EndDateAfterStartDate.php
new file mode 100644
index 0000000..cf7a112
--- /dev/null
+++ b/Validator/Constraints/EndDateAfterStartDate.php
@@ -0,0 +1,21 @@
+getStartDate();
+ $end = $value->getEndDate();
+
+ if (null === $start || null === $end || $end >= $start) {
+ return;
+ }
+
+ $this->context->buildViolation($constraint->message)
+ ->atPath('endDate')
+ ->addViolation();
+ }
+}
diff --git a/Validator/Constraints/ValidTaskParent.php b/Validator/Constraints/ValidTaskParent.php
new file mode 100644
index 0000000..a904d84
--- /dev/null
+++ b/Validator/Constraints/ValidTaskParent.php
@@ -0,0 +1,23 @@
+getParent();
+
+ if (null === $parent) {
+ return;
+ }
+
+ // The parent's ancestors include the task itself: the task is its own parent or a sub-task's child.
+ if ($parent->hasAncestorOrSelf($value)) {
+ $this->context->buildViolation($constraint->loopMessage)
+ ->atPath('parent')
+ ->addViolation();
+
+ return;
+ }
+
+ $plan = $value->getPlan();
+ $parentPlan = $parent->getPlan();
+
+ if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) {
+ $this->context->buildViolation($constraint->otherPlanMessage)
+ ->atPath('parent')
+ ->addViolation();
+ }
+ }
+}
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..0ce63a7
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,19 @@
+{
+ "name": "experiential/mautic-plan-bundle",
+ "description": "Plan plugin for Mautic",
+ "type": "mautic-plugin",
+ "license": "GPL-3.0-or-later",
+ "keywords": ["mautic", "plugin", "plan"],
+ "require": {
+ "php": ">=8.2",
+ "mautic/core-lib": "^7.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "MauticPlugin\\PlanBundle\\": ""
+ }
+ },
+ "extra": {
+ "install-directory-name": "PlanBundle"
+ }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..b0f0889
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,176 @@
+# Mautic Plan plugin
+
+A custom Mautic 7 plugin (`PlanBundle`) for managing plans: a name, status, owner, dates, budget and category.
+
+This repository holds only the plugin source. The bundle files are at the repository root, and Mautic loads them from `docroot/plugins/PlanBundle`.
+
+## Installation
+
+1. Copy or clone this repository into your Mautic installation as `docroot/plugins/PlanBundle`. The folder name must be `PlanBundle`.
+2. Clear the cache and register the plugin:
+
+ ```bash
+ php bin/console cache:clear
+ php bin/console mautic:plugins:reload
+ ```
+
+3. In Mautic, go to **Settings > Plugins**, open **Plan** and publish it.
+
+Plans are listed under **Planning > Plans** in the main menu (URL `/s/plans`), and tasks under **Planning > Tasks** (URL `/s/plan-tasks`). Users who aren't administrators need a role with the **Plan Permissions** set in **Settings > Roles**.
+
+Before using the items of a plan's **Description** and **Allocation** tabs, an administrator sets up their types in **Settings > Configuration > Plan Settings**.
+
+## Development
+
+Run the plugin in the shared Docker environment, [mautic-dev-env](https://git.mt3.solutions/MT3S/mautic-dev-env). Clone both repositories side by side:
+
+```
+~/projects/
+ mautic-plugin-plan/
+```
+
+In the dev environment's `.env`, point it at this plugin:
+
+```
+PLUGIN_PLAN_PATH=../mautic-plugin-plan
+```
+
+Run all commands from the `mautic-dev-env` folder:
+
+```bash
+cd ../mautic-dev-env
+./dev.sh up # start the stack
+./dev.sh install # first time only: install Mautic and register the plugin
+./dev.sh reload # after changing Config/config.php, services or entities
+```
+
+For the complete list of commands, see the dev environment's README.
+
+## Plugin structure
+
+The plugin uses the IntegrationsBundle conventions:
+
+- `PlanBundle.php`: the bundle class
+- `Config/config.php`: metadata, routes, menu and integration service tags
+- `Config/services.php`: autowires and autoconfigures every class in the bundle
+- `DependencyInjection/PlanExtension.php`: loads `Config/services.php`
+- `Integration/PlanIntegration.php`: the integration that is listed on the Plugins page
+- `Integration/Support/ConfigSupport.php`: the configuration form for the integration
+- `Translations/en_US/messages.ini` and `validators.ini`: UI strings and validation messages
+
+### Pages and permissions
+
+- `Controller/PlanController.php`: list, detail page, create, edit and delete (single and batch), built on core's `AbstractStandardFormController`
+- `Resources/views/Plan/list.html.twig`: the list. A plan's name opens its detail page.
+- `Resources/views/Plan/form.html.twig` and `details.html.twig`: the create/edit form and the detail page. Both have the same six tabs, from `_tabs.html.twig`: **Details**, **Description** (description items), **Objectives**, **Allocation** (planned budget, currency and allocation items), **Targets** and **Tasks**.
+- `Resources/views/Plan/_task_table.html.twig`: the plan's tasks in the Tasks tab. It has the same columns as **Planning > Tasks** (ID, Name, Description, Start date, End date, Status), in tree order: each task is followed by its sub-tasks, indented, and a task's name shows its number of sub-tasks. On the detail page it has an **Add task** button and links to each task. On the plan form it is read-only, so that following a link doesn't drop unsaved changes.
+- `Controller/TaskController.php` and `Resources/views/Task/`: the task list, and the create/edit form (**Planning > Tasks**). `new?plan=ID` preselects the plan. After Save or Cancel, the user goes back to where the form was opened from. Opened from **Planning > Tasks**, that's the task list. Opened from a plan's Tasks tab, whose links carry `returnTo=plan`, that's the plan (its new plan, if the task was moved). The origin is stored in the session when the form is opened, because the form posts without the query string.
+- `Assets/js/plan.js`: on the form, the objectives editor (add, remove, drag-and-drop ordering), and after a failed save, marking the tabs that contain errors with an icon and opening the first one. Started by `Mautic.planOnLoad()`.
+
+The plan's tab panes deliberately have no Bootstrap `fade` class. Core reopens the last tab used on a page (`12.tabs.js`), and the plugin opens the tab with an error after a failed save. With `fade`, those two `tab('show')` calls overlapped within the 150 ms transition and left two panes visible at once, so the Tasks tab also showed the objectives.
+
+Which tab opens on a plan's detail page and form (`Mautic.planInitTabs`):
+
+- The tab last used for a plan is remembered for the browser session (`sessionStorage`, key `mautic.plan.tab.`). The detail page and the form both reopen it, so Edit and Save keep the current tab. Cancel goes to the plans list, as in core.
+- After a failed save, the first tab with an error opens instead, and every tab with an error gets a warning icon.
+- Core reopens its own remembered tab on page load and after every Ajax request (`Mautic.rememberActiveTabs`), in an order that varies. `plan.js` wraps that function, so the plan's choice is applied right after core's restore, and only during the page load.
+- A tab counts as having an error only if it shows an error message (`.help-block .alert-danger`), not just because an element has the `has-error` class. Mautic's own `checkbox_row` theme adds `has-error` to every checkbox: it tests `errors|length is not empty`, and `0` isn't "empty" in Twig. Every objective's "Achieved" checkbox would otherwise put a warning icon on the Objectives tab, and opening that tab on load looked like a jump to Objectives.
+- `Security/Permissions/PlanPermissions.php`: the permissions shown in **Settings > Roles**
+
+The main menu has a top-level **Planning** entry, with **Plans** and **Tasks** as its items. Add future planning pages as more children of `mautic.plan.menu.root` in `Config/config.php`.
+
+The **Targets** tab only shows an empty state for now.
+
+| Route | URL | Purpose |
+| --- | --- | --- |
+| `plan_index` | `/s/plans/{page}` | Plan list, with search on name |
+| `plan_action` | `/s/plans/{objectAction}/{objectId}` | `view`, `new`, `edit`, `delete`, `batchDelete` |
+| `plan_task_index` | `/s/plan-tasks/{page}` | Task list, with search on name and description |
+| `plan_task_action` | `/s/plan-tasks/{objectAction}/{objectId}` | `new` (optional `?plan=ID`), `edit`, `delete`, `batchDelete` |
+
+The plan templates don't pass `routeBase` to core's button helpers (`page_actions`, `list_actions`) when a "close" button is involved: from `routeBase`, core builds `mautic__*` route names, which don't exist in this plugin. The other buttons use the `actionRoute` (`plan_action`) that the controller passes to the template.
+
+Permission keys:
+
+- `plan:plans:*` and `plan:tasks:*`: `viewown`, `viewother`, `editown`, `editother`, `create`, `deleteown`, `deleteother`, `publishown`, `publishother`, `full`. "Own" means items the user created (`createdBy`), as in core objects.
+- `plan:categories:*`: managing the `plan` category type.
+
+### The Plan object
+
+- `Entity/Plan.php`: the entity (table `plans`), with its Doctrine mapping and validation rules
+- `Entity/PlanStatus.php`: the status enum (`draft`, `planned`, `active`, `paused`, `completed`, `archived`)
+- `Entity/PlanRepository.php`: the repository
+- `Entity/PlanObjective.php` and `PlanObjectiveRepository.php`: a plan's objectives (table `plan_objectives`): title, description, position and an "achieved" flag
+- `Model/PlanModel.php`: the model, available as `mautic.plan.model.plan` or with `getModel('plan')`. A new plan from `getEntity()` has the current user as owner.
+- `Entity/PlanDescriptionItem.php` and `PlanDescriptionItemRepository.php`: a plan's description items (table `plan_description_items`): type, description and position. They make up the Description tab and replace the former `description` field.
+- `Form/Type/PlanType.php`, `PlanObjectiveType.php` and `PlanDescriptionItemType.php`: the create and edit form, with the objectives and the description items as collections
+- `Validator/Constraints/EndDateAfterStartDate.php`: the end date must be on or after the start date, when both are set. Used by plans and tasks, through `Entity/DateRangeInterface.php`.
+
+Behaviour to know about:
+
+- Setting the status to `completed` from another status sets `completedAt` to the current time. Moving a completed plan to any other status clears `completedAt`.
+- `owner` is required by validation, but the column is nullable: if the user is deleted, the owner becomes `NULL` (`ON DELETE SET NULL`), and the plan must be given a new owner before it can be saved again.
+- Categories use the core CategoryBundle with the `plan` type (**Settings > Categories**).
+- There is one currency for every amount: plan budgets, allocation costs and totals. It's a general setting, the **Currency** dropdown in **Settings > Configuration > Plan Settings** (parameter `plan_currency`, `EUR` by default), offering 40 main world currencies (`Service/CurrencyProvider.php`). Users never choose a currency, and amount fields show it next to the input. Changing it doesn't convert existing amounts: they're simply shown with the new currency.
+- `version` is a whole number from 1 to 99, and new plans start at 1. It is edited by hand and isn't related to Doctrine's optimistic locking.
+- Objectives belong to their plan: they are saved with it, deleted with it (`ON DELETE CASCADE` in the database too), and an objective removed from the form is deleted (`orphanRemoval`). They are always loaded ordered by `position`. On save, the model renumbers positions to 0, 1, 2… in their current order. Description items follow the same rules.
+- `getObjectives()` and `getDescriptionItems()` return the rows sorted by position, as a new collection. The mapping's `orderBy` isn't enough: after a reorder, the page shown right after saving uses the collection already loaded, in its old order.
+- Text typed in the plan form, including in objectives and description items, is kept as typed: line breaks, `&` and quotes are preserved, and HTML tags are removed. This depends on `PlanType` passing a mask array to `CleanFormSubscriber`. Without one, core HTML-encodes every value, again on each save.
+
+### Typed items: description items and allocation items
+
+- A **description item** (Description tab, `Entity/PlanDescriptionItem.php`) has a type and a description. More fields are planned.
+- An **allocation item** (Allocation tab, `Entity/PlanAllocationItem.php`, table `plan_allocation_items`) is a cost line: type, name (optional), description, planned cost and real cost. Costs are `DECIMAL(12,2)`, in the general currency.
+- Both kinds are edited inside the plan form, like objectives: add, remove, drag to reorder. They're saved and deleted with the plan.
+- An administrator sets up each kind's types in **Settings > Configuration > Plan Settings**, in two sections. Each type has a name and a description for each language installed in Mautic, and the default language (the `locale` parameter) requires a name. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown.
+- The types are stored in `config/local.php`, in the `plan_description_item_types` and `plan_allocation_item_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description` or `allocation`). In templates, use the Twig functions `plan_item_type_name(kind, key)`, `plan_item_type_description(kind, key)` and `plan_item_type_icon(kind, key)`, plus `plan_currency()` and `plan_money(amount)` (`Twig/PlanExtension.php`).
+- **Description item types have a pictogram**, chosen by the administrator from a list of Remix Icons that Mautic ships (`Service/Pictograms.php`, each checked against Mautic 7's icon stylesheet), with a live preview. It's stored as `icon` in the type. On the plan form it appears next to the type dropdown when a type is chosen. On the detail page, the Description tab is a table with three columns: Pictogram, Type, Description. Allocation item types have no pictogram.
+- Each type has a hidden key, generated when it's created and never changed. Items store that key, so renaming a type renames it everywhere.
+- A type that items use can't be removed: the configuration isn't saved, and the error lists the types and how many items use them (`EventListener/ConfigSubscriber.php`, on `CONFIG_PRE_SAVE`).
+- On the plan form, the selected type's description is shown under the type dropdown. When no types are set up, the tab says where to set them up.
+- Files: `Form/Type/ConfigType.php`, `ItemTypeConfigType.php`, `PlanDescriptionItemType.php`, `PlanAllocationItemType.php` and `Resources/views/FormTheme/Config/_config_planconfig_widget.html.twig`. Adding and removing types is handled in `Assets/js/plan.js`.
+
+### Cost totals
+
+- `Plan::getAllocationTotals()` adds up the allocation items' planned and real costs, in the general currency. The sums are done in cents, as integers.
+- The plan detail page shows them under the title, after the plan status, as on an email's page (`publishStatus` block): a "Planned" tag and a "Real" tag. A real total above the planned total is red, otherwise green.
+- The Allocation tab of the detail page lists the cost lines, followed by a total row.
+- `isAchieved` is toggled by hand on the form for now.
+
+### The Task object
+
+- `Entity/Task.php` and `TaskRepository.php`: a task (table `plan_tasks`): name, description, plan, optional parent task, optional start and end dates, and status
+- `Entity/TaskStatus.php`: the status enum. The order of its cases is the order of the dropdown: `new` (New, the default), `todo` (To do), `in_progress` (In progress), `done` (Done). Stored as `VARCHAR(20)`, indexed.
+- `Model/TaskModel.php`: the model, available as `mautic.plan.model.task` or with `getModel('plan.task')`. `getTaskTree($plan)` returns a plan's tasks in tree order, with their depth.
+- `Form/Type/TaskType.php`: the create and edit form
+- `Validator/Constraints/ValidTaskParent.php`: the parent task must be in the same plan, and must not be the task itself or one of its sub-tasks
+
+Behaviour to know about:
+
+- A task must belong to a plan. A plan can have any number of tasks, including none.
+- A task's end date must be on or after its start date, when both are set.
+- The task list (**Planning > Tasks**) shows these columns, in this order: ID, Name, Description (first 120 characters), Start date, End date, Status. Every column except Description can be sorted.
+- Deleting a plan deletes its tasks (`plan_id` `ON DELETE CASCADE`).
+- Deleting a task keeps its sub-tasks, which become top-level tasks (`parent_id` `ON DELETE SET NULL`).
+- Tasks are edited on their own pages, not inside the plan form: a task can only be picked as a parent once it exists.
+
+After you change `Assets/js/plan.js`, run `php bin/console mautic:assets:generate` (in the dev environment, `./dev.sh console mautic:assets:generate`), because production mode bundles plugin scripts into `app.js`.
+
+### Database schema
+
+Mautic creates the `plans` table from the entity mapping when it installs the plugin. However, the installer drops foreign keys that point to core tables (`users`, `categories`). `Migrations/Version_0_2_0.php` adds them and only runs when they are missing. Core runs plugin migrations when the plugin version changes, and `EventListener/PluginInstallSubscriber.php` also runs them right after a fresh install.
+
+`Migrations/Version_0_3_0.php` adds `plans.version` and the `plan_objectives` table to installs created before 0.3.0. `Migrations/Version_0_4_0.php` adds the `plan_tasks` table and its two foreign keys, and adds the foreign keys to an existing `plan_tasks` table that lacks them. `Migrations/Version_0_5_0.php` adds the tasks' `start_date`, `end_date` and `status` columns, and existing tasks get the status `new`. `Migrations/Version_0_6_0.php` creates `plan_description_items` with its foreign key to `plans` (`ON DELETE CASCADE`), and drops `plans.description`, deleting its content. `Migrations/Version_0_7_0.php` creates `plan_allocation_items` with its foreign key to `plans` (`ON DELETE CASCADE`). `Migrations/Version_0_8_0.php` drops the currency columns (`plans.currency`, `plan_allocation_items.planned_currency` and `real_currency`), since every amount is now in the general currency. Every migration checks the schema first, so it's safe to run again.
+
+If a migration builds its `CREATE TABLE` with Doctrine's `SchemaTool`, keep only the statement for its own table. `SchemaTool` also returns statements for other tables, such as Symfony Messenger's `messenger_messages`. Those fail on an existing install, and the migration engine then reports "There is no active transaction" instead of the real error.
+
+When you change the schema, add a migration in `Migrations/` and increase `version` in `Config/config.php`, then run `./dev.sh reload`.
+
+## Naming conventions
+
+To avoid collisions with other plugins, such as UTM Manager, every identifier in this bundle is prefixed with `plan`:
+
+- Service IDs: `mautic.plan.*`
+- Route names: `plan_*`
+- Translation keys: `mautic.plan.*`, plus `mautic.plugin.plan.name`
+- Permission keys: `plan:*`
diff --git a/test.fr b/test.fr
deleted file mode 100644
index e69de29..0000000