Ejemplo n.º 1
0
 /**
  * Get the group header.
  *
  * @param EnvironmentInterface $environment    The environment.
  *
  * @param ModelInterface       $model          The model interface.
  *
  * @param string               $field          The grouping field name.
  *
  * @param int                  $groupingMode   The grouping mode.
  *
  * @param int                  $groupingLength The grouping length.
  *
  * @return string
  */
 public function formatGroupHeader($environment, $model, $field, $groupingMode, $groupingLength)
 {
     $property = $environment->getDataDefinition()->getPropertiesDefinition()->getProperty($field);
     // No property? Get out!
     if (!$property) {
         return '-';
     }
     $translator = $environment->getTranslator();
     $value = $model->getProperty($property->getName());
     $evaluation = $property->getExtra();
     if ($property->getWidgetType() == 'checkbox' && !$evaluation['multiple']) {
         return $this->formatCheckboxOptionLabel($value, $translator);
     } elseif ($groupingMode != GroupAndSortingInformationInterface::GROUP_NONE) {
         return $this->formatByGroupingMode($value, $groupingMode, $groupingLength, $environment, $property, $model);
     }
     $value = ViewHelpers::getReadableFieldValue($environment, $property, $model);
     if (isset($evaluation['reference'])) {
         $remoteNew = $evaluation['reference'][$value];
     } elseif (array_is_assoc($property->getOptions())) {
         $options = $property->getOptions();
         $remoteNew = $options[$value];
     } else {
         $remoteNew = $value;
     }
     if (is_array($remoteNew)) {
         $remoteNew = $remoteNew[0];
     }
     if (empty($remoteNew)) {
         $remoteNew = '-';
     }
     return $remoteNew;
 }
Ejemplo n.º 2
0
 /**
  * Create a new factory with basic settings from the environment.
  *
  * This factory can be used to create a new Container, Environment, DcGeneral with the same base settings as the
  * given environment.
  *
  * @param EnvironmentInterface $environment The environment to use as base.
  *
  * @return DcGeneralFactory
  */
 public static function deriveEmptyFromEnvironment(EnvironmentInterface $environment)
 {
     $factory = new DcGeneralFactory();
     $factory->setEventPropagator($environment->getEventPropagator());
     $factory->setTranslator($environment->getTranslator());
     $factory->setEnvironmentClassName(get_class($environment));
     $factory->setContainerClassName(get_class($environment->getDataDefinition()));
     return $factory;
 }
Ejemplo n.º 3
0
 /**
  * Get for a table the human readable name or a fallback.
  *
  * @param EnvironmentInterface $environment The environment in use.
  *
  * @param string               $table       Name of table.
  *
  * @return string The human readable name.
  */
 protected function getBreadcrumbLabel(EnvironmentInterface $environment, $table)
 {
     $shortTable = str_replace('tl_', '', $table);
     $label = $environment->getTranslator()->translate($shortTable, 'BRD');
     if ($label == $shortTable) {
         $shortTable = str_replace('tl_metamodel_', '', $table);
         return strtoupper(substr($shortTable, 0, 1)) . substr($shortTable, 1, strlen($shortTable) - 1) . ' %s';
     }
     return specialchars($label);
 }
 /**
  * Append wizard icons.
  *
  * @param PropertyInterface    $propInfo    The property for which the wizards shall be generated.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public static function getWizard($propInfo, EnvironmentInterface $environment)
 {
     $wizard = '';
     $dispatcher = $environment->getEventDispatcher();
     $translator = $environment->getTranslator();
     $propExtra = $propInfo->getExtra();
     $assetsPath = 'assets/mootools/colorpicker/' . $GLOBALS['TL_ASSETS']['COLORPICKER'] . '/images/';
     if (array_key_exists('colorpicker', $propExtra) && $propExtra['colorpicker']) {
         $pickerText = $translator->translate('colorpicker', 'MSC');
         $event = new GenerateHtmlEvent('pickcolor.gif', $pickerText, sprintf('style="%s" title="%s" id="moo_%s"', 'vertical-align:top;cursor:pointer', specialchars($pickerText), $propInfo->getName()));
         $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, $event);
         // Support single fields as well (see contao/core#5240)
         $strKey = $propExtra['multiple'] ? $propInfo->getName() . '_0' : $propInfo->getName();
         $wizard .= sprintf(' %1$s <script>var cl;window.addEvent("domready", function() { new MooRainbow("moo_%2$s", {' . 'id: "ctrl_%3$s", startColor: ((cl = $("ctrl_%3$s").value.hexToRgb(true)) ? cl : [255, 0, 0]),' . 'imgPath: "%4$s", onComplete: function(color) {$("ctrl_%3$s").value = color.hex.replace("#", "");}});' . '});</script>', $event->getHtml(), $propInfo->getName(), $strKey, $assetsPath);
     }
     return $wizard;
 }
Ejemplo n.º 5
0
 /**
  * Create a new instance.
  *
  * @param EnvironmentInterface $environment The environment.
  */
 public function __construct(EnvironmentInterface $environment)
 {
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $this->eventDispatcher = $environment->getEventDispatcher();
     $this->clipboardItems = $this->calculateClipboardItems();
     $dataDefinition = $environment->getDataDefinition();
     $basicDefinition = $dataDefinition->getBasicDefinition();
     $this->isHierarchical = $basicDefinition::MODE_HIERARCHICAL === $basicDefinition->getMode();
     $this->commands = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME)->getModelCommands();
     $controller = $environment->getController();
     $this->clipboardModels = $controller->getModelsFromClipboardItems($this->clipboardItems);
     $this->circularModelIds = array();
     // We must only check for CUT operation here as pasting copy'ed parents is allowed.
     $cutItems = array_filter($this->clipboardItems, function ($item) {
         /** @var ItemInterface $item */
         return $item->getAction() === $item::CUT;
     });
     $cutModels = $controller->getModelsFromClipboardItems($cutItems);
     foreach ($cutModels as $model) {
         $providerName = $model->getProviderName();
         foreach ($controller->assembleAllChildrenFrom($model) as $subModel) {
             $this->circularModelIds[] = ModelId::fromValues($providerName, $subModel)->getSerialized();
         }
     }
     if (null !== ViewHelpers::getManualSortingProperty($environment)) {
         $this->hasPasteButtons = !empty($this->clipboardItems);
         $this->hasPasteNewButton = empty($this->clipboardItems) && !$this->isHierarchical;
     } else {
         $this->hasPasteButtons = false;
         $this->hasPasteNewButton = false;
     }
 }
