/** * @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']; }
/** * @return array|Field[] */ public function getFields() { if (!isset($this->fields)) { $fields = Field::where(['form_id' => $this->id])->orderBy('priority', 'ASC')->get(); } else { $fields = $this->fields; } //make sure type exists $formmaker = App::module('bixie/formmaker'); $this->fields = []; foreach ($fields as $field) { if ($formmaker->getFieldType($field->type)) { $this->fields[$field->id] = $field; } } return $this->fields; }
/** * @Route("/csv", methods="GET") * @Request({"options": "array"}, csrf=true) */ public function indexCsvAction($options = []) { $count = 0; $forms = []; $fields = []; $form = ['id' => 0]; $options = new ArrObject($options); if ($form_id = $options->get('form_id', 0)) { //get forminfo $form = Form::find($form_id); $fields = Field::where(['form_id = ?'], [$form_id])->get(); $options->set('field_ids', array_keys($fields)); //count exported submissions $query = Submission::query(); $query->where(['form_id = ?'], [$form_id])->whereIn('status', $options->get('status', [])); //input cleaned? $count = $query->count(); } else { $forms = array_values(Form::findAll()); } //force int $options->set('status', array_map(function ($id) { return (int) $id; }, $options->get('status', []))); $options->set('form_id', (int) $form_id); return ['options' => $options->toArray(), 'forms' => $forms, 'formitem' => $form, 'fields' => array_values($fields), 'count' => $count]; }