Example #1
0
 /**
  * Calculate the special parameters for certain operations.
  *
  * @param CommandInterface $command           The command.
  * @param string           $serializedModelId The model id to use.
  *
  * @return string[]
  */
 private function calculateParameters(CommandInterface $command, $serializedModelId)
 {
     $parameters = (array) $command->getParameters();
     if ($command instanceof ToggleCommandInterface) {
         // Toggle has to trigger the javascript.
         $parameters['act'] = $command->getName();
         $parameters['id'] = $serializedModelId;
         return $parameters;
     }
     if ($command instanceof CutCommandInterface || $command instanceof CopyCommandInterface) {
         // Cut & copy need some special information.
         $parameters = array();
         $parameters['act'] = $command->getName();
         $inputProvider = $this->environment->getInputProvider();
         // If we have a pid add it, used for mode 4 and all parent -> current views.
         if ($inputProvider->hasParameter('pid')) {
             $parameters['pid'] = $inputProvider->getParameter('pid');
         }
         // Source is the id of the element which should move.
         $parameters['source'] = $serializedModelId;
         return $parameters;
     }
     $extra = (array) $command->getExtra();
     $idParam = isset($extra['idparam']) ? $extra['idparam'] : null;
     if ($idParam) {
         $parameters[$idParam] = $serializedModelId;
     } else {
         $parameters['id'] = $serializedModelId;
     }
     return $parameters;
 }
Example #2
0
 /**
  * Retrieve the MetaModel attached to the model condition setting.
  *
  * @param EnvironmentInterface $interface The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $interface)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE
             id=(SELECT pid FROM tl_metamodel_dca WHERE
             id=(SELECT pid FROM tl_metamodel_dcasetting WHERE id=?))')->execute(ModelId::fromSerialized($interface->getInputProvider()->getParameter('pid'))->getId());
     return $this->getMetaModelById($metaModelId->id);
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function populate(EnvironmentInterface $environment)
 {
     if (!$environment->getInputProvider()) {
         $environment->setInputProvider(new InputProvider());
     }
     if (!$environment->getClipboard()) {
         $environment->setClipboard(new DefaultClipboard());
     }
     $this->populateController($environment);
 }
 /**
  * Handle the submit and determine which button has been triggered.
  *
  * This method will redirect the client.
  *
  * @param array $buttons The registered edit buttons.
  *
  * @return void
  */
 private function handleSubmit($buttons)
 {
     $inputProvider = $this->environment->getInputProvider();
     foreach (array_keys($buttons) as $button) {
         if ($inputProvider->hasValue($button)) {
             $event = new HandleSubmitEvent($this->environment, $this->model, $button);
             $this->dispatcher->dispatch(DcGeneralFrontendEvents::HANDLE_SUBMIT, $event);
             break;
         }
     }
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function getBreadcrumbElements(EnvironmentInterface $environment, $elements)
 {
     $input = $environment->getInputProvider();
     if (!$this->isActiveTable('tl_metamodel_filter', $input)) {
         $this->filterId = $this->extractIdFrom($environment, 'pid');
     } else {
         $this->metamodelId = $this->extractIdFrom($environment, 'pid');
     }
     if (!isset($this->metamodelId)) {
         $this->metamodelId = $this->getFilter()->pid;
     }
     $elements = parent::getBreadcrumbElements($environment, $elements);
     $elements[] = array('url' => $this->generateUrl('tl_metamodel_filter', $this->seralizeId('tl_metamodel', $this->metamodelId)), 'text' => sprintf($this->getBreadcrumbLabel($environment, 'tl_metamodel_filter'), $this->getMetaModel()->getName()), 'icon' => $this->getBaseUrl() . '/system/modules/metamodels/assets/images/icons/filter.png');
     return $elements;
 }
 /**
  * {@inheritDoc}
  */
 public function populate(EnvironmentInterface $environment)
 {
     if (!$environment->getSessionStorage()) {
         $environment->setSessionStorage(new SessionStorage('DC_GENERAL_' . strtoupper($environment->getDataDefinition()->getName())));
     }
     if (!$environment->getInputProvider()) {
         $environment->setInputProvider(new InputProvider());
     }
     if (!$environment->getClipboard()) {
         $environment->setClipboard(new Clipboard());
     }
     if (!$environment->getBaseConfigRegistry()) {
         $baseConfigRegistry = new BaseConfigRegistry();
         $baseConfigRegistry->setEnvironment($environment);
         $environment->setBaseConfigRegistry($baseConfigRegistry);
     }
     $this->populateController($environment);
 }
 /**
  * Load property values.
  *
  * @return void
  */
 private function loadPropertyValues()
 {
     $flatten = $this->flatten($this->getData());
     $this->propertyValues = new PropertyValueBag($flatten);
     $this->model->setPropertiesAsArray($flatten);
     foreach ($this->getForms() as $form) {
         foreach ($form->getFields() as $field) {
             $defintion = $this->environment->getDataDefinition()->getPropertiesDefinition();
             $defintion->addProperty($field);
             if (!$this->isSubmit()) {
                 continue;
             }
             $value = $this->environment->getInputProvider()->getValue($field->getName(), true);
             // Set value to property values and to model. If validation failed, the widget manager loads data
             // from the model.
             $this->model->setProperty($field->getName(), $value);
             $this->propertyValues->setPropertyValue($field->getName(), $value);
         }
     }
 }
Example #8
0
 /**
  * Retrieve the MetaModel attached to the model filter setting.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $environment)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE id=(SELECT pid FROM tl_metamodel_dca WHERE id=?)')->execute(ModelId::fromSerialized($environment->getInputProvider()->getParameter('pid'))->getId());
     /** @noinspection PhpUndefinedFieldInspection */
     return $this->getMetaModelById($metaModelId->id);
 }
 /**
  * Is adding to the clipboard allowed.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return bool
  */
 protected function isAddingAllowed(EnvironmentInterface $environment)
 {
     $inputProvider = $environment->getInputProvider();
     // No manual sorting property defined, no need to add it to the clipboard.
     // Or we already have an after or into attribute, a handler can pick it up.
     return !ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after') || $inputProvider->hasParameter('into');
 }
