/**
  * Get the available fields
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		protected
  * @param
  * @return 		array	an array of options
  * @since 		4.3
  */
 protected function getOptions()
 {
     // Get the template ID
     $jinput = JFactory::getApplication()->input;
     $session = JFactory::getSession();
     $sess_template_id = $session->get('com_csvi.select_template', 0);
     if ($sess_template_id !== 0) {
         $sess_template_id = unserialize($sess_template_id);
     }
     $template_id = $jinput->get('template_id', $sess_template_id, 'int');
     // Load the selected template
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/template.php';
     $template = new CsviTemplate();
     $template->load($template_id);
     // Load the available fields
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/availablefields.php';
     $availablefields_model = new CsviModelAvailablefields();
     $fields = $availablefields_model->getAvailableFields($template->get('operation', 'options'), $template->get('component', 'options'), 'array');
     if (!is_array($fields)) {
         $avfields = array();
     } else {
         $avfields = array();
         foreach ($fields as $field) {
             $avfields[$field] = $field;
         }
     }
     return array_merge(parent::getOptions(), $avfields);
 }
Beispiel #2
0
 /**
  * Prepare for export
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function getPrepareExport()
 {
     // Load the basics
     $jinput = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $exportfile_model = $this->_getModel('exportfile');
     // Load the backend language file
     $lang = JFactory::getLanguage();
     $lang->load('com_csvi', JPATH_ADMINISTRATOR);
     // Load the template
     $template = new CsviTemplate();
     $template->load($jinput->get('template_id', 0, 'int'));
     $template->set('exportto', 'general', 'tofront');
     $jinput->set('template', $template);
     // Set the export type
     $jinput->set('export_type', $template->get('operation', 'options'));
     // Initiate the log
     $csvilog = new CsviLog();
     // Create a new Import ID in the logger
     $csvilog->setId();
     // Set to collect debug info
     $csvilog->setDebug($template->get('collect_debug_info', 'general'));
     // Set some log info
     $csvilog->SetAction('export');
     $csvilog->SetActionType($template->get('export_type'), $template->getName());
     // Add the logger to the registry
     $jinput->set('csvilog', $csvilog);
     // Load the fields to export
     $exportfields = $exportfile_model->getExportFields();
     if (!empty($exportfields)) {
         $jinput->set('export.fields', $exportfields);
         // Allow big SQL selects
         $db->setQuery("SET OPTION SQL_BIG_SELECTS=1");
         $db->query();
         // Get the filename for the export file
         $jinput->set('export.filename', $exportfile_model->exportFilename());
         // See if we need to get an XML/HTML class
         $export_format = $template->get('export_file', 'general');
         if ($export_format == 'xml' || $export_format == 'html') {
             $exportclass = $exportfile_model->getExportClass();
             if ($exportclass) {
                 $jinput->set('export.class', $exportclass);
             } else {
                 $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_EXPORT_CLASS'));
                 $jinput->set('logcount', 0);
                 return false;
             }
         }
         // Return all is good
         return true;
     } else {
         $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_EXPORT_FIELDS'));
         $jinput->set('logcount', 0);
         return false;
     }
 }
Beispiel #3
0
 /**
  * Import the files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		string	JSON encoded text
  * @since 		3.0
  */
 public function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     if ($jinput->get('importsession', true, 'bool')) {
         // Process the data
         $this->get('ProcessData');
         // Empty the message stack
         $session = JFactory::getSession();
         $session->set('application.queue', null);
         // Collect the results
         $result = array();
         // Set the view mode
         if ($jinput->get('csvipreview', false, 'bool')) {
             $result['view'] = 'preview';
             $result['headers'] = $jinput->get('headers_preview', null, null);
             $result['output'] = $jinput->get('data_preview', null, null);
             if (empty($results['headers']) && empty($result['output'])) {
                 $result['process'] = false;
                 $csvilog = $jinput->get('csvilog', null, null);
                 $result['url'] = JURI::root() . 'administrator/index.php?option=com_csvi&task=process.finished&run_id=' . $csvilog->getId();
                 // Clean the session, nothing to import
                 $this->get('CleanSession');
             } else {
                 $result['process'] = true;
             }
         } else {
             $result['view'] = '';
             // Get the number of records processed
             $result['records'] = $jinput->get('recordsprocessed', 0, 'int');
             if ($result['records'] == 0 || $jinput->get('finished', false)) {
                 $result['process'] = false;
                 $result['url'] = JURI::root() . 'administrator/index.php?option=com_csvi&task=process.finished&run_id=' . $jinput->get('run_id', 0, 'int');
             } else {
                 // Check if we are finished
                 $result['process'] = true;
             }
         }
     } else {
         // Collect the results
         $result = array();
         $result['process'] = false;
         $result['url'] = JURI::root() . 'administrator/index.php?option=com_csvi&task=process.finished&run_id=' . $jinput->get('run_id', 0, 'int');
         // Clean the session, nothing to import
         $this->get('CleanSession');
     }
     // If the import is finished, call the plugins
     if (!$result['process']) {
         // Load the template
         $session = JFactory::getSession();
         $template = new CsviTemplate();
         $template->load(unserialize($session->get('com_csvi.select_template')));
         $options = array();
         $options[] = $template->get('options');
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('csvi');
         $dispatcher->trigger('onImportComplete', $options);
     } else {
         // Import is not finished, lets sleep
         if ($jinput->get('currentline', 0, 'int') > 0 && !$jinput->get('finished', false)) {
             $settings = new CsviSettings();
             sleep($settings->get('import.import_wait', 0));
         }
     }
     // Output the results
     echo json_encode($result);
 }
