|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * @copyright 2019 Mautic Contributors. All rights reserved |
| 5 | + * @author Mautic |
| 6 | + * |
| 7 | + * @link http://mautic.org |
| 8 | + * |
| 9 | + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
| 10 | + */ |
| 11 | + |
| 12 | +namespace MauticPlugin\MauticSqlConditionsBundle\Controller; |
| 13 | + |
| 14 | +use Mautic\CoreBundle\Controller\AbstractStandardFormController; |
| 15 | +use Mautic\PluginBundle\Helper\IntegrationHelper; |
| 16 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 17 | + |
| 18 | +class SqlConditionsController extends AbstractStandardFormController |
| 19 | +{ |
| 20 | + |
| 21 | + /** |
| 22 | + * {@inheritdoc} |
| 23 | + */ |
| 24 | + protected function getJsLoadMethodPrefix() |
| 25 | + { |
| 26 | + return 'sqlConditions'; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * {@inheritdoc} |
| 31 | + */ |
| 32 | + protected function getModelName() |
| 33 | + { |
| 34 | + return 'sqlConditions.sqlConditions'; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * {@inheritdoc} |
| 39 | + */ |
| 40 | + protected function getRouteBase() |
| 41 | + { |
| 42 | + return 'sqlConditions'; |
| 43 | + } |
| 44 | + |
| 45 | + /*** |
| 46 | + * @param null $objectId |
| 47 | + * |
| 48 | + * @return string |
| 49 | + */ |
| 50 | + protected function getSessionBase($objectId = null) |
| 51 | + { |
| 52 | + return 'sqlConditions'.(($objectId) ? '.'.$objectId : ''); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @return string |
| 57 | + */ |
| 58 | + protected function getControllerBase() |
| 59 | + { |
| 60 | + return 'MauticSqlConditionsBundle:SqlConditions'; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
| 65 | + */ |
| 66 | + public function batchDeleteAction() |
| 67 | + { |
| 68 | + return $this->batchDeleteStandard(); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @param $objectId |
| 73 | + * |
| 74 | + * @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
| 75 | + */ |
| 76 | + public function cloneAction($objectId) |
| 77 | + { |
| 78 | + return $this->cloneStandard($objectId); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @param $objectId |
| 83 | + * @param bool $ignorePost |
| 84 | + * |
| 85 | + * @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse |
| 86 | + */ |
| 87 | + public function editAction($objectId, $ignorePost = false) |
| 88 | + { |
| 89 | + return $this->editStandard($objectId, $ignorePost); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @param int $page |
| 94 | + * |
| 95 | + * @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
| 96 | + */ |
| 97 | + public function indexAction($page = 1) |
| 98 | + { |
| 99 | + return $this->indexStandard($page); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse |
| 104 | + */ |
| 105 | + public function newAction() |
| 106 | + { |
| 107 | + return $this->newStandard(); |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + /** |
| 112 | + * @param $objectId |
| 113 | + * |
| 114 | + * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
| 115 | + */ |
| 116 | + public function viewAction($objectId) |
| 117 | + { |
| 118 | + return $this->viewStandard($objectId, $this->getModelName(), null, null, 'entity'); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @param $args |
| 123 | + * @param $action |
| 124 | + * |
| 125 | + * @return mixed |
| 126 | + */ |
| 127 | + protected function getViewArguments(array $args, $action) |
| 128 | + { |
| 129 | + $viewParameters = []; |
| 130 | + switch ($action) { |
| 131 | + case 'new': |
| 132 | + case 'edit': |
| 133 | + break; |
| 134 | + case 'view': |
| 135 | + break; |
| 136 | + } |
| 137 | + $args['viewParameters'] = array_merge($args['viewParameters'], $viewParameters); |
| 138 | + |
| 139 | + return $args; |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + /** |
| 144 | + * @param $objectId |
| 145 | + * |
| 146 | + * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
| 147 | + */ |
| 148 | + protected function deleteAction($objectId) |
| 149 | + { |
| 150 | + return $this->deleteStandard($objectId); |
| 151 | + } |
| 152 | + |
| 153 | + protected function getDefaultOrderColumn() |
| 154 | + { |
| 155 | + return 'id'; |
| 156 | + } |
| 157 | + |
| 158 | + |
| 159 | + /** |
| 160 | + * @param int $objectId |
| 161 | + * |
| 162 | + * @return JsonResponse|\Symfony\Component\HttpFoundation\Response |
| 163 | + */ |
| 164 | + public function batchCronsAction($objectId = 0) |
| 165 | + { |
| 166 | + /** @var \Mautic\LeadBundle\Model\LeadModel $model */ |
| 167 | + $model = $this->getModel('sqlConditions'); |
| 168 | + /** @var IntegrationHelper $integrationHelper */ |
| 169 | + $integrationHelper = $this->get('mautic.helper.integration'); |
| 170 | + $integration = $integrationHelper->getIntegrationObject('SqlConditions'); |
| 171 | + |
| 172 | + if (false === $integration || !$integration->getIntegrationSettings()->getIsPublished()) { |
| 173 | + return; |
| 174 | + } |
| 175 | + $settings = $integration->mergeConfigToFeatureSettings(); |
| 176 | + $ids = $this->request->get('ids'); |
| 177 | + $entities = $model->getEntities( |
| 178 | + [ |
| 179 | + 'filter' => [ |
| 180 | + 'force' => [ |
| 181 | + [ |
| 182 | + 'column' => 'e.id', |
| 183 | + 'expr' => 'in', |
| 184 | + 'value' => $ids, |
| 185 | + ], |
| 186 | + ], |
| 187 | + ], |
| 188 | + 'ignore_paginator' => true, |
| 189 | + ] |
| 190 | + ); |
| 191 | + return $this->delegateView( |
| 192 | + [ |
| 193 | + 'viewParameters' => [ |
| 194 | + 'entities' => $entities, |
| 195 | + 'crons' => $settings['crons'], |
| 196 | + 'pathsHelper' => $this->get('mautic.helper.paths'), |
| 197 | + ], |
| 198 | + 'contentTemplate' => 'MauticSqlConditionsBundle:Batch:crons.html.php', |
| 199 | + ] |
| 200 | + ); |
| 201 | + } |
| 202 | +} |
0 commit comments