/** * @Route("/", methods="POST") * @Route("/{id}", methods="POST", requirements={"id"="\d+"}) * @Request({"submission": "array", "id": "int"}, csrf=true) */ public function saveAction($data, $id = 0) { if (!($submission = Submission::find($id))) { $submission = Submission::create(); unset($data['id']); $submission->form_id = $data['form_id']; $submission->created = new \DateTime(); $submission->ip = App::request()->getClientIp(); } unset($data['created']); if (!($form = Form::find($submission->form_id))) { App::abort(404, 'Form not found.'); } $submission->form = $form; $submission->save($data); $submission->email = $submission->getUserEmail(); if ($id == 0 && $submission->email) { try { (new MailHelper($submission))->sendMail(); $submission->save(); } catch (Exception $e) { App::abort(400, $e->getMessage()); } } return ['message' => 'Submission successfull', 'submission' => $submission]; }
/** * {@inheritdoc} */ public function main(App $app) { $app['field'] = function ($app) { if ($id = $app['request']->attributes->get('_field') and $field = Form::find($id)) { return $field; } return new Form(); }; }
/** * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"}) * @Request({"id": "int"}, csrf=true) */ public function deleteAction($id) { if ($field = Form::find($id)) { foreach (Profilevalue::where(['field_id = :id'], [':id' => $id])->get() as $profilevalue) { $profilevalue->delete(); } $field->delete(); } return ['message' => 'success']; }
/** * @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('formmaker'); if (!($form = Form::find($id))) { $form = Form::create(); } if (!$form) { throw new NotFoundException(__('Form not found.')); } return ['$view' => ['title' => __('Form'), 'name' => 'formmaker:views/admin/edit.php'], '$data' => ['config' => $formmaker->config(), 'types' => $formmaker->getTypes(), '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]; }