/** * 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; }
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); }