Example #10
0
 /**
  * Redirect to edit mask.
  *
  * @param EnvironmentInterface $environment   The environment.
  * @param ModelIdInterface     $copiedModelId The model id.
  *
  * @return void
  */
 protected function redirect($environment, $copiedModelId)
 {
     // Build a clean url to remove the copy related arguments instad of using the AddToUrlEvent.
     $url = new BackendUrlBuilder();
     $url->setPath('contao/main.php')->setQueryParameter('do', $environment->getInputProvider()->getParameter('do'))->setQueryParameter('table', $copiedModelId->getDataProviderName())->setQueryParameter('act', 'edit')->setQueryParameter('id', $copiedModelId->getSerialized());
     $redirectEvent = new RedirectEvent($url->getUrl());
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
 }
Example #11
0
 /**
  * Check if the language has been switched.
  *
  * If so, the value in the session will be updated and the page reloaded.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  */
 private function checkLanguageSubmit($environment)
 {
     $sessionStorage = $environment->getSessionStorage();
     $inputProvider = $environment->getInputProvider();
     if ($inputProvider->getValue('FORM_SUBMIT') !== 'language_switch') {
         return;
     }
     $modelId = $inputProvider->getParameter('id') && $inputProvider->getParameter('id') ? IdSerializer::fromSerialized($inputProvider->getParameter('id'))->getId() : null;
     $languages = $environment->getController()->getSupportedLanguages($modelId);
     $providerName = $environment->getDataDefinition()->getName();
     // Get/Check the new language.
     if ($inputProvider->hasValue('language') && array_key_exists($inputProvider->getValue('language'), $languages)) {
         $session['ml_support'][$providerName][$modelId] = $inputProvider->getValue('language');
         $sessionStorage->set('dc_general', $session);
     }
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
 }
