/**
  * Call the onmodel_update.
  * NOTE: the fact that this method has been called does not mean the values of the model have been changed
  * it merely just tells "we have loaded a model (from memory or database) and updated it's properties with
  * those from the POST data".
  *
  * @param InterfaceGeneralModel $objModel The model that has been updated.
  *
  * @return void
  */
 public function onModelUpdateCallback($objModel)
 {
     // Load DCA
     $arrDCA = $this->objDC->getDCA();
     // Call the oncreate_callback
     if (is_array($arrDCA['config']['onmodel_update'])) {
         foreach ($arrDCA['config']['onmodel_update'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objModel, $this->objDC);
         }
     }
 }
 /**
  * Call the child record callback
  *
  * @param InterfaceGeneralModel $objModel
  * @return string|null
  */
 public function childRecordCallback(InterfaceGeneralModel $objModel)
 {
     if (!$objModel instanceof GeneralModelMetaModel) {
         throw new Exception('ERROR: incompatible object passed to GeneralCallbackMetaModel::labelCallback()');
     }
     // Load DCA
     $arrDCA = $this->objDC->getDCA();
     $arrCallback = $arrDCA['list']['sorting']['child_record_callback'];
     // Check Callback
     if (is_array($arrCallback) && count($arrCallback)) {
         return parent::childRecordCallback($objModel);
     }
     return $this->drawItem($objModel);
 }
