/** * Build the command to use for the cron command to do an import/export * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return string the parameters for the cron line * @since 3.0 */ public function getCronLine() { $jinput = JFactory::getApplication()->input; $db = JFactory::getDbo(); $settings = $jinput->get('com_csvi.data', array(), 'array'); $cronline = ''; $notemplate = false; $details = new StdClass(); // Get the template used $template_id = $jinput->get('template_id', 0, 'int'); if ($template_id) { $cronline .= ' template_id="' . $template_id . '"'; // Load the template settings to compare against selection $query = $db->getQuery(true); $query->select('settings'); $query->from('#__csvi_template_settings'); $query->where('id = ' . $template_id); $db->setQuery($query); $template = new CsviTemplate(json_decode($db->loadResult(), true)); $details->type = $template->get('action', 'options'); } else { $notemplate = true; // Initialise the details $details->type = $settings['options']['action']; } // Check if this is an import or export cron if ($details->type == 'export') { foreach ($settings as $group => $values) { switch ($group) { case 'options': break; case 'general': if ($notemplate) { $general = $settings['general']; } else { $general = CsviHelper::recurseArrayDiff($settings['general'], $template->get('general')); } foreach ($general as $name => $setting) { switch ($name) { case 'exportto': if (!empty($setting)) { if ($setting == 'todownload') { $setting = 'tofile'; } $cronline .= ' jform:general:' . $name . '="' . $setting . '" '; } break; case 'localpath': if (!empty($setting)) { if ($template->get('exportto', 'general') == 'todownload' || $template->get('exportto', 'general') == 'tofile') { $cronline .= ' jform:general:' . $name . '="' . $setting . '" '; } } break; default: if (!empty($setting)) { $cronline .= ' jform:general:' . $name . '="' . $setting . '" '; } break; } } break; case 'export_fields': if ($notemplate) { if (array_key_exists('export_fields', $settings)) { $fields = $settings['export_fields']; } else { $fields = array(); } } else { $fields = $template->get('export_fields', '', array()); } if (!empty($fields)) { $fields['_selected_name'] = CsviHelper::recurseArrayDiff($settings['export_fields']['_selected_name'], $fields['_selected_name']); if (!empty($fields['_selected_name'])) { $cronline .= ' jform:export_fields:_selected_name = "' . implode('|', $settings['export_fields']['_selected_name']) . '|"'; $cronline .= ' jform:export_fields:_column_header = "' . implode('|', $settings['export_fields']['_column_header']) . '|"'; $cronline .= ' jform:export_fields:_default_value = "' . implode('|', $settings['export_fields']['_default_value']) . '|"'; $cronline .= ' jform:export_fields:_process_field = "' . implode('|', $settings['export_fields']['_process_field']) . '|"'; } } break; default: if ($notemplate) { $values = $settings[$group]; } else { $values = CsviHelper::recurseArrayDiff($settings[$group], $template->get($group)); } $cronline .= $this->_getCronSetting($values, $group); break; } } } else { if ($details->type == 'import') { foreach ($settings as $group => $values) { switch ($group) { case 'options': break; case 'import_fields': if ($notemplate) { if (array_key_exists('import_fields', $settings)) { $fields = $settings['import_fields']; } else { $fields = array(); } } else { // Create a default value $default = array(); $default['_selected_name'][] = ''; $fields = $template->get('import_fields', '', $default); $fields['_selected_name'] = CsviHelper::recurseArrayDiff($settings['import_fields']['_selected_name'], $fields['_selected_name']); } if (!empty($fields)) { if (!empty($fields['_selected_name'])) { $cronline .= ' jform:import_fields:_selected_name = "' . implode('|', $settings['import_fields']['_selected_name']) . '|"'; $cronline .= ' jform:import_fields:_default_value = "' . implode('|', $settings['import_fields']['_default_value']) . '|"'; $cronline .= ' jform:import_fields:_process_field = "' . implode('|', $settings['import_fields']['_process_field']) . '|"'; } } break; default: if ($notemplate) { $values = $settings[$group]; if (!is_array($values)) { $values = array(); $values[$group] = $settings[$group]; } } else { $values = CsviHelper::recurseArrayDiff($settings[$group], $template->get($group)); } $cronline .= $this->_getCronSetting($values, $group); break; } } } } return $cronline; }