예제 #1
0
 /**
  * Get the exporttypes that can be used and get the data for the checkboxes
  * 
  * @param array $params
  * @return array 
  */
 protected function actionLoad($params)
 {
     $response = array();
     $response['data'] = array();
     $settings = Settings::load();
     $data = $settings->getArray();
     // retreive checkbox settings
     $response['data']['includeHeaders'] = $data['export_include_headers'];
     $response['data']['humanHeaders'] = $data['export_human_headers'];
     $response['data']['includeHidden'] = $data['export_include_hidden'];
     $response['outputTypes'] = $this->_getExportTypes(GO::config()->root_path . 'go/base/export/');
     if (!empty($params['exportClassPath'])) {
         $response['outputTypes'] = array_merge($response['outputTypes'], $this->_getExportTypes(GO::config()->root_path . $params['exportClassPath']));
     }
     $response['success'] = true;
     echo $this->render('json', $response);
 }
예제 #2
0
 /**
  * 
  * @param \GO\Base\Data\AbstractStore $store
  * @param type $params
  */
 protected function renderExport(\GO\Base\Data\AbstractStore $store, $params)
 {
     //define('EXPORTING', true);
     //used by custom fields to format diffently
     if (\GO::modules()->customfields) {
         \GO\Customfields\Model\AbstractCustomFieldsRecord::$formatForExport = true;
     }
     $checkboxSettings = array('export_include_headers' => !empty($params['includeHeaders']), 'export_human_headers' => empty($params['humanHeaders']), 'export_include_hidden' => !empty($params['includeHidden']));
     $settings = \GO\Base\Export\Settings::load();
     $settings->saveFromArray($checkboxSettings);
     if (!empty($params['exportOrientation']) && $params['exportOrientation'] == "H") {
         $orientation = 'L';
     } else {
         $orientation = 'P';
     }
     // Set the orientation to Portrait
     if (!empty($params['columns'])) {
         $columnModel = $store->getColumnModel();
         $includeColumns = explode(',', $params['columns']);
         foreach ($includeColumns as $incColumn) {
             if (!$columnModel->getColumn($incColumn)) {
                 $columnModel->addColumn(new \GO\Base\Data\Column($incColumn, $incColumn));
             }
         }
         $columnModel->sort($includeColumns);
         foreach ($columnModel->getColumns() as $c) {
             if (!in_array($c->getDataIndex(), $includeColumns)) {
                 $columnModel->removeColumn($c->getDataIndex());
             }
         }
     }
     if (!empty($params['type'])) {
         //temporary fix for compatibility with AbsractModelController
         $params['type'] = str_replace('GO\\Base\\Export', 'GO\\Base\\Storeexport', $params['type']);
         $export = new $params['type']($store, $settings->export_include_headers, $settings->export_human_headers, $params['documentTitle'], $orientation);
     } else {
         $export = new \GO\Base\Storeexport\ExportCSV($store, $settings->export_include_headers, $settings->export_human_headers, $params['documentTitle'], $orientation);
     }
     // The default Export is the CSV outputter.
     if (isset($params['extraLines'])) {
         $export->addLines($params['extraLines']);
     }
     $export->output();
 }
