Ejemplo n.º 1
0
 /**
  * Handle the "create variant" event.
  *
  * @param ActionEvent $event The action Event being executed.
  *
  * @return void
  *
  * @throws \RuntimeException When the base model can not be found.
  * @throws \InvalidArgumentException When the view in the environment is incompatible.
  */
 public function handleCreateVariantAction(ActionEvent $event)
 {
     if ($event->getAction()->getName() != 'createvariant') {
         return;
     }
     $environment = $event->getEnvironment();
     $view = $environment->getView();
     $dataProvider = $environment->getDataProvider();
     $inputProvider = $environment->getInputProvider();
     $modelId = $inputProvider->hasParameter('id') ? ModelId::fromSerialized($inputProvider->getParameter('id')) : null;
     /** @var \MetaModels\DcGeneral\Data\Driver $dataProvider */
     $model = $dataProvider->createVariant($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     if ($model == null) {
         throw new \RuntimeException(sprintf('Could not find model with id %s for creating a variant.', $modelId));
     }
     $metaModel = $this->getServiceContainer()->getFactory()->getMetaModel($model->getProviderName());
     if (!$metaModel || !$metaModel->hasVariants()) {
         return;
     }
     $preFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PreCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     $postFunction = function ($environment, $model) {
         /** @var EnvironmentInterface $environment */
         $copyEvent = new PostCreateModelEvent($environment, $model);
         $environment->getEventDispatcher()->dispatch($copyEvent::NAME, $copyEvent);
     };
     if (!$view instanceof BackendViewInterface) {
         throw new \InvalidArgumentException('Invalid view registered in environment.');
     }
     $editMask = new EditMask($view, $model, null, $preFunction, $postFunction, $this->breadcrumb($environment));
     $event->setResponse($editMask->execute());
 }
 /**
  * @param ActionEvent                   $event
  * @param null                          $eventName
  * @param EventDispatcherInterface|null $eventDispatcher
  * @SuppressWarnings(PHPMD.LongVariable)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function migrateRecipients(ActionEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
 {
     $environment = $event->getEnvironment();
     if ($environment->getDataDefinition()->getName() == 'mem_avisota_recipient_migrate' && $event->getAction()->getName() == 'migrate') {
         $input = $environment->getInputProvider();
         $migrationId = 'AVISOTA_MIGRATE_RECIPIENT_' . $input->getParameter('migration');
         if (!($migrationSettings = $this->getMigrationSettings($migrationId))) {
             return;
         }
         if (!($response = $this->generateResponse($environment, $migrationSettings, $migrationId))) {
             return;
         }
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
Ejemplo n.º 3
0
 public function generateStandardGroup(ActionEvent $event)
 {
     $action = $event->getAction();
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     if ($dataDefinition->getName() !== 'orm_avisota_salutation_group' || $action->getName() !== 'generate') {
         return;
     }
     global $AVISOTA_SALUTATION;
     $eventDispatcher = $environment->getEventDispatcher();
     $translator = $environment->getTranslator();
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_salutation'));
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('orm_avisota_salutation_group'));
     $predefinedSalutations = $AVISOTA_SALUTATION;
     $entityDataProvider = new EntityDataProvider();
     $entityDataProvider->setBaseConfig(array('source' => 'orm_avisota_salutation_group'));
     $entityManager = $entityDataProvider->getEntityManager();
     $entityAccessor = $entityDataProvider->getEntityAccessor();
     $salutationGroup = new \Avisota\Contao\Entity\SalutationGroup();
     $salutationGroup->setTitle('Default group generated at ' . date(Config::get('datimFormat')));
     $salutationGroup->setAlias(null);
     $sorting = 64;
     foreach ($predefinedSalutations as $index => $predefinedSalutation) {
         $salutation = new \Avisota\Contao\Entity\Salutation();
         $entityAccessor->setProperties($salutation, $predefinedSalutation);
         $salutation->setSalutation($translator->translate($index, 'avisota_salutation'));
         $salutation->setSalutationGroup($salutationGroup);
         $salutation->setSorting($sorting);
         $salutationGroup->addSalutation($salutation);
         $sorting *= 2;
     }
     $entityManager->persist($salutationGroup);
     $entityManager->flush($salutationGroup);
     $sessionConfirm = Session::getInstance()->get('TL_CONFIRM');
     if (!is_array($sessionConfirm)) {
         $sessionConfirm = (array) $sessionConfirm;
     }
     $sessionConfirm[] = $translator->translate('group_generated', 'orm_avisota_salutation_group');
     Session::getInstance()->set('TL_CONFIRM', $sessionConfirm);
     Controller::redirect('contao/main.php?do=avisota_salutation');
 }
Ejemplo n.º 4
0
 public function handleAction(ActionEvent $event)
 {
     $environment = $event->getEnvironment();
     if ($environment->getDataDefinition()->getName() != 'orm_avisota_queue') {
         return;
     }
     $action = $event->getAction();
     if ($action->getName() == 'clear') {
         $input = $environment->getInputProvider();
         $id = IdSerializer::fromSerialized($input->getParameter('id'));
         $repository = EntityHelper::getRepository('Avisota\\Contao:Queue');
         /** @var \Avisota\Contao\Entity\Queue $queueData */
         $queueData = $repository->find($id->getId());
         /** @var QueueInterface $queue */
         $queue = $GLOBALS['container'][sprintf('avisota.queue.%s', $queueData->getAlias())];
         $queue->execute(new NullTransport());
         $message = new AddMessageEvent(sprintf($GLOBALS['TL_LANG']['orm_avisota_queue']['queueCleared'], $queueData->getTitle()), AddMessageEvent::TYPE_CONFIRM);
         $event->getDispatcher()->dispatch(ContaoEvents::MESSAGE_ADD, $message);
         $redirect = new RedirectEvent('contao/main.php?do=avisota_queue&ref=' . TL_REFERER_ID);
         $event->getDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirect);
     }
 }
 /**
  * Handle custom events.
  *
  * @param ActionEvent $event
  * @SuppressWarnings(PHPMD.LongVariable)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function handleAction(ActionEvent $event)
 {
     if ($event->getResponse() || $event->getEnvironment()->getDataDefinition()->getName() != 'orm_avisota_recipient') {
         return;
     }
     $action = $event->getAction();
     $name = $action->getName();
     $subscribeOptions = SubscriptionManager::OPT_IGNORE_BLACKLIST;
     switch ($name) {
         case 'confirm-subscription':
             $this->handleConfirmSubscriptionAction($event);
             break;
         case 'remove-subscription':
             $this->handleRemoveSubscriptionAction($event);
             break;
         case 'subscribe-confirmed':
             $subscribeOptions |= SubscriptionManager::OPT_ACTIVATE;
             $this->handleSubscribeAction($event, $subscribeOptions);
             break;
         case 'subscribe':
             $this->handleSubscribeAction($event, $subscribeOptions);
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Handle the action event.
  *
  * @param ActionEvent $event The event to handle.
  *
  * @return void
  *
  * @throws \RuntimeException When the MetaModel could not be determined.
  */
 public function handleActionEvent(ActionEvent $event)
 {
     $environment = $event->getEnvironment();
     if ($environment->getDataDefinition()->getName() !== static::$table) {
         return;
     }
     if ($event->getAction()->getName() !== static::$actionName) {
         return;
     }
     $this->input = $environment->getInputProvider();
     $referrer = new GetReferrerEvent(true, static::$table);
     $this->dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer);
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $pid = ModelId::fromSerialized($this->input->getParameter('pid'))->getId();
     $this->metaModel = $this->getMetaModelById($this->database->prepare('SELECT * FROM ' . static::$ptable . ' WHERE id=?')->execute($pid)->pid);
     if (!$this->metaModel) {
         throw new \RuntimeException('Could not retrieve MetaModel from ' . $this->input->getParameter('pid'));
     }
     $startSort = 0;
     $this->knownAttributes = array();
     $alreadyExisting = $this->database->prepare('SELECT * FROM ' . static::$table . ' WHERE pid=? ORDER BY sorting ASC')->execute($pid);
     while ($alreadyExisting->next()) {
         $this->knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row();
         // Keep the sorting value.
         $startSort = $alreadyExisting->sorting;
     }
     if ($this->input->hasValue('add') || $this->input->hasValue('saveNclose')) {
         $this->perform($startSort + 128, $pid);
     }
     if ($this->input->hasValue('saveNclose')) {
         \Controller::redirect($referrer->getReferrerUrl());
     }
     $this->template = new \BackendTemplate('be_addallattributes');
     $this->template->href = $referrer->getReferrerUrl();
     $this->template->backBt = $this->translator->translate('MSC.backBT');
     $this->template->add = $this->translator->translate('MSC.continue');
     $this->template->saveNclose = $this->translator->translate('MSC.saveNclose');
     $this->template->headline = $this->translator->translate('addall.1', static::$table);
     $this->template->selectAll = $this->translator->translate('MSC.selectAll');
     $this->template->cacheMessage = '';
     $this->template->updateMessage = '';
     $this->template->hasCheckbox = false;
     $this->template->fields = $this->generateForm();
     $event->setResponse($this->template->parse());
 }
