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_*
This commit is contained in:
1 parent
687d33d30c
commit
ea88b7a772
131 files changed
+3238
-2836
No files matched your search
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Program;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Model\TaskModel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* List, view, create, edit and delete plans, using core's standard CRUD flow.
|
||||
*
|
||||
* Core derives most names from the model name "program": model mt3s.marketing_program.model.program, permission base
|
||||
* mt3smarketingprogram:programs (from ProgramModel), translation base mt3s.marketing_program, session base mt3s.marketing_program.
|
||||
*/
|
||||
class ProgramController extends AbstractStandardFormController
|
||||
{
|
||||
public const ROUTE_INDEX = 'mt3s_marketing_program_index';
|
||||
public const ROUTE_ACTION = 'mt3s_marketing_program_action';
|
||||
|
||||
protected function getModelName(): string
|
||||
{
|
||||
return 'mt3smp.program';
|
||||
}
|
||||
|
||||
protected function getTemplateBase(): string
|
||||
{
|
||||
return '@MT3SMarketingProgram/Program';
|
||||
}
|
||||
|
||||
/**
|
||||
* Core would build mautic_mt3s_marketing_program_index; the plugin's routes use the plan_ prefix.
|
||||
*/
|
||||
protected function getIndexRoute(): string
|
||||
{
|
||||
return self::ROUTE_INDEX;
|
||||
}
|
||||
|
||||
protected function getActionRoute(): string
|
||||
{
|
||||
return self::ROUTE_ACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function indexAction(Request $request, $page = 1): Response
|
||||
{
|
||||
return $this->indexStandard($request, $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* The program detail page (tabs: Details, Description, Objectives, Allocations, Audiences, Stakeholders, Tasks).
|
||||
*
|
||||
* Core's viewStandard() isn't used: for users who aren't administrators it checks an
|
||||
* "<entity>:export:enable" permission, which plans don't have.
|
||||
*
|
||||
* @param int $objectId
|
||||
*/
|
||||
public function viewAction(Request $request, $objectId): Response
|
||||
{
|
||||
$program = $this->getModel($this->getModelName())->getEntity((int) $objectId);
|
||||
|
||||
if (!$program instanceof Program) {
|
||||
return $this->notFound('mt3s.marketing_program.error.notfound');
|
||||
}
|
||||
|
||||
if (!$this->checkActionPermission('view', $program)) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$base = $this->getPermissionBase();
|
||||
$permissions = $this->security->isGranted(
|
||||
[
|
||||
$base.':create',
|
||||
$base.':editown',
|
||||
$base.':editother',
|
||||
$base.':deleteown',
|
||||
$base.':deleteother',
|
||||
],
|
||||
'RETURN_ARRAY',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$taskPermissions = $this->security->isGranted(
|
||||
[
|
||||
'mt3smarketingprogram:tasks:create',
|
||||
'mt3smarketingprogram:tasks:editown',
|
||||
'mt3smarketingprogram:tasks:editother',
|
||||
],
|
||||
'RETURN_ARRAY',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
return $this->delegateView([
|
||||
'viewParameters' => [
|
||||
'item' => $program,
|
||||
'permissions' => $permissions,
|
||||
'taskTree' => $this->getTaskModel()->getTaskTree($program),
|
||||
'taskPermissions' => $taskPermissions,
|
||||
// Core's page_actions helper would otherwise build mautic_plan_* route names.
|
||||
'indexRoute' => self::ROUTE_INDEX,
|
||||
'actionRoute' => self::ROUTE_ACTION,
|
||||
'tmpl' => $request->isXmlHttpRequest() ? $request->get('tmpl', 'details') : 'details',
|
||||
],
|
||||
'contentTemplate' => $this->getTemplateName('details.html.twig'),
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mt3s_marketing_program_index',
|
||||
'mauticContent' => $this->getJsLoadMethodPrefix(),
|
||||
'route' => $this->generateUrl(self::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $program->getId()]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the program's task tree to the form, for the read-only Tasks tab.
|
||||
*
|
||||
* @param array<string, mixed> $args
|
||||
* @param string $action
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getViewArguments(array $args, $action): array
|
||||
{
|
||||
$program = $args['viewParameters']['entity'] ?? null;
|
||||
|
||||
if (in_array($action, ['new', 'edit'], true) && $program instanceof Program && null !== $program->getId()) {
|
||||
$args['viewParameters']['taskTree'] = $this->getTaskModel()->getTaskTree($program);
|
||||
}
|
||||
|
||||
return parent::getViewArguments($args, $action);
|
||||
}
|
||||
|
||||
private function getTaskModel(): TaskModel
|
||||
{
|
||||
$model = $this->getModel('mt3smp.task');
|
||||
\assert($model instanceof TaskModel);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function newAction(Request $request): Response
|
||||
{
|
||||
return $this->newStandard($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $objectId
|
||||
* @param bool $ignorePost
|
||||
*/
|
||||
public function editAction(Request $request, $objectId, $ignorePost = false): Response
|
||||
{
|
||||
return $this->editStandard($request, $objectId, $ignorePost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $objectId
|
||||
*/
|
||||
public function deleteAction(Request $request, $objectId): Response
|
||||
{
|
||||
return $this->deleteStandard($request, $objectId);
|
||||
}
|
||||
|
||||
public function batchDeleteAction(Request $request): Response
|
||||
{
|
||||
return $this->batchDeleteStandard($request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user