/** * 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'); }