Пример #1
0
 /**
  * Method to process the export
  * @return
  */
 function processExport()
 {
     $export = new JObject();
     if (empty($this->_model)) {
         $this->_errors = JText::_('COM_TIENDA_PLEASE_SET_A_MODEL_IN_THE_PLUGIN_METHOD_PROCESSEXPORT');
         return $this;
     }
     $arr = array();
     $header = array();
     $fill_header = true;
     $classname = 'TiendaGenericExporterModel' . $this->_model;
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         Tienda::load($classname, 'genericexporter.genericexporter.models.' . $this->_model, array('site' => 'site', 'type' => 'plugins', 'ext' => 'tienda'));
     } else {
         // Joomla! 1.5 code here
         Tienda::load($classname, 'genericexporter.models.' . $this->_model, array('site' => 'site', 'type' => 'plugins', 'ext' => 'tienda'));
     }
     $class = new $classname();
     $list = $class->loadDataList();
     if (empty($list)) {
         $this->_errors = JText::_('COM_TIENDA_NO_DATA_FOUND');
         return $this;
     }
     for ($i = 0, $c = count($list); $i < $c; $i++) {
         if ($fill_header) {
             $list_vars = get_object_vars($list[$i]);
             foreach ($list_vars as $key => $value) {
                 if ($fill_header) {
                     $header[] = $key;
                 }
             }
             $fill_header = false;
             // header is filled
         }
         $arr[] = $this->objectToString($list[$i], true);
     }
     $f_name = $this->_model . '_' . time() . '.csv';
     $this->_link = 'tmp/' . $f_name;
     $this->_name = $f_name;
     if (!($res = TiendaCSV::FromArrayToFile('tmp' . DS . $f_name, $arr, $header))) {
         $this->_errors = JText::_('COM_TIENDA_UNABLE_TO_WRITE_FILE');
     }
     return $this;
 }
Пример #2
0
 function fromFileToArray($file_path, $fields = array(), $num_fields = 0, $method = 1, $params = '')
 {
     if (empty($params)) {
         $params = new DSCParameter();
     }
     $throttled = $params->getValue('throttled_import', false);
     if ($throttled) {
         $content = $file_path;
     } else {
         // parse whole file
         $content = file_get_contents($file_path);
     }
     // read the file
     return TiendaCSV::toArray($content, $fields, $num_fields, $method, $params);
 }
Пример #3
0
 function migrate()
 {
     if ($this->import_throttled_import) {
         $result = '';
         $this->import_skip_first = $this->state->skip_first;
         $this->import_field_separator = $this->state->field_separator;
         $params = new DSCParameter();
         $params->setValue('skip_first', $this->import_skip_first);
         $params->setValue('num_records', $this->import_num_records);
         $params->setValue('num_fields', $this->import_fields_num);
         $params->setValue('clear_fields', $this->import_clear_fields);
         $params->setValue('chunk_size', $this->import_chunk_size);
         $params->setValue('preserve_header', $this->import_preserve_header);
         $params->setValue('offset', $this->import_offset);
         $params->setValue('begin_import', $this->import_begin_import);
         $params->setValue('throttled_import', true);
         $params->setValue('rec_deliminer', $this->import_rec_deliminer);
         $params->setValue('field_deliminer', $this->import_field_separator);
         while (true) {
             $data = TiendaCSV::fromFileToArray($this->source_import, $this->import_fields, $this->import_fields_num, $this->parse_method, $params);
             $c = count($data[0]);
             $this->set('data', $data[0]);
             $result .= $this->migrate_data();
             if ($c != $this->import_num_records) {
                 break;
             }
             $params->setValue('offset', $data[1]);
             $params->setValue('begin_import', false);
         }
         return $result;
     } else {
         return $this->migrate_data();
     }
 }
Пример #4
0
 function export()
 {
     Tienda::load('TiendaCSV', 'library.csv');
     $request = JRequest::get('request');
     //// load the plugins
     JPluginHelper::importPlugin('tienda');
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $params = json_decode(base64_decode($request['exportParams']));
     $model = JModel::getInstance($params->view, 'TiendaModel');
     $list = $model->getList();
     $arr = array();
     $header = array();
     // header -> it'll be filled out when
     $fill_header = true;
     // we need to fill header
     for ($i = 0, $c = count($list); $i < $c; $i++) {
         if ($fill_header) {
             $list_vars = get_object_vars($list[$i]);
             foreach ($list_vars as $key => $value) {
                 if ($fill_header) {
                     $header[] = $key;
                 }
             }
             $fill_header = false;
             // header is filled
         }
         $arr[] = $this->objectToString($list[$i], true);
     }
     $f_name = 'tmp/' . $params->view . '_' . time() . '.csv';
     $res = TiendaCSV::FromArrayToFile($f_name, $arr, $header);
     $this->render_page($f_name, $params->view);
 }