/** * @Route("/", methods="GET") * @Request({"form_id": "int"}, csrf=true) */ public function indexAction($form_id) { if (!$form_id) { return []; } if (!($form = Form::find($form_id))) { throw new NotFoundException(__('Form not found.')); } return array_values($form->getFields()); }
/** * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"}) * @Request({"id": "int"}, csrf=true) */ public function deleteAction($id) { if ($form = Form::find($id)) { foreach (Field::where(['form_id = :id'], [':id' => $id])->get() as $field) { $field->delete(); } $form->delete(); } return ['message' => 'success']; }
/** * @Route("/edit", name="edit") * @Request({"id": "int"}) */ public function editAction($id = 0) { $formmaker = App::module('bixie/formmaker'); if (!($form = Form::find($id))) { $form = Form::create(); } if (!$form) { throw new NotFoundException(__('Form not found.')); } return ['$view' => ['title' => __('Form'), 'name' => 'bixie/formmaker/admin/edit.php'], '$data' => ['config' => $formmaker->config(), 'types' => $formmaker->getFieldTypes(), 'formitem' => $form]]; }
/** * @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]; }