Esempio n. 1
0
 /**
  * Get the export fields as array.
  *
  * @return array
  */
 public function getExportFields()
 {
     if (!\Input::get('id')) {
         return array();
     }
     $arrFields = array();
     $systemColumns = \Leads\Leads::getSystemColumns();
     foreach ($systemColumns as $k => $systemColumn) {
         $arrFields[$k] = $systemColumn['name'];
     }
     $objFields = \Database::getInstance()->prepare("SELECT * FROM tl_form_field WHERE leadStore!='' AND pid=(SELECT pid FROM tl_lead_export WHERE id=?)")->execute(Input::get('id'));
     while ($objFields->next()) {
         $strLabel = $objFields->name;
         // Use the field label
         if ($objFields->label != '') {
             $strLabel = $objFields->label . ' [' . $objFields->name . ']';
         }
         $arrFields[$objFields->id] = $strLabel;
     }
     return $arrFields;
 }
Esempio n. 2
0
 /**
  * Process data submitted through the form generator.
  *
  * @param array
  * @param array
  * @param array
  */
 public function processFormData(&$arrPost, &$arrForm, &$arrFiles)
 {
     if ($arrForm['leadEnabled']) {
         $time = time();
         $intLead = \Database::getInstance()->prepare("INSERT INTO tl_lead (tstamp,created,language,form_id,master_id,member_id,post_data) VALUES (?, UNIX_TIMESTAMP(), ?,?,?,?,?)")->execute($time, $GLOBALS['TL_LANGUAGE'], $arrForm['id'], $arrForm['leadMaster'] ? $arrForm['leadMaster'] : $arrForm['id'], FE_USER_LOGGED_IN === true ? \FrontendUser::getInstance()->id : 0, serialize($arrPost))->insertId;
         // Fetch master form fields
         if ($arrForm['leadMaster'] > 0) {
             $objFields = \Database::getInstance()->prepare("SELECT f2.*, f1.id AS master_id, f1.name AS postName FROM tl_form_field f1 LEFT JOIN tl_form_field f2 ON f1.leadStore=f2.id WHERE f1.pid=? AND f1.leadStore>0 AND f2.leadStore='1' ORDER BY f2.sorting")->execute($arrForm['id']);
         } else {
             $objFields = \Database::getInstance()->prepare("SELECT *, id AS master_id, name AS postName FROM tl_form_field WHERE pid=? AND leadStore='1' ORDER BY sorting")->execute($arrForm['id']);
         }
         while ($objFields->next()) {
             $arrSet = array();
             // Regular data
             if (isset($arrPost[$objFields->postName])) {
                 $varValue = Leads::prepareValue($arrPost[$objFields->postName], $objFields);
                 $varLabel = Leads::prepareLabel($varValue, $objFields);
                 $arrSet = array('pid' => $intLead, 'sorting' => $objFields->sorting, 'tstamp' => $time, 'master_id' => $objFields->master_id, 'field_id' => $objFields->id, 'name' => $objFields->name, 'value' => $varValue, 'label' => $varLabel);
             }
             // Files
             if (isset($arrFiles[$objFields->postName]) && $arrFiles[$objFields->postName]['uploaded']) {
                 $varValue = Leads::prepareValue($arrFiles[$objFields->postName], $objFields);
                 $varLabel = Leads::prepareLabel($varValue, $objFields);
                 $arrSet = array('pid' => $intLead, 'sorting' => $objFields->sorting, 'tstamp' => $time, 'master_id' => $objFields->master_id, 'field_id' => $objFields->id, 'name' => $objFields->name, 'value' => $varValue, 'label' => $varLabel);
             }
             if (!empty($arrSet)) {
                 // HOOK: add custom logic
                 if (isset($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore']) && is_array($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore'])) {
                     foreach ($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore'] as $callback) {
                         $this->import($callback[0]);
                         $this->{$callback[0]}->{$callback[1]}($arrPost, $arrForm, $arrFiles, $intLead, $objFields, $arrSet);
                     }
                 }
                 \Database::getInstance()->prepare("INSERT INTO tl_lead_data %s")->set($arrSet)->executeUncached();
             }
         }
         // HOOK: add custom logic
         if (isset($GLOBALS['TL_HOOKS']['storeLeadsData']) && is_array($GLOBALS['TL_HOOKS']['storeLeadsData'])) {
             foreach ($GLOBALS['TL_HOOKS']['storeLeadsData'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($arrPost, $arrForm, $arrFiles, $intLead, $objFields);
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Try to export and catch ExportFailedException.
  *
  * @param $intConfig
  * @param $arrIds
  */
 public function exportAndCatchExceptions($intConfig, $arrIds)
 {
     try {
         \Leads\Leads::export($intConfig, $arrIds);
     } catch (\Leads\Exporter\ExportFailedException $e) {
         \Message::addError($e->getMessage());
         \Controller::redirect(\System::getReferer());
     }
 }
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * Add an image to each record
  * @param array
  * @param string
  * @return string
  */
 public function listRows($row)
 {
     return $row['name'] . ': ' . \Leads\Leads::formatValue((object) $row);
 }