Beispiel #1
0
 /**
  * @return string
  */
 protected function getHeaders()
 {
     $headers = [];
     foreach ($this->options->get('datafields', []) as $datafield) {
         $headers[] = __($datafield);
     }
     //todo error checking
     foreach ($this->options->get('field_ids', []) as $field_id) {
         $headers[] = isset($this->form->fields[$field_id]) ? __($this->form->fields[$field_id]->label) : "Field {$field_id}";
     }
     return $this->csvString($headers);
 }
 /**
  * @Route("/csv", methods="POST")
  * @Request({"options": "array"}, csrf=true)
  */
 public function exportCsvAction($options = [])
 {
     $csvString = '';
     $options = new ArrObject($options);
     if ($form_id = $options->get('form_id', 0)) {
         //get forminfo
         $form = Form::find($form_id);
         //get submissions
         $query = Submission::query();
         $query->where(['form_id = ?'], [$form_id])->whereIn('status', $options->get('status', []));
         //input cleaned?
         $submissions = $query->orderBy('created', 'desc')->get();
         $csvString = (new CsvHelper($submissions, $form, $options))->toCsv();
         if ($options->get('mark_archived', false)) {
             Submission::query()->whereIn('id', array_keys($submissions))->update(['status' => Submission::STATUS_ARCHIVED]);
         }
     } else {
         App::abort(404, 'Not a single form was given.');
     }
     return ['csv' => $csvString];
 }