/**
  * Export action method
  *
  * @param  int $tid
  * @return void
  */
 public function export($tid)
 {
     $entities = new Model\Entity(['tid' => $tid]);
     $type = new Model\EntityType();
     $type->getById($tid);
     if (!isset($type->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/entities');
     }
     if ($this->services['acl']->isAllowed($this->sess->user->role, 'entity-type-' . $type->id, 'export')) {
         $rows = $entities->getAllForExport($tid);
         $data = new Data($rows);
         $data->serialize('csv', ['omit' => 'type_id']);
         $data->outputToHttp($type->name . '_' . date('Y-m-d') . '.csv');
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/entities/' . $tid);
     }
 }
 /**
  * Export action method
  *
  * @param  int $id
  * @return void
  */
 public function export($id)
 {
     $form = new Model\Form();
     $form->getById($id);
     if (!isset($form->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/forms');
     }
     $submission = new Model\FormSubmission();
     $submissions = $submission->getAll($id, null, null, $this->request->getQuery('sort'), $this->application->modules());
     $data = [];
     foreach ($submissions['rows'] as $row) {
         $d = ['id' => $row->id];
         foreach ($submissions['fields'] as $name => $type) {
             $r = (array) $row;
             unset($r['ip_address']);
             unset($r['timestamp']);
             unset($r['form_id']);
             if (isset($r[$name])) {
                 $d[$name] = is_array($r[$name]) ? implode(', ', $r[$name]) : $r[$name];
             } else {
                 $d[$name] = '';
             }
         }
         $d['ip_address'] = $row->ip_address;
         $d['timestamp'] = $row->timestamp;
         $data[] = $d;
     }
     $data = new Data($data);
     $data->serialize('csv');
     $data->outputToHttp($_SERVER['HTTP_HOST'] . '_' . str_replace(' ', '_', strtolower($form->name)) . '_' . date('Y-m-d') . '.csv');
 }