Example #1
0
 /**
  * Get the export fields
  *
  * @param object
  * @param array
  * @return ArrayReader
  *
  * @deprecated Use the DataCollector class instead.
  */
 protected function getExportData($objConfig, $arrIds = null)
 {
     $dataCollector = new DataCollector($objConfig->master);
     // Limit the fields
     if ($objConfig->export != 'all') {
         $arrLimitFields = array_keys($objConfig->fields);
         $dataCollector->setFieldIds(array_map('intval', $arrLimitFields));
     }
     if (null !== $arrIds) {
         $dataCollector->setLeadDataIds($arrIds);
     }
     $objReader = new ArrayReader($dataCollector->getExportData());
     // Add header fields
     if ($objConfig->headerFields) {
         $arrHeader = array();
         // Add base information columns
         if ($objConfig->export == 'all') {
             \System::loadLanguageFile('tl_lead_export');
             $arrHeader[] = $GLOBALS['TL_LANG']['tl_lead_export']['field_form'];
             $arrHeader[] = $GLOBALS['TL_LANG']['tl_lead_export']['field_created'];
             $arrHeader[] = $GLOBALS['TL_LANG']['tl_lead_export']['field_member'];
         } else {
             if ($objConfig->fields['_form']) {
                 $arrHeader[] = $objConfig->fields['_form']['name'];
             }
             if ($objConfig->fields['_created']) {
                 $arrHeader[] = $objConfig->fields['_created']['name'];
             }
             if ($objConfig->fields['_member']) {
                 $arrHeader[] = $objConfig->fields['_member']['name'];
             }
         }
         // Add export data header fields
         foreach ($dataCollector->getHeaderFields() as $fieldId => $label) {
             // Use a custom header field
             if ($objConfig->fields[$fieldId]['name'] != '') {
                 $arrHeader[] = $objConfig->fields[$fieldId]['name'];
             } else {
                 $arrHeader[] = $label;
             }
         }
         $objReader->setHeaderFields($arrHeader);
     }
     return $objReader;
 }
 /**
  * Prepares the default export configuration according to the configuration.
  *
  * @param \Database\Result $config
  * @param DataCollector    $dataCollector
  * @return array
  */
 protected function prepareDefaultExportConfig($config, DataCollector $dataCollector)
 {
     $columnConfig = array();
     // Config: all
     if ('all' === $config->export) {
         // Add base information columns (system columns)
         foreach (Leads::getSystemColumns() as $systemColumn) {
             $columnConfig[] = $systemColumn;
         }
         // Add export data column config.
         foreach ($dataCollector->getFieldsData() as $fieldId => $fieldConfig) {
             $fieldConfig = $this->handleContaoSpecificConfig($fieldConfig);
             $fieldConfig['value'] = 'all';
             $columnConfig[] = $fieldConfig;
         }
         return $columnConfig;
     }
     // We do this here so we don't have to do it in the loop
     $fieldsData = $dataCollector->getFieldsData();
     // Config: tokens
     if ('tokens' === $config->export) {
         $allFieldsConfig = array();
         foreach ($fieldsData as $fieldConfig) {
             $allFieldsConfig[] = $this->handleContaoSpecificConfig($fieldConfig);
         }
         foreach ($config->tokenFields as $column) {
             $column = array_merge($column, array('allFieldsConfig' => $allFieldsConfig));
             $columnConfig[] = $column;
         }
         return $columnConfig;
     }
     // Config: custom
     $systemColumns = Leads::getSystemColumns();
     foreach ($config->fields as $column) {
         // System column
         if (in_array($column['field'], array_keys($systemColumns))) {
             $columnConfig[] = $systemColumns[$column['field']];
         } else {
             // Skip non existing fields
             if (!isset($fieldsData[$column['field']])) {
                 continue;
             }
             // Merge form field config with custom export config
             $fieldConfig = array_merge($fieldsData[$column['field']], $column);
             $fieldConfig = $this->handleContaoSpecificConfig($fieldConfig);
             $columnConfig[] = $fieldConfig;
         }
     }
     return $columnConfig;
 }