Ejemplo n.º 6
0
 /**
  * Retrieve the parameters for the label with attribute name and url parameter.
  *
  * @param EnvironmentInterface $environment The translator in use.
  *
  * @param ModelInterface       $model       The model.
  *
  * @return array
  */
 protected function getLabelParametersNormal(EnvironmentInterface $environment, ModelInterface $model)
 {
     $translator = $environment->getTranslator();
     return array($this->getLabelImage($model), $this->getLabelText($translator, $model), $this->getLabelComment($model, $translator), $model->getProperty('type'));
 }
Ejemplo n.º 7
0
 /**
  * Create a widget for naming contexts. Use the language and translation information from the MetaModel.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param PropertyInterface    $property      The property.
  *
  * @param IMetaModel           $metaModel     The MetaModel.
  *
  * @param string               $languageLabel The label to use for the language indicator.
  *
  * @param string               $valueLabel    The label to use for the input field.
  *
  * @param bool                 $isTextArea    If true, the widget will become a textarea, false otherwise.
  *
  * @param array                $arrValues     The values for the widget, needed to highlight the fallback language.
  *
  * @return void
  */
 public static function prepareLanguageAwareWidget(EnvironmentInterface $environment, PropertyInterface $property, IMetaModel $metaModel, $languageLabel, $valueLabel, $isTextArea, $arrValues)
 {
     if (!$metaModel->isTranslated()) {
         $extra = $property->getExtra();
         $extra['tl_class'] .= 'w50';
         $property->setWidgetType('text')->setExtra($extra);
         return;
     }
     $fallback = $metaModel->getFallbackLanguage();
     $languages = self::buildLanguageArray($metaModel, $environment->getTranslator());
     $neededKeys = array_keys($languages);
     // Ensure we have values for all languages present.
     if (array_diff_key(array_keys($arrValues), $neededKeys)) {
         foreach ($neededKeys as $langCode) {
             $arrValues[$langCode] = '';
         }
     }
     $rowClasses = array();
     foreach (array_keys($arrValues) as $langCode) {
         $rowClasses[] = $langCode == $fallback ? 'fallback_language' : 'normal_language';
     }
     $extra = $property->getExtra();
     $extra['minCount'] = $extra['maxCount'] = count($languages);
     $extra['disableSorting'] = true;
     $extra['tl_class'] = 'clr';
     $extra['columnFields'] = array('langcode' => array('label' => $languageLabel, 'exclude' => true, 'inputType' => 'justtextoption', 'options' => $languages, 'eval' => array('rowClasses' => $rowClasses, 'valign' => 'center', 'style' => 'min-width:75px;display:block;')), 'value' => array('label' => $valueLabel, 'exclude' => true, 'inputType' => $isTextArea ? 'textarea' : 'text', 'eval' => array('rowClasses' => $rowClasses, 'style' => 'width:400px;', 'rows' => 3)));
     $property->setWidgetType('multiColumnWizard')->setExtra($extra);
 }
 /**
  * @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();
     }
 }
 /**
  * Create the edit mask.
  *
  * @param EnvironmentInterface $environment   The view in use.
  *
  * @param ModelInterface       $model         The model with the current data.
  *
  * @param ModelInterface       $originalModel The data from the original data.
  *
  * @param callable             $preFunction   The function to call before saving an item.
  *
  * @param callable             $postFunction  The function to call after saving an item.
  */
 public function __construct($environment, $model, $originalModel, $preFunction, $postFunction)
 {
     $providerName = $model->getProviderName();
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $this->dispatcher = $environment->getEventDispatcher();
     $this->definition = $environment->getDataDefinition();
     $this->modelProvider = $this->definition->getDataProviderDefinition()->getInformation($providerName);
     $this->model = $model;
     $this->originalModel = $originalModel;
     $this->preFunction = $preFunction;
     $this->postFunction = $postFunction;
 }
Ejemplo n.º 10
0
 /**
  * Obtain the values of a property within a dc-general instance.
  *
  * @param IMetaModel           $metaModel   The metamodel instance to obtain the values from.
  *
  * @param EnvironmentInterface $environment The environment used in the input screen table dc-general.
  *
  * @param IAttribute           $attribute   The attribute to obtain the values for.
  *
  * @return array
  */
 private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
 {
     $factory = new DcGeneralFactory();
     $dcGeneral = $factory->setContainerName($metaModel->getTableName())->setEventDispatcher($environment->getEventDispatcher())->setTranslator($environment->getTranslator())->createDcGeneral();
     $subEnv = $dcGeneral->getEnvironment();
     $optEv = new GetPropertyOptionsEvent($subEnv, $subEnv->getDataProvider()->getEmptyModel());
     $optEv->setPropertyName($attribute->getColName());
     $subEnv->getEventDispatcher()->dispatch(GetPropertyOptionsEvent::NAME, $optEv);
     $options = $optEv->getOptions();
     return $options;
 }