/**
  * Get arguments for label
  *
  * @param InterfaceGeneralModel $objModelRow
  * @return array
  */
 protected function getListViewLabelArguments($objModelRow)
 {
     if ($this->getDC()->arrDCA['list']['sorting']['mode'] == 6) {
         $this->loadDataContainer($objDC->getParentTable());
         $objTmpDC = new DC_General($objDC->getParentTable());
         $arrCurrentDCA = $objTmpDC->getDCA();
     } else {
         $arrCurrentDCA = $this->getDC()->arrDCA;
     }
     $args = array();
     $showFields = $arrCurrentDCA['list']['label']['fields'];
     // Label
     foreach ($showFields as $k => $v) {
         if (strpos($v, ':') !== false) {
             $args[$k] = $objModelRow->getMeta(DCGE::MODEL_LABEL_ARGS);
         } elseif (in_array($this->getDC()->arrDCA['fields'][$v]['flag'], array(5, 6, 7, 8, 9, 10))) {
             if ($this->getDC()->arrDCA['fields'][$v]['eval']['rgxp'] == 'date') {
                 $args[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objModelRow->getProperty($v));
             } elseif ($this->getDC()->arrDCA['fields'][$v]['eval']['rgxp'] == 'time') {
                 $args[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objModelRow->getProperty($v));
             } else {
                 $args[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objModelRow->getProperty($v));
             }
         } elseif ($this->getDC()->arrDCA['fields'][$v]['inputType'] == 'checkbox' && !$this->getDC()->arrDCA['fields'][$v]['eval']['multiple']) {
             $args[$k] = strlen($objModelRow->getProperty($v)) ? $arrCurrentDCA['fields'][$v]['label'][0] : '';
         } else {
             $row = deserialize($objModelRow->getProperty($v));
             if (is_array($row)) {
                 $args_k = array();
                 foreach ($row as $option) {
                     $args_k[] = strlen($arrCurrentDCA['fields'][$v]['reference'][$option]) ? $arrCurrentDCA['fields'][$v]['reference'][$option] : $option;
                 }
                 $args[$k] = implode(', ', $args_k);
             } elseif (isset($arrCurrentDCA['fields'][$v]['reference'][$objModelRow->getProperty($v)])) {
                 $args[$k] = is_array($arrCurrentDCA['fields'][$v]['reference'][$objModelRow->getProperty($v)]) ? $arrCurrentDCA['fields'][$v]['reference'][$objModelRow->getProperty($v)][0] : $arrCurrentDCA['fields'][$v]['reference'][$objModelRow->getProperty($v)];
             } elseif (($arrCurrentDCA['fields'][$v]['eval']['isAssociative'] || array_is_assoc($arrCurrentDCA['fields'][$v]['options'])) && isset($arrCurrentDCA['fields'][$v]['options'][$objModelRow->getProperty($v)])) {
                 $args[$k] = $arrCurrentDCA['fields'][$v]['options'][$objModelRow->getProperty($v)];
             } else {
                 $args[$k] = $objModelRow->getProperty($v);
             }
         }
     }
     return $args;
 }
 /**
  * Check if two models have the same values in all properties.
  *
  * @param InterfaceGeneralModel $objModel1 The first model to compare.
  *
  * @param InterfaceGeneralModel $objModel2 The second model to compare.
  *
  * @return boolean True - If both models are same, false if not.
  */
 public function sameModels($objModel1, $objModel2)
 {
     foreach ($objModel1 as $key => $value) {
         if ($key == "id") {
             continue;
         }
         if (is_array($value)) {
             if (!is_array($objModel2->getProperty($key))) {
                 return false;
             }
             if (serialize($value) != serialize($objModel2->getProperty($key))) {
                 return false;
             }
         } else {
             if ($value != $objModel2->getProperty($key)) {
                 return false;
             }
         }
     }
     return true;
 }
 public function sortCollection(InterfaceGeneralModel $a, InterfaceGeneralModel $b)
 {
     if ($a->getProperty($this->arrColSort['field']) == $b->getProperty($this->arrColSort['field'])) {
         return 0;
     }
     if (!$this->arrColSort['reverse']) {
         return $a->getProperty($this->arrColSort['field']) < $b->getProperty($this->arrColSort['field']) ? -1 : 1;
     } else {
         return $a->getProperty($this->arrColSort['field']) < $b->getProperty($this->arrColSort['field']) ? 1 : -1;
     }
 }