Пример #3
0
 /**
  * Get the breadcrumb navigation by callback
  *
  * @return string
  */
 protected function breadcrumb()
 {
     // Load DCA
     $arrDCA = $this->objDC->getDCA();
     $arrCallback = $arrDCA['list']['presentation']['breadcrumb_callback'];
     if (!is_array($arrCallback) || count($arrCallback) == 0) {
         return null;
     }
     // Get data from callback
     $strClass = $arrCallback[0];
     $strMethod = $arrCallback[1];
     $this->import($strClass);
     $arrReturn = $this->{$strClass}->{$strMethod}($this->objDC);
     // Check if we have a result with elements
     if (!is_array($arrReturn) || count($arrReturn) == 0) {
         return null;
     }
     // Include the breadcrumb css
     $GLOBALS['TL_CSS'][] = 'system/modules/generalDriver/html/css/generalBreadcrumb.css';
     // Build template
     $objTemplate = new BackendTemplate('dcbe_general_breadcrumb');
     $objTemplate->elements = $arrReturn;
     return $objTemplate->parse();
 }
 /**
  * Add sorting options to filter menu
  *
  * @param array $arrSortingFields
  * @param array $arrSession
  * @param string $strFilter
  * @return array
  */
 protected function filterMenuAddOptions($arrSortingFields, $arrSession, $strFilter)
 {
     $arrPanelView = array();
     // Add sorting options
     foreach ($arrSortingFields as $cnt => $field) {
         $arrProcedure = array();
         if ($this->getDC()->arrDCA['list']['sorting']['mode'] == 4) {
             $arrProcedure[] = array('operation' => '=', 'property' => 'pid', 'value' => CURRENT_ID);
         }
         if (!is_null($this->getDC()->getRootIds()) && is_array($this->getDC()->getRootIds())) {
             $arrProcedure[] = array('operation' => 'IN', 'property' => 'id', 'values' => array_map('intval', $this->getDC()->getRootIds()));
         }
         foreach ((array) $this->getFilter() as $arrSubFilter) {
             if ($arrSubFilter['property'] != $field) {
                 $arrProcedure[] = $arrSubFilter;
             }
         }
         $objCollection = $this->getDC()->getDataProvider()->getFilterOptions($this->getDC()->getDataProvider()->getEmptyConfig()->setFields(array($field))->setFilter($arrProcedure));
         // Begin select menu
         $arrPanelView[$field] = array('select' => array('name' => $field, 'id' => $field, 'class' => 'tl_select' . (isset($arrSession['filter'][$strFilter][$field]) ? ' active' : '')), 'option' => array(array('value' => 'tl_' . $field, 'content' => is_array($this->getDC()->arrDCA['fields'][$field]['label']) ? $this->getDC()->arrDCA['fields'][$field]['label'][0] : $this->getDC()->arrDCA['fields'][$field]['label']), array('value' => 'tl_' . $field, 'content' => '---')));
         if ($objCollection->length() > 0) {
             $options = array();
             foreach ($objCollection as $intIndex => $objModel) {
                 $options[$intIndex] = $objModel->getProperty($field);
             }
             // Sort by day
             if (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'], array(5, 6))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 6 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objModel->getProperty($field));
                     }
                     unset($options[$intIndex]);
                 }
             } elseif (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(7, 8))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 8 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = date('Y-m', $objModel->getProperty($field));
                         $intMonth = date('m', $objModel->getProperty($field)) - 1;
                         if (isset($GLOBALS['TL_LANG']['MONTHS'][$intMonth])) {
                             $options[$objModel->getProperty($field)] = $GLOBALS['TL_LANG']['MONTHS'][$intMonth] . ' ' . date('Y', $objModel->getProperty($field));
                         }
                     }
                     unset($options[$intIndex]);
                 }
             } elseif (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(9, 10))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 10 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = date('Y', $objModel->getProperty($field));
                     }
                     unset($options[$intIndex]);
                 }
             }
             // Manual filter
             if ($this->getDC()->arrDCA['fields'][$field]['eval']['multiple']) {
                 $moptions = array();
                 foreach ($objCollection as $objModel) {
                     if (isset($this->getDC()->arrDCA['fields'][$field]['eval']['csv'])) {
                         $doptions = trimsplit($this->getDC()->arrDCA['fields'][$field]['eval']['csv'], $objModel->getProperty($field));
                     } else {
                         $doptions = deserialize($objModel->getProperty($field));
                     }
                     if (is_array($doptions)) {
                         $moptions = array_merge($moptions, $doptions);
                     }
                 }
                 $options = $moptions;
             }
             $options = array_unique($options);
             $arrOptionsCallback = array();
             // Load options callback
             if (is_array($this->getDC()->arrDCA['fields'][$field]['options_callback']) && !$this->getDC()->arrDCA['fields'][$field]['reference']) {
                 $arrOptionsCallback = $this->getDC()->getCallbackClass()->optionsCallback($field);
                 // Sort options according to the keys of the callback array
                 if (!is_null($arrOptionsCallback)) {
                     $options = array_intersect(array_keys($arrOptionsCallback), $options);
                 }
             }
             $arrOptions = array();
             $arrSortOptions = array();
             $blnDate = in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(5, 6, 7, 8, 9, 10));
             // Options
             foreach ($options as $kk => $vv) {
                 $value = $blnDate ? $kk : $vv;
                 // Replace the ID with the foreign key
                 if (isset($this->getDC()->arrDCA['fields'][$field]['foreignKey'])) {
                     $key = explode('.', $this->getDC()->arrDCA['fields'][$field]['foreignKey'], 2);
                     $objModel = $this->getDC()->getDataProvider($key[0])->fetch($this->getDC()->getDataProvider($key[0])->getEmptyConfig()->setId($vv)->setFields(array($key[1] . ' AS value')));
                     if ($objModel->hasProperties()) {
                         $vv = $objModel->getProperty('value');
                     }
                 } elseif ($this->getDC()->arrDCA['fields'][$field]['eval']['isBoolean'] || $this->getDC()->arrDCA['fields'][$field]['inputType'] == 'checkbox' && !$this->getDC()->arrDCA['fields'][$field]['eval']['multiple']) {
                     $vv = $vv != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
                 } elseif (is_array($arrOptionsCallback) && !empty($arrOptionsCallback)) {
                     $vv = $arrOptionsCallback[$vv];
                 } elseif ($field == 'pid') {
                     // Load language file and data container array of the parent table
                     $this->loadLanguageFile($this->getDC()->getParentTable());
                     $this->loadDataContainer($this->getDC()->getParentTable());
                     $objParentDC = new DC_General($this->getDC()->getParentTable());
                     $arrParentDca = $objParentDC->getDCA();
                     $showFields = $arrParentDca['list']['label']['fields'];
                     if (!$showFields[0]) {
                         $showFields[0] = 'id';
                     }
                     $objModel = $this->getDC()->getDataProvider('parent')->fetch($this->getDC()->getDataProvider('parent')->getEmptyConfig()->setId($vv)->setFields(array($showFields[0])));
                     if ($objModel->hasProperties()) {
                         $vv = $objModel->getProperty($showFields[0]);
                     }
                 }
                 $strOptionsLabel = '';
                 // Use reference array
                 if (isset($this->getDC()->arrDCA['fields'][$field]['reference'])) {
                     $strOptionsLabel = is_array($this->getDC()->arrDCA['fields'][$field]['reference'][$vv]) ? $this->getDC()->arrDCA['fields'][$field]['reference'][$vv][0] : $this->getDC()->arrDCA['fields'][$field]['reference'][$vv];
                 } elseif ($this->getDC()->arrDCA['fields'][$field]['eval']['isAssociative'] || array_is_assoc($this->getDC()->arrDCA['fields'][$field]['options'])) {
                     $strOptionsLabel = $this->getDC()->arrDCA['fields'][$field]['options'][$vv];
                 }
                 // No empty options allowed
                 if (!strlen($strOptionsLabel)) {
                     // FIXME: this is a rather evil hack but I ended up here with an array containing files.
                     // This usually reensembles an invalid setup but we should not raise warnings then but cope
                     // correctly with it. For the moment, we simply ignore such data we can not handle.
                     if (!is_string($vv)) {
                         continue;
                     }
                     $strOptionsLabel = strlen($vv) ? $vv : '-';
                 }
                 $arrOptions[utf8_romanize($strOptionsLabel)] = array('value' => specialchars($value), 'select' => isset($arrSession['filter'][$strFilter][$field]) && $value == $arrSession['filter'][$strFilter][$field] ? ' selected="selected"' : '', 'content' => $strOptionsLabel);
                 $arrSortOptions[] = utf8_romanize($strOptionsLabel);
             }
             // Sort by option values
             if (!$blnDate) {
                 natcasesort($arrSortOptions);
                 if (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(2, 4, 12))) {
                     $arrSortOptions = array_reverse($arrSortOptions, true);
                 }
             }
             foreach ($arrSortOptions as $value) {
                 $arrPanelView[$field]['option'][] = $arrOptions[$value];
             }
         }
         // Force a line-break after six elements
         if (($cnt + 1) % 6 == 0) {
             $arrPanelView[] = 'new';
         }
     }
     return $arrPanelView;
 }