Ejemplo n.º 7
0
 /**
  * Initialize the panels for known actions so that they always know their state.
  *
  * @param ActionEvent $event The event.
  *
  * @return void
  */
 public function initializePanels(ActionEvent $event)
 {
     if (!in_array($event->getAction()->getName(), array('copy', 'create', 'paste', 'delete', 'move', 'undo', 'edit', 'toggle', 'showAll', 'show'))) {
         return;
     }
     $environment = $event->getEnvironment();
     $definition = $environment->getDataDefinition();
     $view = $environment->getView();
     if (!$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME) || !$view instanceof BaseView || !$view->getPanel()) {
         return;
     }
     /** @var Contao2BackendViewDefinitionInterface $backendDefinition */
     $backendDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
     $listingConfig = $backendDefinition->getListingConfig();
     $dataConfig = $environment->getBaseConfigRegistry()->getBaseConfig();
     $panel = $view->getPanel();
     ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig);
 }
Ejemplo n.º 8
0
 /**
  * @param ActionEvent $event
  */
 public function handleAction(ActionEvent $event)
 {
     if (!$event->getResponse() && $event->getEnvironment()->getDataDefinition()->getName() == 'orm_avisota_message' && $event->getAction()->getName() == 'preview') {
         $event->setResponse($this->renderPreviewView($event->getEnvironment()));
     }
 }
 /**
  * Handle "old" add to clipboard actions.
  *
  * @param ActionEvent $event The action event.
  *
  * @return void
  */
 private function addToClipboard(ActionEvent $event)
 {
     $actionName = $event->getAction()->getName();
     $environment = $event->getEnvironment();
     $input = $environment->getInputProvider();
     $clipboard = $environment->getClipboard();
     $parentIdRaw = $input->getParameter('pid');
     if ($parentIdRaw) {
         $parentId = ModelId::fromSerialized($parentIdRaw);
     } else {
         $parentId = null;
     }
     $clipboardActionName = $this->translateActionName($actionName);
     if (!$clipboardActionName) {
         return;
     }
     if ('create' === $actionName) {
         if ($this->isAddingAllowed($environment)) {
             return;
         }
         $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider();
         $item = new UnsavedItem($clipboardActionName, $parentId, $providerName);
         // Remove other create items, there can only be one create item in the clipboard or many others
         $clipboard->clear();
     } else {
         $modelIdRaw = $input->getParameter('source');
         $modelId = ModelId::fromSerialized($modelIdRaw);
         $filter = new Filter();
         $filter->andActionIs(ItemInterface::CREATE);
         $items = $clipboard->fetch($filter);
         foreach ($items as $item) {
             $clipboard->remove($item);
         }
         // Only push item to clipboard if manual sorting is used.
         if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) {
             return;
         }
         // create the new item
         $item = new Item($clipboardActionName, $parentId, $modelId);
     }
     // Let the clipboard save it's values persistent.
     $clipboard->clear()->push($item)->saveTo($environment);
     ViewHelpers::redirectHome($environment);
 }
