protected function exportBatch()
 {
     $filter = $this->getFilter($this->data);
     if ($this->data) {
         $batch = $this->loader->getTaskRunnerBatch('export_surveys');
         $models = $this->getExportModels($this->data['gto_id_survey'], $filter);
         $batch->setVariable('model', $models);
         if (!$batch->count()) {
             $batch->minimalStepDurationMs = 2000;
             $batch->finishUrl = $this->view->url(array('step' => 'download'));
             $batch->setSessionVariable('files', array());
             foreach ($this->data['gto_id_survey'] as $surveyId) {
                 $batch->addTask('Export_ExportCommand', $this->data['type'], 'addExport', $this->data, $surveyId);
             }
             $batch->addTask('addTask', 'Export_ExportCommand', $this->data['type'], 'finalizeFiles');
             $batch->autoStart = true;
         }
         if ($batch->run($this->request)) {
             exit;
         } else {
             $controller = $this;
             if ($batch->isFinished()) {
             } else {
                 if ($batch->count()) {
                     $controller->html->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%'));
                 } else {
                     $controller->html->pInfo($controller->_('Nothing to do.'));
                 }
                 $controller->html->pInfo()->a(\MUtil_Html_UrlArrayAttribute::rerouteUrl($this->getRequest(), array('action' => 'index', 'step' => false)), array('class' => 'actionlink'), $this->_('Back'));
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Reroutes the page (i.e. header('Location: ');)
  *
  * @param array $urlOptions Url parts
  * @param boolean $reset Use default module, action and controller instead of current when not specified in $urlOptions
  * @param string $routeName
  * @param boolean $encode
  */
 protected function _reroute(array $urlOptions = array(), $reset = false, $routeName = null, $encode = true)
 {
     if ($reset) {
         // \MUtil_Echo::r($urlOptions, 'before');
         $urlOptions = \MUtil_Html_UrlArrayAttribute::rerouteUrl($this->getRequest(), $urlOptions);
         // \MUtil_Echo::r($urlOptions, 'after');
     }
     $this->_helper->redirector->gotoRoute($urlOptions, $routeName, $reset, $encode);
 }
Ejemplo n.º 3
0
 public function __construct($args_array = null)
 {
     $args = func_get_args();
     parent::__construct('href', $args);
 }
 /**
  * Export model data
  */
 public function exportAction()
 {
     $step = $this->request->getParam('step');
     $post = $this->request->getPost();
     $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters;
     $model = $this->getExportModel();
     if (isset($this->autofilterParameters['sortParamAsc'])) {
         $model->setSortParamAsc($this->autofilterParameters['sortParamAsc']);
     }
     if (isset($this->autofilterParameters['sortParamDesc'])) {
         $model->setSortParamDesc($this->autofilterParameters['sortParamDesc']);
     }
     $model->applyParameters($this->getSearchFilter(false), true);
     // Add any defaults.
     if (isset($this->autofilterParameters['extraFilter'])) {
         $model->addFilter($this->autofilterParameters['extraFilter']);
     }
     if (isset($this->autofilterParameters['extraSort'])) {
         $model->addSort($this->autofilterParameters['extraSort']);
     }
     if (!$step || $post && $step == 'form') {
         $this->addSnippet($this->exportFormSnippets);
         $batch = $this->loader->getTaskRunnerBatch('export_data');
         $batch->reset();
     } elseif ($step == 'batch') {
         $batch = $this->loader->getTaskRunnerBatch('export_data');
         $batch->setVariable('model', $model);
         if (!$batch->count()) {
             $batch->minimalStepDurationMs = 2000;
             $batch->finishUrl = $this->view->url(array('step' => 'download'));
             $batch->setSessionVariable('files', array());
             $batch->addTask('Export_ExportCommand', $post['type'], 'addExport', $post);
             $batch->addTask('addTask', 'Export_ExportCommand', $post['type'], 'finalizeFiles');
             $batch->autoStart = true;
         }
         if ($batch->run($this->request)) {
             exit;
         } else {
             $controller = $this;
             if ($batch->isFinished()) {
                 /*\MUtil_Echo::track('finished');
                   $file = $batch->getSessionVariable('file');
                   if ((!empty($file)) && isset($file['file']) && file_exists($file['file'])) {
                       // Forward to download action
                       $this->_session->exportFile = $file;
                   }*/
             } else {
                 if ($batch->count()) {
                     $controller->html->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%'));
                 } else {
                     $controller->html->pInfo($controller->_('Nothing to do.'));
                 }
                 $controller->html->pInfo()->a(\MUtil_Html_UrlArrayAttribute::rerouteUrl($this->getRequest(), array('action' => 'index', 'step' => false)), array('class' => 'actionlink'), $this->_('Back'));
             }
         }
     } elseif ($step == 'download') {
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $batch = $this->loader->getTaskRunnerBatch('export_data');
         $file = $batch->getSessionVariable('file');
         print_r($file);
         foreach ($file['headers'] as $header) {
             header($header);
         }
         while (ob_get_level()) {
             ob_end_clean();
         }
         readfile($file['file']);
         // Now clean up the file
         unlink($file['file']);
         exit;
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns relative url string using the current module, controller and action when
  * none where specified.
  *
  * This is url is encoded for url usage, but not for use as attribute values,
  * i.e. this helper function is used for generating url's for internal use.
  *
  * @param array $options Array of parameter values
  * @param \Zend_Controller_Request_Abstract $request
  * @param \Zend_Controller_Router_Route $router
  * @return string
  */
 public static function urlString(array $options, \Zend_Controller_Request_Abstract $request = null, \Zend_Controller_Router_Route $router = null)
 {
     return \MUtil_Html_UrlArrayAttribute::toUrlString($options, $request, $router);
 }
 public function handleExportAction()
 {
     $this->initHtml();
     $batch = $this->loader->getTaskRunnerBatch('export_data');
     $batch->minimalStepDurationMs = 2000;
     if (!$batch->count()) {
         $data = $this->_session->exportParams;
         $exportModelName = $this->exportModelSource;
         $exportModel = $this->loader->getExportModelSource($exportModelName);
         $exportFilters = $exportModel->getFilters($data);
         $language = $this->locale->getLanguage();
         $batch->setSessionVariable('files', array());
         foreach ($exportFilters as $filter) {
             $batch->addTask('Export_ExportCommand', $data['type'], 'addExport', $exportModelName, $filter, $data);
         }
         $batch->addTask('addTask', 'Export_ExportCommand', $data['type'], 'finalizeFiles', $exportModelName);
         $batch->autoStart = true;
     }
     $title = $this->_('Export');
     if ($batch->run($this->getRequest())) {
         exit;
     } else {
         $controller = $this;
         $controller->html->h3($title);
         if ($batch->isFinished()) {
             $file = $batch->getSessionVariable('file');
             if (!empty($file) && isset($file['file']) && file_exists($file['file'])) {
                 // Forward to download action
                 $this->_session->exportFile = $file;
                 $this->_reroute(array('action' => 'download'));
             }
         } else {
             if ($batch->count()) {
                 $controller->html->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%'));
             } else {
                 $controller->html->pInfo($controller->_('Nothing to do.'));
             }
             $controller->html->pInfo()->a(\MUtil_Html_UrlArrayAttribute::rerouteUrl($this->getRequest(), array('action' => 'index')), array('class' => 'actionlink'), $this->_('Back'));
         }
     }
 }