public function actionIndex() { $model = new ExportObject(); if (isset($_POST['ExportObject'])) { $model->attributes = $_POST['ExportObject']; if ($model->validate()) { echo $model->getDump(); Yii::app()->end(); } } $objects = DaObject::model()->findAll('table_name IS NOT NULL'); $this->render('index', array('model' => $model, 'objects' => $objects)); }
/** * Manage table list for csv export. * * @return void */ public function toCsvAction() { // variables $pageID = $this->_getParam('pageID'); $returnAction = $this->_getParam('return'); $returnUrl = '/'; $blockID = $this->_getParam('blockID'); $baseDir = $this->view->baseUrl(); if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) { $returnUrl .= $this->_moduleTitle . "/" . $this->_name . "/" . $this->_firstAction . "/"; if ($pageID > 0) { $returnUrl .= "page/" . $pageID . "/"; } // get the list of tables that may be exported $tablesList = $this->_tablesList; // generate the form to select tables to export $form = new FormExportCatalog(array('baseDir' => $baseDir, 'cancelUrl' => "{$baseDir}{$returnUrl}", 'selectedTables' => $tablesList)); $this->view->form = $form; // action if (!$this->_request->isPost()) { $form->populate($tablesList); } else { $formData = $this->_request->getPost(); $selectedTables = $formData['tablesList']; if ($selectedTables[0] == 'checkAll') { unset($selectedTables[0]); } if ($form->isValid($formData)) { if ($this->_ftpTransfer && $this->_exportFilesFolder) { $config = Zend_Registry::get('config'); $properties = $config->toArray(); $ftp = new Cible_Ftp($properties['ftpTransfer']); } // Process export foreach ($selectedTables as $name) { // if (isset($this->relatedId[$name])) // { $this->type = 'CSV'; $options['dataClass'] = $this->_formatName($name); $lines = new ExportObject($options); $dataColumns = $lines->getDataColumnsForExport(); $this->tables = array($name => $dataColumns); $this->fields = $dataColumns; $this->filters = array(); $this->select = $lines->getAll(null, false); if (is_array($this->relatedId) && count($this->relatedId) > 0) { $object = new $options['dataClass'](); //Get the constraint to find related data/table $field = $object->getConstraint(); //If no constraint it's the first table. We take the key. if (empty($field)) { $field = $object->getDataId(); } // Add where clause to the query if (isset($this->relatedId[$name]) && is_array($this->relatedId[$name]) && count($this->relatedId[$name]) > 0) { $this->select->where($field . " = ?", current($this->relatedId[$name])); for ($i = 1; $i < count($this->relatedId[$name]); $i++) { $this->select->orWhere($field . " = ?", $this->relatedId[$name][$i]); } } elseif (isset($this->relatedId[$name])) { $this->select->where($field . " = ?", $this->relatedId[$name]); } $name .= "_" . $this->_getParam('ID'); } $this->filename = $name . ".csv"; parent::toCsvAction(); if ($this->_ftpTransfer && $this->_exportFilesFolder) { $ftp->setFileName($this->filename); $ftp->setLocalFile($this->_exportFilesFolder . $this->filename); $ftp->transfer(); } // } } // return to list $this->_redirect($returnUrl); } } } }