예제 #1
0
파일: Subscriber.php 프로젝트: zonky2/core
 /**
  * Provide options for filter list.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getRenderSettingsOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_searchable_pages' || $event->getPropertyName() !== 'rendersetting') {
         return;
     }
     $model = $event->getModel();
     $pid = $model->getProperty('pid');
     if (empty($pid)) {
         return;
     }
     $renderSettings = $this->getDatabase()->prepare('SELECT id, name FROM tl_metamodel_rendersettings WHERE pid=?')->execute($pid);
     $options = array();
     while ($renderSettings->next()) {
         $options[$renderSettings->id] = $renderSettings->name;
     }
     $event->setOptions($options);
 }
 /**
  * Retrieve all column names of type int for the current selected table.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getSourceColumnNames(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getPropertyName() !== 'tag_srcsorting') {
         return;
     }
     $model = $event->getModel();
     $table = $model->getProperty('select_srctable');
     $database = $this->getServiceContainer()->getDatabase();
     if (!$table || !$database->tableExists($table)) {
         return;
     }
     $result = array();
     foreach ($database->listFields($table) as $arrInfo) {
         if ($arrInfo['type'] != 'index') {
             $result[$arrInfo['name']] = $arrInfo['name'];
         }
     }
     $event->setOptions($result);
 }
예제 #3
0
 /**
  * Retrieve the property options.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getPropertyOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getOptions() !== null) {
         return;
     }
     $model = $event->getModel();
     if (!$model instanceof Model) {
         return;
     }
     $attribute = $model->getItem()->getAttribute($event->getPropertyName());
     if (!$attribute instanceof AbstractSelect) {
         return;
     }
     try {
         $options = $attribute->getFilterOptions(null, false);
     } catch (\Exception $exception) {
         $options = array('Error: ' . $exception->getMessage());
     }
     $event->setOptions($options);
 }
 /**
  * @param GetPropertyOptionsEvent $event
  * @param                         $name
  * @param EventDispatcher         $eventDispatcher
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.LongVariableName)
  */
 public function eventTemplateOptions(GetPropertyOptionsEvent $event, $name, EventDispatcher $eventDispatcher)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     if ($dataDefinition->getName() !== 'orm_avisota_message_content' || $event->getPropertyName() !== 'eventTemplate') {
         return;
     }
     $getTemplateGroupEvent = new GetTemplateGroupEvent('event_');
     $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_TEMPLATE_GROUP, $getTemplateGroupEvent);
     $options = $getTemplateGroupEvent->getTemplates()->getArrayCopy();
     /** @var MessageContent $messageContent */
     $messageContent = $event->getModel()->getEntity();
     $theme = $messageContent->getMessage()->getCategory()->getLayout()->getTheme();
     if (!$theme->getTemplateDirectory()) {
         $event->setOptions($options);
         return;
     }
     $themeTemplateDirectory = scandir(TL_ROOT . '/templates/' . $theme->getTemplateDirectory());
     foreach ($themeTemplateDirectory as $file) {
         if (substr($file, 0, strlen('event_')) !== 'event_') {
             continue;
         }
         $chunks = explode('.', $file);
         $chunks = array_reverse($chunks);
         unset($chunks[0]);
         $chunks = array_reverse($chunks);
         $template = implode('.', $chunks);
         if (!array_key_exists($template, $options)) {
             $options[$template] = $template . ' (' . $theme->getTemplateDirectory() . ')';
             continue;
         }
         if (strlen($options[$template]) === strlen($template)) {
             $options[$template] = $template . ' (' . $theme->getTemplateDirectory() . ')';
             continue;
         }
         $options[$template] = str_replace('(', '(' . $theme->getTemplateDirectory() . ', ', $options[$template]);
     }
     $event->setOptions($options);
 }
 /**
  * Group leaflet markers, layers and vectors by their group.
  *
  * @param GetPropertyOptionsEvent $event The GetPropertyOptions Event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function getPropertyOptions(GetPropertyOptionsEvent $event)
 {
     $model = $event->getModel();
     if ($model instanceof Model) {
         $item = $model->getItem();
         $attribute = $item->getAttribute($event->getPropertyName());
         if (!$attribute) {
             return;
         }
         $selectTable = $attribute->get('select_table');
         $alias = $attribute->get('select_alias');
         if ($selectTable == 'tl_leaflet_layer') {
             $collection = $this->fetchOptionsCollection('Netzmacht\\Contao\\Leaflet\\Model\\LayerModel', $attribute);
             $options = OptionsBuilder::fromCollection($collection, $alias, array($this, 'parseLayerLabel'))->groupBy('pid', array($this, 'parseLayerGroup'))->getOptions();
             $event->setOptions($options);
         } elseif ($selectTable == 'tl_leaflet_vector' || $selectTable == 'tl_leaflet_marker') {
             $class = $GLOBALS['TL_MODELS'][$selectTable];
             $collection = $this->fetchOptionsCollection($class, $attribute);
             $options = OptionsBuilder::fromCollection($collection, $alias, $attribute->get('select_column'))->groupBy('pid', array($this, 'parseLayerGroup'))->getOptions();
             $event->setOptions($options);
         }
     }
 }
 /**
  * @param CreateOptionsEvent|GetPropertyOptionsEvent $event
  * @param                                            $name
  * @param EventDispatcher                            $eventDispatcher
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.ShortVariables)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function createContentTypeOptions(GetPropertyOptionsEvent $event, $name, EventDispatcher $eventDispatcher)
 {
     if ($event->getModel()->getProviderName() !== 'orm_avisota_layout' || $event->getPropertyName() !== 'allowedCellContents') {
         return;
     }
     $layout = $event->getModel()->getEntity();
     if ($layout->getType() !== 'mailChimp') {
         return;
     }
     $allTypes = $event->getOptions();
     $options = array();
     list($group, $mailChimpTemplate) = explode(':', $layout->getMailchimpTemplate());
     if (isset($GLOBALS['AVISOTA_MAILCHIMP_TEMPLATE'][$group][$mailChimpTemplate])) {
         $config = $GLOBALS['AVISOTA_MAILCHIMP_TEMPLATE'][$group][$mailChimpTemplate];
         foreach ($config['cells'] as $cellName => $cellConfig) {
             if (!isset($cellConfig['content'])) {
                 if (!isset($options[$cellName])) {
                     $options[$cellName] = array();
                 }
                 foreach ($allTypes as $elements) {
                     foreach ($elements as $elementType => $elementLabel) {
                         $options[$cellName][$cellName . ':' . $elementType] = $elementLabel;
                     }
                 }
             }
         }
     }
     $event->setOptions($options);
 }
 /**
  * Retrieve the arguments for the callback.
  *
  * @param GetPropertyOptionsEvent $event The event being emitted.
  *
  * @return array
  */
 public function getArgs($event)
 {
     return array(new DcCompat($event->getEnvironment(), $event->getModel()));
 }