Example #12
0
 public function handleListAction(EnvironmentInterface $environment)
 {
     $input = $environment->getInputProvider();
     $id = IdSerializer::fromSerialized($input->getParameter('id'));
     $repository = EntityHelper::getRepository('Avisota\\Contao:RecipientSource');
     /** @var \Avisota\Contao\Entity\RecipientSource $recipientSourceEntity */
     $recipientSourceEntity = $repository->find($id->getId());
     /** @var RecipientSourceInterface $recipientSource */
     $recipientSource = $GLOBALS['container'][sprintf('avisota.recipientSource.%s', $recipientSourceEntity->getId())];
     if ($input->getValue('page')) {
         /** @var EventDispatcher $eventDispatcher */
         $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
         $addToUrlEvent = new AddToUrlEvent('page=' . (int) $input->getValue('page'));
         $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
         $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
     }
     $total = $recipientSource->countRecipients();
     $page = $input->getParameter('page') ?: 0;
     $pages = ceil($total / 30);
     $recipients = $recipientSource->getRecipients(30, $page * 30);
     $template = new \TwigBackendTemplate('avisota/backend/recipient_source_list');
     $template->total = $total;
     $template->page = $page;
     $template->pages = $pages;
     $template->recipients = $recipients;
     return $template->parse();
 }
Example #13
0
 /**
  * Redirects to the real back end module.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  */
 public static function redirectHome(EnvironmentInterface $environment)
 {
     $input = $environment->getInputProvider();
     if ($input->hasParameter('table') && $input->hasParameter('pid')) {
         if ($input->hasParameter('pid')) {
             $event = new RedirectEvent(sprintf('contao/main.php?do=%s&table=%s&pid=%s', $input->getParameter('do'), $input->getParameter('table'), $input->getParameter('pid')));
         } else {
             $event = new RedirectEvent(sprintf('contao/main.php?do=%s&table=%s', $input->getParameter('do'), $input->getParameter('table')));
         }
     } else {
         $event = new RedirectEvent(sprintf('contao/main.php?do=%s', $input->getParameter('do')));
     }
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $event);
 }
 /**
  * @param EnvironmentInterface $environment
  * @param                      $migrationSettings
  * @param                      $migrationId
  *
  * @return null|string
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  * @SuppressWarnings(PHPMD.LongVariable)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function generateResponse(EnvironmentInterface $environment, $migrationSettings, $migrationId)
 {
     global $container;
     $eventDispatcher = $container['event-dispatcher'];
     $input = $environment->getInputProvider();
     $translator = $environment->getTranslator();
     $entityManager = EntityHelper::getEntityManager();
     $recipientRepository = EntityHelper::getRepository('Avisota\\Contao:Recipient');
     list($offset, $skipped, $migrated, $channelMailingListMapping, $statement) = $this->getMigrationStatement($migrationSettings);
     /** @var SubscriptionManager $subscriptionManager */
     $subscriptionManager = $container['avisota.subscription'];
     $subscribeOptions = 0;
     if ($migrationSettings['ignoreBlacklist']) {
         $subscribeOptions |= SubscriptionManager::OPT_IGNORE_BLACKLIST;
     }
     $user = \BackendUser::getInstance();
     $response = new StringBuilder();
     $this->addHeaderContent($response, $translator);
     $contaoRecipients = $statement->fetchAll();
     $lastNewMigrationRecipient = (array) \Session::getInstance()->get('AVISOTA_LAST_MIGRATION_RECIPIENT' . $input->getParameter('migration'));
     foreach ($contaoRecipients as $contaoRecipientData) {
         $recipient = $recipientRepository->findOneBy(array('email' => $contaoRecipientData['email']));
         if ($recipient && in_array($recipient->getEmail(), $lastNewMigrationRecipient)) {
             $migrationSettings['overwrite'] = true;
         }
         if (!$recipient) {
             $this->addCreateRecipientInformation($response, $contaoRecipientData, $translator);
             $recipient = new Recipient();
             $recipient->setEmail($contaoRecipientData['email']);
             $recipient->setAddedById($user->id);
             $recipient->setAddedByName($user->name);
             $recipient->setAddedByUsername($user->username);
         } else {
             if (!$migrationSettings['overwrite']) {
                 $skipped++;
                 continue;
             } else {
                 $this->addSkippedRecipientInformation($response, $contaoRecipientData, $translator);
             }
         }
         $mailingList = $channelMailingListMapping[$contaoRecipientData['pid']];
         if (!$mailingList) {
             // graceful ignore missing mailing lists
             $skipped++;
             continue;
         }
         $migrateRecipientEvent = new MigrateRecipientEvent($migrationSettings, $contaoRecipientData, $recipient);
         $eventDispatcher->dispatch(RecipientEvents::MIGRATE_RECIPIENT, $migrateRecipientEvent);
         if (!$recipient->getId()) {
             $lastNewMigrationRecipient[] = $recipient->getEmail();
         }
         $entityManager->persist($recipient);
         $subscriptionManager->subscribe($recipient, $mailingList, ($contaoRecipientData['active'] ? SubscriptionManager::OPT_ACTIVATE : 0) | $subscribeOptions);
         $migrated++;
     }
     $entityManager->flush();
     if (count($contaoRecipients) < 10) {
         \Session::getInstance()->set('AVISOTA_LAST_MIGRATION_RECIPIENT' . $input->getParameter('migration'), array());
         $this->migrationFinished($migrationId, $migrated, $skipped);
         return null;
     } else {
         $offset += count($contaoRecipients);
         $this->updateRedirectSession($migrationId, $offset, $skipped, $migrated, $migrationSettings['channels'], $migrationSettings['overwrite'], $migrationSettings['importFromMembers']);
         $this->addReloadScriptAndButton($response, $translator);
         \Session::getInstance()->set('AVISOTA_LAST_MIGRATION_RECIPIENT' . $input->getParameter('migration'), $lastNewMigrationRecipient);
         return $response->__toString();
     }
 }