Exemple #4
0
 /**
  * Get for a field the readable value
  *
  * @param string $strFieldName
  * @param mixed $mixValue
  * @return mixed [string|int]
  */
 public function getReadableFieldValue($strFieldName, $mixValue)
 {
     if (!key_exists($strFieldName, $this->arrDCA['fields'])) {
         return $mixValue;
     }
     // Load the config for current field
     $arrFieldConfig = $this->arrDCA['fields'][$strFieldName];
     $mixModelField = $this->objCurrentModel->getProperty($strFieldName);
     /*
      * @todo Maybe the controlle should handle this ?
      */
     if (isset($arrFieldConfig['foreignKey'])) {
         $temp = array();
         $chunks = explode('.', $arrFieldConfig['foreignKey'], 2);
         foreach ((array) $value as $v) {
             //                    $objKey = $this->Database->prepare("SELECT " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id=?")
             //                            ->limit(1)
             //                            ->execute($v);
             //
             //                    if ($objKey->numRows)
             //                    {
             //                        $temp[] = $objKey->value;
             //                    }
         }
         //                $row[$i] = implode(', ', $temp);
     } else {
         if (is_array($mixValue)) {
             foreach ($mixValue as $kk => $vv) {
                 if (is_array($vv)) {
                     $vals = array_values($vv);
                     $mixValue[$kk] = $vals[0] . ' (' . $vals[1] . ')';
                 }
             }
             return implode(', ', $mixValue);
         } else {
             if ($arrFieldConfig['eval']['rgxp'] == 'date') {
                 return $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $mixValue);
             } else {
                 if ($arrFieldConfig['eval']['rgxp'] == 'time') {
                     return $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $mixValue);
                 } else {
                     if ($arrFieldConfig['eval']['rgxp'] == 'datim' || in_array($arrFieldConfig['flag'], array(5, 6, 7, 8, 9, 10)) || $strFieldName == 'tstamp') {
                         return $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $mixValue);
                     } else {
                         if ($arrFieldConfig['inputType'] == 'checkbox' && !$arrFieldConfig['eval']['multiple']) {
                             return strlen($mixValue) ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
                         } else {
                             if ($arrFieldConfig['inputType'] == 'textarea' && ($arrFieldConfig['eval']['allowHtml'] || $arrFieldConfig['eval']['preserveTags'])) {
                                 return nl2br_html5(specialchars($mixValue));
                             } else {
                                 if (is_array($arrFieldConfig['reference'])) {
                                     return isset($arrFieldConfig['reference'][$mixModelField]) ? is_array($arrFieldConfig['reference'][$mixModelField]) ? $arrFieldConfig['reference'][$mixModelField][0] : $arrFieldConfig['reference'][$mixModelField] : $mixModelField;
                                 } else {
                                     if (array_is_assoc($arrFieldConfig['options'])) {
                                         return $arrFieldConfig['options'][$mixModelField];
                                     } else {
                                         return $mixValue;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Retrieve the current values of the model and create the title widget information.
  *
  * @param InterfaceGeneralModel $objModel the current Model active in the DC.
  *
  * @param DC_General            $objDC    the Datacontainer calling us.
  */
 public function onModelUpdatedCallback($objModel, $objDC)
 {
     // do nothing if not in edit mode.
     if (!($this->Input->get('act') == 'create' || $this->Input->get('act') == 'edit')) {
         return;
     }
     $this->objectsFromUrl($objDC);
     $GLOBALS['TL_DCA']['tl_metamodel_dcasetting']['fields']['legendtitle'] = array_replace_recursive(parent::makeMultiColumnName($this->objMetaModel, $GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['name_langcode'], $GLOBALS['TL_LANG']['tl_metamodel_dcasetting']['name_value'], false, $objModel->getProperty('legendtitle')), $GLOBALS['TL_DCA']['tl_metamodel_dcasetting']['fields']['legendtitle']);
 }
 /**
  * Save a model to the database.
  *
  * In general, this method fetches the solely property "rows" from the model and updates the local table against
  * these contents.
  *
  * The parent id (id of the model) will get checked and reflected also for new items.
  *
  * When rows with duplicate ids are encountered (like from MCW for example), the dupes are inserted as new rows.
  *
  * @param InterfaceGeneralModel $objItem   The model to save.
  *
  * @param bool                  $recursive Ignored as not relevant in this data provider.
  *
  * @return InterfaceGeneralModel The passed Model.
  *
  * @throws Exception When the passed model does not contain a property named "rows", an Exception is thrown.
  */
 public function save(InterfaceGeneralModel $objItem, $recursive = false)
 {
     $arrData = $objItem->getProperty('rows');
     if (!($objItem->getID() && $arrData)) {
         throw new Exception('invalid input data in model.', 1);
     }
     $arrKeep = array();
     foreach ($arrData as $i => $arrRow) {
         // TODO: add an option to restrict this to some allowed fields?
         $arrSQL = $arrRow;
         // update all.
         $intId = intval($arrRow['id']);
         // Work around the fact that multicolumnwizard does not clear any hidden fields when copying a dataset.
         // therefore we do consider any dupe as new dataset and save it accordingly.
         if (in_array($intId, $arrKeep)) {
             $intId = 0;
             unset($arrSQL['id']);
         }
         if ($intId > 0) {
             $this->objDatabase->prepare(sprintf('UPDATE tl_metamodel_dca_combine %%s WHERE id=? AND %s=?', $this->strGroupCol))->set($arrSQL)->execute($intId, $objItem->getId());
             $arrKeep[] = $intId;
         } else {
             // force group col value:
             $arrSQL[$this->strGroupCol] = $objItem->getId();
             $arrKeep[] = $this->objDatabase->prepare('INSERT INTO tl_metamodel_dca_combine %s')->set($arrSQL)->execute()->insertId;
         }
     }
     // house keeping, kill the rest.
     $this->objDatabase->prepare(sprintf('DELETE FROM  tl_metamodel_dca_combine WHERE %s=? AND id NOT IN (%s)', $this->strGroupCol, implode(',', $arrKeep)))->execute($objItem->getId());
     return $objItem;
 }