예제 #8
0
파일: Subscriber.php 프로젝트: zonky2/core
 /**
  * Retrieve the options for the attributes.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getAttributeOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting' || $event->getPropertyName() !== 'attr_id') {
         return;
     }
     $model = $event->getModel();
     $metaModel = $this->getMetaModelFromModel($model);
     if (!$metaModel) {
         return;
     }
     $arrResult = array();
     // Fetch all attributes that exist in other settings.
     $alreadyTaken = $this->getDatabase()->prepare('
         SELECT
             attr_id
         FROM
             tl_metamodel_dcasetting
         WHERE
             attr_id<>?
             AND pid=?
             AND dcatype="attribute"')->execute($model->getProperty('attr_id') ?: 0, $model->getProperty('pid'))->fetchEach('attr_id');
     foreach ($metaModel->getAttributes() as $attribute) {
         if (in_array($attribute->get('id'), $alreadyTaken)) {
             continue;
         }
         $arrResult[$attribute->get('id')] = sprintf('%s [%s]', $attribute->getName(), $attribute->get('type'));
     }
     $event->setOptions($arrResult);
 }
예제 #9
0
파일: Subscriber.php 프로젝트: zonky2/core
 /**
  * Prepares a option list with alias => name connection for all attributes.
  *
  * This is used in the attr_id select box.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getAttributeIdOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_filtersetting' || $event->getPropertyName() !== 'attr_id') {
         return;
     }
     $result = array();
     $model = $event->getModel();
     $metaModel = $this->getMetaModel($model);
     $typeFactory = $this->getServiceContainer()->getFilterFactory()->getTypeFactory($model->getProperty('type'));
     $typeFilter = null;
     if ($typeFactory) {
         $typeFilter = $typeFactory->getKnownAttributeTypes();
     }
     foreach ($metaModel->getAttributes() as $attribute) {
         $typeName = $attribute->get('type');
         if ($typeFilter && !in_array($typeName, $typeFilter)) {
             continue;
         }
         $strSelectVal = $metaModel->getTableName() . '_' . $attribute->getColName();
         $result[$strSelectVal] = $attribute->getName() . ' [' . $typeName . ']';
     }
     $event->setOptions($result);
 }
예제 #10
0
 /**
  * Provide options for the values contained within a certain attribute.
  *
  * The values get prefixed with 'value_' to ensure numeric values are kept intact.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getValueOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting_condition' || $event->getPropertyName() !== 'value') {
         return;
     }
     $model = $event->getModel();
     $metaModel = $this->getMetaModel($event->getEnvironment());
     $attribute = $metaModel->getAttributeById($model->getProperty('attr_id'));
     if ($attribute) {
         $options = $attribute->getFilterOptions(null, false);
         $mangled = array();
         foreach ($options as $key => $option) {
             $mangled['value_' . $key] = $option;
         }
         $event->setOptions($mangled);
     }
 }
예제 #11
0
파일: Subscriber.php 프로젝트: zonky2/core
 /**
  * Provide options for attribute type selection.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getOptions(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getPropertyName() !== 'type') {
         return;
     }
     $services = $this->getServiceContainer();
     $translator = $event->getEnvironment()->getTranslator();
     $attributeFactory = $services->getAttributeFactory();
     $objMetaModel = $this->getMetaModelByModelPid($event->getModel());
     $flags = IAttributeFactory::FLAG_ALL_UNTRANSLATED;
     if ($objMetaModel->isTranslated()) {
         $flags |= IAttributeFactory::FLAG_INCLUDE_TRANSLATED;
     }
     $options = array();
     foreach ($attributeFactory->getTypeNames($flags) as $attributeType) {
         // Might be translated+complex or translated+simple.
         if ($attributeFactory->getTypeFactory($attributeType)->isTranslatedType() && !$objMetaModel->isTranslated()) {
             continue;
         }
         $options[$attributeType] = $translator->translate('typeOptions.' . $attributeType, 'tl_metamodel_attribute');
     }
     $event->setOptions($options);
 }
예제 #12
0
 /**
  * Retrieve all column names of type int for the current selected table.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getIntColumnNames(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getPropertyName() !== 'select_id') {
         return;
     }
     $result = $this->getColumnNamesFromMetaModel($event->getModel()->getProperty('select_table'), array('int'));
     $event->setOptions($result);
 }
예제 #13
0
 /**
  * Retrieve a list of all render modes.
  *
  * @param GetPropertyOptionsEvent $event The event.
  *
  * @return void
  */
 public function getRenderModes(GetPropertyOptionsEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca' || $event->getPropertyName() !== 'rendermode') {
         return;
     }
     $translator = $event->getEnvironment()->getTranslator();
     $options = array('flat' => $translator->translate('rendermodes.flat', 'tl_metamodel_dca'), 'hierarchical' => $translator->translate('rendermodes.hierarchical', 'tl_metamodel_dca'));
     if ($event->getModel()->getProperty('rendertype') == 'ctable') {
         $options['parented'] = $translator->translate('rendermodes.parented', 'tl_metamodel_dca');
     }
     $event->setOptions($options);
 }