Example #15
0
 /**
  * Extract the id value from the serialized parameter with the given name.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param string               $parameterName The parameter name containing the id.
  *
  * @return int
  */
 protected function extractIdFrom(EnvironmentInterface $environment, $parameterName = 'pid')
 {
     $parameter = $environment->getInputProvider()->getParameter($parameterName);
     return ModelId::fromSerialized($parameter)->getId();
 }
Example #16
0
 /**
  * Copy each children.
  *
  * @param ModelIdInterface     $modelId     The model id.
  * @param ModelInterface       $copiedModel The copied model.
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.LongVariableName)
  */
 protected function copyEachChilds(ModelIdInterface $modelId, ModelInterface $copiedModel, EnvironmentInterface $environment)
 {
     $childDataProviderName = $environment->getInputProvider()->getParameter('ctable');
     $dataProvider = $environment->getDataProvider();
     $childDataProvider = $environment->getDataProvider($childDataProviderName);
     $modelRelationship = $environment->getParentDataDefinition()->getModelRelationshipDefinition();
     $childCondition = $modelRelationship->getChildCondition($copiedModel->getProviderName(), $childDataProviderName);
     if (!$childCondition) {
         return;
     }
     $parentModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
     $parentFilters = $childCondition->getFilter($parentModel);
     $copiedFilters = $childCondition->getFilter($copiedModel);
     $filter = array();
     // Todo can many filter has operation equal
     foreach ($parentFilters as $index => $parentFilter) {
         if ($parentFilter['operation'] !== '=') {
             continue;
         }
         $filter = array('parent' => $parentFilter, 'copied' => $copiedFilters[$index]);
     }
     $childModels = $childDataProvider->fetchAll($childDataProvider->getEmptyConfig()->setFilter(array($filter['parent'])));
     if ($childModels->count() < 1) {
         return;
     }
     foreach ($childModels->getModelIds() as $index => $modelId) {
         $childModel = $childModels->get($index);
         $copyModelId = ModelId::fromModel($childModel);
         $copiedChildModel = null;
         if ($environment->getDataDefinition()->getName() !== $copyModelId->getDataProviderName()) {
             $copiedChildModel = $this->copyParent($copyModelId, $environment);
         }
         if ($environment->getDataDefinition()->getName() === $copyModelId->getDataProviderName() && !$copiedChildModel) {
             $copiedChildModel = $this->copyHandler($copyModelId, $environment);
         }
         $copiedChildModel->setProperty($filter['copied']['property'], $filter['copied']['value']);
         $childDataProvider->save($copiedChildModel);
     }
 }