/**
  * Set up export of a batch of records.
  *
  * @return mixed
  */
 public function exportAction()
 {
     // Get the desired ID list:
     $ids = is_null($this->params()->fromPost('selectAll')) ? $this->params()->fromPost('ids') : $this->params()->fromPost('idsAll');
     if (!is_array($ids) || empty($ids)) {
         return $this->redirectToSource('error', 'bulk_noitems_advice');
     }
     // Process form submission if necessary:
     if (!is_null($this->params()->fromPost('submit'))) {
         $format = $this->params()->fromPost('format');
         $url = Export::getBulkUrl($this->getViewRenderer(), $format, $ids);
         if (Export::needsRedirect($format)) {
             return $this->redirect()->toUrl($url);
         }
         $msg = array('translate' => false, 'html' => true, 'msg' => $this->getViewRenderer()->render('cart/export-success.phtml', array('url' => $url)));
         return $this->redirectToSource('info', $msg);
     }
     // Load the records:
     $view = $this->createViewModel();
     $view->records = $this->getRecordLoader()->loadBatch($ids);
     // Assign the list of legal export options.  We'll filter them down based
     // on what the selected records actually support.
     $view->exportOptions = Export::getBulkOptions();
     foreach ($view->records as $driver) {
         // Filter out unsupported export formats:
         $newFormats = array();
         foreach ($view->exportOptions as $current) {
             if ($driver->supportsExport($current)) {
                 $newFormats[] = $current;
             }
         }
         $view->exportOptions = $newFormats;
     }
     // No legal export options?  Display a warning:
     if (empty($view->exportOptions)) {
         $this->flashMessenger()->setNamespace('error')->addMessage('bulk_export_not_supported');
     }
     return $view;
 }
 /**
  * Export the record
  *
  * @return mixed
  */
 public function exportAction()
 {
     $driver = $this->loadRecord();
     $view = $this->createViewModel();
     $format = $this->params()->fromQuery('style');
     // Display export menu if missing/invalid option
     if (empty($format) || !$driver->supportsExport($format)) {
         if (!empty($format)) {
             $this->flashMessenger()->setNamespace('error')->addMessage('export_invalid_format');
         }
         $view->setTemplate('record/export-menu');
         return $view;
     }
     // If this is an export format that redirects to an external site, perform
     // the redirect now (unless we're being called back from that service!):
     if (Export::needsRedirect($format) && !$this->params()->fromQuery('callback')) {
         // Build callback URL:
         $parts = explode('?', $this->getServerUrl(true));
         $callback = $parts[0] . '?callback=1&style=' . urlencode($format);
         return $this->redirect()->toUrl(Export::getRedirectUrl($format, $callback));
     }
     // Send appropriate HTTP headers for requested format:
     $response = $this->getResponse();
     $response->getHeaders()->addHeaders(Export::getHeaders($format));
     // Actually export the record
     $recordHelper = $this->getViewRenderer()->plugin('record');
     $response->setContent($recordHelper($driver)->getExport($format));
     return $response;
 }