/**
  * Convert file source to uuid before save the model.
  * After convert this is an insert tag {{file::uuid}}.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event to handle.
  *
  * @return void
  */
 public function convertFileSourceToUuid(EncodePropertyValueFromWidgetEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     $propertiesDefinition = $dataDefinition->getPropertiesDefinition();
     $property = $propertiesDefinition->getProperty($event->getProperty());
     if (!array_key_exists('rte', $property->getExtra()) || strpos($property->getExtra()['rte'], 'tiny') !== 0) {
         return;
     }
     $event->setValue(StringUtil::srcToInsertTag($event->getValue()));
 }
Esempio n. 2
0
 public function checkCsvColumnEmail(EncodePropertyValueFromWidgetEvent $event)
 {
     $value = $event->getValue();
     if (!is_array($value)) {
         $value = deserialize($value, true);
     }
     foreach ($value as $item) {
         if ($item['field'] == 'email') {
             return;
         }
     }
     throw new \RuntimeException($GLOBALS['TL_LANG']['orm_avisota_recipient_source']['missing_email_column']);
 }
Esempio n. 3
0
 /**
  * Handle event to update the sorting for DCA combinations.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function fixSortingInRows(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca_combine' || $event->getProperty() !== 'rows') {
         return;
     }
     $values = $event->getValue();
     $index = 0;
     $time = time();
     foreach (array_keys($values) as $key) {
         $values[$key]['sorting'] = $index;
         $values[$key]['tstamp'] = $time;
         $index += 128;
     }
     $event->setValue($values);
 }
Esempio n. 4
0
 /**
  * Translates an generated alias to the corresponding attribute id.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeAttrValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca_sortgroup' || $event->getProperty() !== 'rendergroupattr' && $event->getProperty() !== 'rendersortattr') {
         return;
     }
     $metaModel = self::getMetaModel($event->getEnvironment());
     $value = $event->getValue();
     if (!($metaModel && $value)) {
         return;
     }
     $value = substr($value, strlen($metaModel->getTableName() . '_'));
     $attribute = $metaModel->getAttribute($value);
     if ($attribute) {
         $event->setValue($attribute->get('id'));
     }
 }
 /**
  * Encode the values into a serialized array.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function saveValues(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getProperty() !== 'translatedtabletext_cols') {
         return;
     }
     $objMetaModel = $this->getMetaModelById($event->getModel()->getProperty('pid'));
     $varValue = $event->getValue();
     // Not translated, make it a plain string.
     if (!$objMetaModel->isTranslated()) {
         $event->setValue(serialize($varValue));
         return;
     }
     $arrLangValues = deserialize($varValue);
     $arrOutput = array();
     foreach ($arrLangValues as $varSubValue) {
         $strLangCode = $varSubValue['langcode'];
         unset($varSubValue['langcode']);
         if (count($varSubValue) > 1) {
             $arrOutput[$strLangCode] = $varSubValue;
         } else {
             $arrKeys = array_keys($varSubValue);
             $arrOutput[$strLangCode] = $varSubValue[$arrKeys[0]];
         }
     }
     $event->setValue(serialize($arrOutput));
 }
 /**
  * Retrieve the arguments for the callback.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event being emitted.
  *
  * @return array
  */
 public function getArgs($event)
 {
     return array($event->getValue(), new DcCompat($event->getEnvironment(), $event->getModel(), $event->getProperty()));
 }