Ejemplo n.º 10
0
 /**
  * Handle the given action.
  *
  * @param ActionEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function handleAction(ActionEvent $event)
 {
     $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalDriver.css';
     if ($event->getEnvironment()->getDataDefinition()->getName() !== $this->environment->getDataDefinition()->getName() || $event->getResponse() !== null) {
         return;
     }
     $action = $event->getAction();
     $name = $action->getName();
     switch ($name) {
         case 'select':
             // If no redirect happens, we want to display the showAll action.
             $name = 'showAll';
             // No break here.
         // No break here.
         case 'create':
         case 'paste':
         case 'move':
         case 'undo':
         case 'edit':
         case 'showAll':
             $response = call_user_func_array(array($this, $name), array_merge(array($action), $action->getArguments()));
             $event->setResponse($response);
             break;
         case 'show':
             $handler = new ShowHandler();
             $handler->handleEvent($event);
             break;
         default:
     }
 }
Ejemplo n.º 11
0
 /**
  * Handle the add all action event.
  *
  * @param ActionEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the MetaModel can not be retrieved.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function handleAddAll(ActionEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting') {
         return;
     }
     if ($event->getAction()->getName() !== 'dca_addall') {
         return;
     }
     $environment = $event->getEnvironment();
     $dispatcher = $environment->getEventDispatcher();
     $database = $this->getDatabase();
     $input = $environment->getInputProvider();
     $pid = ModelId::fromSerialized($input->getParameter('pid'));
     $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('default'));
     $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('tl_metamodel_dcasetting'));
     $referrer = new GetReferrerEvent(true, 'tl_metamodel_dcasetting');
     $dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $referrer);
     $template = new \BackendTemplate('be_autocreatepalette');
     $template->cacheMessage = '';
     $template->updateMessage = '';
     $template->href = $referrer->getReferrerUrl();
     $template->headline = $GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addall'][1];
     // Severity is: error, confirm, info, new.
     $messages = array();
     $palette = $database->prepare('SELECT * FROM tl_metamodel_dca WHERE id=?')->execute($pid->getId());
     $metaModel = $this->getMetaModelById($palette->pid);
     if (!$metaModel) {
         throw new \RuntimeException('Could not retrieve MetaModel ' . $palette->pid);
     }
     $alreadyExisting = $database->prepare('SELECT * FROM tl_metamodel_dcasetting WHERE pid=?')->execute($pid->getId());
     $knownAttributes = array();
     $intMax = 128;
     while ($alreadyExisting->next()) {
         $knownAttributes[$alreadyExisting->attr_id] = $alreadyExisting->row();
         if ($intMax < $alreadyExisting->sorting) {
             $intMax = $alreadyExisting->sorting;
         }
     }
     $blnWantPerform = false;
     // Perform the labour work.
     if ($input->getValue('act') == 'perform') {
         $this->perform($metaModel, $knownAttributes, $intMax, $pid->getId(), $messages);
     } else {
         // Loop over all attributes now.
         foreach ($metaModel->getAttributes() as $attribute) {
             if (array_key_exists($attribute->get('id'), $knownAttributes)) {
                 $messages[] = array('severity' => 'info', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_alreadycontained'], $attribute->getName()));
             } else {
                 $messages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['addAll_willadd'], $attribute->getName()));
                 $blnWantPerform = true;
             }
         }
     }
     if ($blnWantPerform) {
         $template->action = ampersand(\Environment::get('request'));
         $template->submit = $GLOBALS['TL_LANG']['MSC']['continue'];
     } else {
         $template->action = ampersand($referrer->getReferrerUrl());
         $template->submit = $GLOBALS['TL_LANG']['MSC']['saveNclose'];
     }
     $template->error = $messages;
     $event->setResponse($template->parse());
 }
Ejemplo n.º 12
0
 public function handleAction(ActionEvent $event)
 {
     $environment = $event->getEnvironment();
     if ($environment->getDataDefinition()->getName() != 'orm_avisota_recipient_source') {
         return;
     }
     $action = $event->getAction();
     if ($action->getName() == 'list') {
         $response = $this->handleListAction($environment);
         $event->setResponse($response);
     }
 }
Ejemplo n.º 13
0
 public function handleAction(ActionEvent $event)
 {
     $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalDriver.css';
     if ($event->getEnvironment()->getDataDefinition()->getName() !== $this->environment->getDataDefinition()->getName() || $event->getResponse() !== null) {
         return;
     }
     $action = $event->getAction();
     $name = $action->getName();
     switch ($name) {
         case 'copy':
         case 'copyAll':
         case 'create':
         case 'cut':
         case 'cutAll':
         case 'paste':
         case 'delete':
         case 'move':
         case 'undo':
         case 'edit':
         case 'show':
         case 'showAll':
         case 'toggle':
             $response = call_user_func_array(array($this, $name), $action->getArguments());
             $event->setResponse($response);
             break;
         default:
     }
     if ($this->getViewSection()->getModelCommands()->hasCommandNamed($name)) {
         $command = $this->getViewSection()->getModelCommands()->getCommandNamed($name);
         if ($command instanceof ToggleCommandInterface) {
             $this->toggle($name);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Handle "old" add to clipboard actions.
  *
  * @param ActionEvent $event The action event.
  *
  * @return void
  */
 private function addToClipboard(ActionEvent $event)
 {
     $actionName = $event->getAction()->getName();
     $environment = $event->getEnvironment();
     $input = $environment->getInputProvider();
     $clipboard = $environment->getClipboard();
     $parentIdRaw = $input->getParameter('pid');
     if ($parentIdRaw) {
         $parentId = ModelId::fromSerialized($parentIdRaw);
     } else {
         $parentId = null;
     }
     $clipboardActionName = $this->translateActionName($actionName);
     if (!$clipboardActionName) {
         return;
     }
     if ('create' === $actionName) {
         $inputProvider = $environment->getInputProvider();
         // No manual sorting property defined, no need to add it to the clipboard.
         // Or we already have an after attribute, a handler can pick it up.
         if (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after')) {
             return;
         }
         $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider();
         $item = new UnsavedItem($clipboardActionName, $parentId, $providerName);
         // Remove other create items, there can only be one create item in the clipboard or many others
         $clipboard->clear();
     } else {
         $modelIdRaw = $input->getParameter('source');
         $modelId = ModelId::fromSerialized($modelIdRaw);
         $filter = new Filter();
         $filter->andActionIs(ItemInterface::CREATE);
         $items = $clipboard->fetch($filter);
         foreach ($items as $item) {
             $clipboard->remove($item);
         }
         // Only push item to clipboard if manual sorting is used.
         if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) {
             return;
         }
         // create the new item
         $item = new Item($clipboardActionName, $parentId, $modelId);
     }
     // Let the clipboard save it's values persistent.
     // TODO remove clear and allow adding multiple items
     // Clipboard get cleared twice so far if being in create mode and partially in others. Don't know why it's here.
     $clipboard->clear()->push($item)->saveTo($environment);
     ViewHelpers::redirectHome($environment);
 }
Ejemplo n.º 15
0
 /**
  * Handle copy each children.
  *
  * @param ActionEvent     $event           The event.
  * @param string          $name            The event name.
  * @param EventDispatcher $eventDispatcher The event dispatcher.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function handleCopyChilds(ActionEvent $event, $name, EventDispatcher $eventDispatcher)
 {
     if ($event->getAction()->getName() !== 'copyChilds' || !\Input::get('ctable')) {
         return;
     }
     $environment = $event->getEnvironment();
     $inputProvider = $environment->getInputProvider();
     $modelId = ModelId::fromSerialized($inputProvider->getParameter('id'));
     if ($environment->getDataDefinition()->getName() !== $inputProvider->getParameter('ctable') && $environment->getParentDataDefinition()->getName() !== $modelId->getDataProviderName()) {
         $this->redirectToChildTable($environment);
     }
     $copiedParentModel = $this->copyParent($modelId, $environment);
     $this->copyEachChilds($modelId, $copiedParentModel, $environment);
     $this->redirectToChildTable($environment, true);
 }