Beispiel #4
0
 /**
  * Export for front-end
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function export()
 {
     // Create the view
     $view = $this->getView('export', 'raw');
     // Add the export model
     $view->setModel($this->getModel('export', 'CsviModel'), true);
     // Add the export model path
     $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . '/models');
     // General export functions
     $view->setModel($this->getModel('exportfile', 'CsviModel'));
     // Log functions
     $view->setModel($this->getModel('log', 'CsviModel'));
     // Settings functions
     $view->setModel($this->getModel('settings', 'CsviModel'));
     // General category functions
     $view->setModel($this->getModel('category', 'CsviModel'));
     // Available fields
     $view->setModel($this->getModel('availablefields', 'CsviModel'));
     // Load the model
     $model = $this->getModel('exportfile');
     // Add extra helper paths
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers');
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers/xml');
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers/html');
     // Load the helper classes
     $view->loadHelper('csvidb');
     $view->loadHelper('template');
     $view->loadHelper('csvisef');
     // Load the template details
     $jinput = JFactory::getApplication()->input;
     $template = new CsviTemplate();
     $template->load($jinput->get('template_id', 0, 'int'));
     $jinput->set('jform', $template->getSettings());
     // Set the output destination
     $template->set('exportto', 'general', $jinput->get('exportto', 'tofront', 'cmd'));
     $jinput->set('template', $template);
     if ($template->get('action', 'options', 'export') == 'export') {
         // Prepare for export
         if ($model->getPrepareExport()) {
             // Set the export override
             $app = JFactory::getApplication();
             $jinput = JFactory::getApplication()->input;
             $overridefile = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_csvi/models/export/' . $template->get('operation', 'options') . '.php';
             // Add the export model path if override exists
             if (file_exists($overridefile)) {
                 $this->addModelPath(JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_csvi/models/' . $template->get('component', 'options') . '/export');
             } else {
                 $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/' . $template->get('component', 'options') . '/export');
             }
             // Load export specifc helper
             $view->loadHelper($template->get('component', 'options'));
             $view->loadHelper($template->get('component', 'options') . '_config');
             // Display it all
             $view->display();
         } else {
             // Clean up first
             $model->getCleanSession();
             // Add appropriate message
         }
     } else {
         // Add appropriate message
     }
 }