Esempio n. 7
0
 /**
  * Encode the title value.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeLegendTitleValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting' || $event->getProperty() !== 'legendtitle') {
         return;
     }
     $metaModel = $this->getMetaModelFromModel($event->getModel());
     $values = Helper::encodeLangArray($event->getValue(), $metaModel);
     $event->setValue($values);
 }
Esempio n. 8
0
 /**
  * Check if the select_where value is valid by firing a test query.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the where condition is invalid.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function checkQuery(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getProperty() !== 'tag_where') {
         return;
     }
     $where = $event->getValue();
     $values = $event->getPropertyValueBag();
     if ($where) {
         $objDB = \Database::getInstance();
         $strTableName = $values->getPropertyValue('tag_table');
         $strColNameId = $values->getPropertyValue('tag_id');
         $strSortColumn = $values->getPropertyValue('tag_sorting') ?: $strColNameId;
         $query = sprintf('SELECT %1$s.*
             FROM %1$s%2$s
             ORDER BY %1$s.%3$s', $strTableName, $where ? ' WHERE (' . $where . ')' : false, $strSortColumn);
         try {
             $objDB->prepare($query)->execute();
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('%s %s', $GLOBALS['TL_LANG']['tl_metamodel_attribute']['sql_error'], $e->getMessage()));
         }
     }
 }
Esempio n. 9
0
 /**
  * Translates an generated alias {@see getAttributeNames()} to the corresponding attribute id.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeAttributeIdValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_filtersetting' || $event->getProperty() !== 'attr_id') {
         return;
     }
     $model = $event->getModel();
     $metaModel = $this->getMetaModel($model);
     $value = $event->getValue();
     if (!($metaModel && $value)) {
         return;
     }
     $value = substr($value, strlen($metaModel->getTableName() . '_'));
     $attribute = $metaModel->getAttribute($value);
     if ($attribute) {
         $event->setValue($attribute->get('id'));
     }
 }
Esempio n. 10
0
 /**
  * Translates an generated alias to the corresponding value.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeValueValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting_condition' || $event->getProperty() !== 'value') {
         return;
     }
     if (is_array($event->getValue())) {
         $values = array();
         foreach ($event->getValue() as $value) {
             $values[] = substr($value, 6);
         }
         // Cut off the 'value_' prefix.
         $event->setValue($values);
     } else {
         // Cut off the 'value_' prefix.
         $event->setValue(substr($event->getValue(), 6));
     }
 }
Esempio n. 11
0
 /**
  * Encode the given value from a real language array into a serialized language array.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the column name is illegal or duplicate.
  */
 public function encodeColumnNameValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getProperty() !== 'colname') {
         return;
     }
     $oldColumnName = $event->getModel()->getProperty($event->getProperty());
     $columnName = $event->getValue();
     $metaModel = $this->getMetaModelByModelPid($event->getModel());
     if (!$columnName || $oldColumnName !== $columnName) {
         TableManipulation::checkColumnDoesNotExist($metaModel->getTableName(), $columnName);
         $colNames = array_keys($metaModel->getAttributes());
         if (in_array($columnName, $colNames)) {
             throw new \RuntimeException(sprintf($event->getEnvironment()->getTranslator()->translate('columnExists', 'ERR'), $columnName, $metaModel->getTableName()));
         }
     }
 }
Esempio n. 12
0
 /**
  * Called by tl_metamodel.tableName onsave_callback.
  *
  * Prefixes the table name with mm_ if not provided by the user as such.
  * Checks if the table name is legal to the DB.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When no table name has been given.
  */
 public function ensureTableNamePrefix(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel' || $event->getProperty() !== 'tableName') {
         return;
     }
     // See #49.
     $tableName = strtolower($event->getValue());
     if (!strlen($tableName)) {
         throw new \RuntimeException('Table name not given');
     }
     // Force mm_ prefix.
     if (substr($tableName, 0, 3) !== 'mm_') {
         $tableName = 'mm_' . $tableName;
     }
     $dataProvider = $event->getEnvironment()->getDataProvider('tl_metamodel');
     // New model, ensure the table does not exist.
     if (!$event->getModel()->getId()) {
         TableManipulation::checkTableDoesNotExist($tableName);
     } else {
         // Edited model, ensure the value is unique and then that the table does not exist.
         $oldVersion = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($event->getModel()->getId()));
         if ($oldVersion->getProperty('tableName') !== $event->getModel()->getProperty('tableName')) {
             TableManipulation::checkTableDoesNotExist($tableName);
         }
     }
     $event->setValue($tableName);
 }
Esempio n. 13
0
 /**
  * Translates the values of the jumpTo entries into the internal array.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeJumpToValue(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_rendersettings' || $event->getProperty() !== 'jumpTo') {
         return;
     }
     $value = deserialize($event->getValue(), true);
     foreach ($value as $k => $v) {
         $value[$k]['value'] = str_replace(array('{{link_url::', '}}'), array('', ''), $v['value']);
     }
     $event->setValue(serialize($value));
 }
Esempio n. 14
0
 /**
  * Check if column email exists in the csv file.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function checkCsvColumnEmail(EncodePropertyValueFromWidgetEvent $event)
 {
     $environment = $event->getEnvironment();
     $dataProvider = $environment->getDataProvider();
     if ($dataProvider !== 'orm_avisota_recipient_source' || $dataProvider === 'orm_avisota_recipient_source' && $event->getProperty() != 'csvColumnAssignment') {
         return;
     }
     $value = $event->getValue();
     if (!is_array($value)) {
         $value = deserialize($value, true);
     }
     foreach ($value as $item) {
         if ($item['field'] == 'email') {
             return;
         }
     }
     $translator = $environment->getTranslator();
     throw new \RuntimeException($translator->translate('missing_email_column', 'orm_avisota_recipient_source'));
 }
Esempio n. 15
0
 /**
  * Translates an generated alias {@see getAttributeNames()} to the corresponding attribute id.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  */
 public function encodeAttributeIdValue(EncodePropertyValueFromWidgetEvent $event)
 {
     $isAllowed = $this->isAllowedContext($event->getEnvironment()->getDataDefinition(), $event->getProperty(), $event->getModel());
     if (!$isAllowed) {
         return;
     }
     $model = $event->getModel();
     $metaModel = $this->getMetaModel($model);
     $value = $event->getValue();
     if (!($metaModel && $value)) {
         return;
     }
     $value = substr($value, strlen($metaModel->getTableName() . '_'));
     $attribute = $metaModel->getAttribute($value);
     if ($attribute) {
         $event->setValue($attribute->get('id'));
     }
 }