예제 #3
0
 /**
  * This function can export the current data to a given format.
  * 
  * The $params array has a couple of keys wich you maybe want to set:
  * 
  * * title	: The title of the file that will be created. (Without extention)
  * * type		: Which class needs to be used to export. (Eg. \GO\Base\Export\ExportCSV)
  * * showHeader : Do you want to show the column headers in the file? (True or False)
  * 
  * @param Array $params 
  */
 protected function actionExport($params)
 {
     \GO::setMaxExecutionTime(0);
     $orientation = false;
     $showHeader = false;
     $humanHeaders = true;
     $includeHidden = false;
     if (!empty($params['includeHeaders'])) {
         $showHeader = true;
     }
     if (!empty($params['humanHeaders'])) {
         $humanHeaders = false;
     }
     if (!empty($params['includeHidden'])) {
         $includeHidden = true;
     }
     $checkboxSettings = array('export_include_headers' => $showHeader, 'export_human_headers' => !$humanHeaders, 'export_include_hidden' => $includeHidden);
     $settings = \GO\Base\Export\Settings::load();
     $settings->saveFromArray($checkboxSettings);
     //define('EXPORTING', true);
     //used by custom fields to format diffently
     if (\GO::modules()->customfields) {
         \GO\Customfields\Model\AbstractCustomFieldsRecord::$formatForExport = true;
     }
     if (!empty($params['exportOrientation']) && $params['exportOrientation'] == "H") {
         $orientation = 'L';
     } else {
         $orientation = 'P';
     }
     // Set the orientation to Portrait
     if (!empty($params['documentTitle'])) {
         $title = $params['documentTitle'];
     } else {
         $title = \GO::session()->values[$params['name']]['name'];
     }
     $findParams = \GO::session()->values[$params['name']]['findParams'];
     $findParams->limit(0);
     // Let the export handle all found records without a limit
     $findParams->getCriteria()->recreateTemporaryTables();
     $model = \GO::getModel(\GO::session()->values[$params['name']]['model']);
     $store = new \GO\Base\Data\Store($this->getStoreColumnModel());
     $store->getColumnModel()->setFormatRecordFunction(array($this, 'formatStoreRecord'));
     //$store->getColumnModel()->setModelFormatType('formatted'); //no html
     $response = array();
     $this->beforeStore($response, $params, $store);
     $this->prepareStore($store);
     $storeParams = $store->getDefaultParams($params)->mergeWith($this->getStoreParams($params));
     $this->beforeStoreStatement($response, $params, $store, $storeParams);
     $this->afterStore($response, $params, $store, $storeParams);
     $columnModel = $store->getColumnModel();
     $this->formatColumns($columnModel);
     if (!$includeHidden && !empty($params['columns'])) {
         $includeColumns = explode(',', $params['columns']);
         foreach ($includeColumns as $incColumn) {
             if (!$columnModel->getColumn($incColumn)) {
                 $columnModel->addColumn(new \GO\Base\Data\Column($incColumn, $incColumn));
             }
         }
         $columnModel->sort($includeColumns);
         foreach ($columnModel->getColumns() as $c) {
             if (!in_array($c->getDataIndex(), $includeColumns)) {
                 $columnModel->removeColumn($c->getDataIndex());
             }
         }
     } elseif ($includeHidden) {
         $columnOrder = array();
         $colNames = $model->getColumns();
         if (\GO::modules()->customfields) {
             $cfRecord = $model->getCustomfieldsRecord(false);
             if ($cfRecord) {
                 $cfColNames = $cfRecord->getColumns();
                 unset($cfColNames['model_id']);
                 $colNames = array_merge($colNames, $cfColNames);
             }
         }
         foreach ($colNames as $colName => $record) {
             $columnOrder[] = $colName;
         }
         $columnModel->sort($columnOrder);
     }
     $extraParams = empty($params['params']) ? array() : json_decode($params['params'], true);
     $this->beforeExport($store, $columnModel, $model, $findParams, $showHeader, $humanHeaders, $title, $orientation, $extraParams);
     if ($includeHidden) {
         $select = $storeParams->getParam('fields');
         $select = trim($select);
         if (!empty($select) && substr($select, 0, 1) != ',') {
             $select = ',' . $select;
         }
         if (\GO::modules()->customfields && $cfRecord) {
             $select = 't.*,cf.*' . $select;
         } else {
             $select = 't.*' . $select;
         }
         $findParams->select($select);
     }
     if (!empty($params['type'])) {
         $export = new $params['type']($store, $columnModel, $model, $findParams, $showHeader, $humanHeaders, $title, $orientation, $extraParams);
     } else {
         $export = new \GO\Base\Export\ExportCSV($store, $columnModel, $model, $findParams, $showHeader, $humanHeaders, $title, $orientation, $extraParams);
     }
     // The default Export is the CSV outputter.
     $export->output();
 }