示例#1
0
 /**
  * CsvHelper constructor.
  * @param Submission[] $submissions
  * @param  Form        $form
  * @param  ArrObject   $options
  */
 public function __construct($submissions, $form, ArrObject $options)
 {
     $this->submissions = $submissions;
     $this->form = $form;
     $this->form->fields = $form->getFields();
     $this->options = $options;
 }
示例#2
0
 public function getFieldsubmissions()
 {
     if (!isset($this->fieldsubmissions)) {
         $fields = $this->form->getFields();
         foreach ($this->data as $submissionvalue) {
             if (isset($fields[$submissionvalue['field_id']])) {
                 $field = $fields[$submissionvalue['field_id']];
             } else {
                 //field might be deleted from form
                 $field = Field::create();
                 $field->setFieldType($submissionvalue['type']);
             }
             $this->fieldsubmissions[$field->slug] = (new Fieldsubmission($field, $submissionvalue))->toFormattedArray();
         }
     }
     return $this->fieldsubmissions;
 }
 /**
  * @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("/", 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("/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]];
 }
 /**
  * @param App   $app
  * @param int   $form_id
  * @param array $options
  * @param null  $view
  * @return mixed
  */
 public function renderForm(App $app, $form_id, $options = [], $view = null)
 {
     if (!$this->framework) {
         throw new App\Exception('Bixie Framework Extension required!');
     }
     $user = $app->user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$form_id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         throw new App\Exception('Form not found', 404);
     }
     foreach ($options as $key => $value) {
         $form->set($key, $value);
     }
     $form->prepareView($app, $this);
     return $app->view($view ?: 'bixie/formmaker/form.php');
 }
 /**
  * @Route("/{id}", name="form/front")
  */
 public function formAction($id = 0)
 {
     if (!($formmaker = App::module('bixie/formmaker'))) {
         return 'Formmaker extension is disabled!';
     }
     $user = App::user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         App::abort(404, __('Form not found!'));
     }
     if (!App::node()->hasAccess(App::user())) {
         App::abort(403, __('Insufficient User Rights.'));
     }
     $app = App::getInstance();
     $form->prepareView($app, $formmaker);
     return ['$view' => ['title' => __($form->title), 'name' => 'bixie/formmaker/form.php'], '$formmaker' => ['config' => $formmaker->publicConfig(), 'formitem' => $form, 'fields' => array_values($form->getFields())], 'node' => App::node()];
 }
 public function renderForm(App $app, $form_id, $options = [], $view = null)
 {
     $user = $app->user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$form_id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         throw new App\Exception('Form not found', 404);
     }
     foreach ($options as $key => $value) {
         $form->set($key, $value);
     }
     $form->prepareView($app, $this);
     $formmaker = $this;
     $app->on('view.data', function ($event, $data) use($form, $formmaker) {
         $data->add('$formmaker', ['config' => $this->publicConfig(), 'formitem' => $form, 'fields' => array_values($form->getFields())]);
     });
     return $app->view($view ?: 'bixie/formmaker/form.php');
 }
 /**
  * @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];
 }
 /**
  * @Route("/submissions", methods="GET")
  * @Request({"filter": "array", "page":"int"})
  */
 public function submissionsAction($filter = null, $page = 0)
 {
     return ['$view' => ['title' => __('Submissions'), 'name' => 'bixie/formmaker/admin/submissions.php'], '$data' => ['forms' => array_values(Form::query()->get()), 'statuses' => Submission::getStatuses(), 'config' => ['filter' => $filter, 'page' => $page]]];
 }
 /**
  * @Route("/submissions", methods="GET")
  * @Request({"filter": "array", "page":"int"})
  */
 public function submissionsAction($filter = null, $page = 0)
 {
     $formmaker = App::module('bixie/formmaker');
     return ['$view' => ['title' => __('Submissions'), 'name' => 'bixie/formmaker/admin/submissions.php'], '$data' => ['forms' => array_values(Form::query()->get()), 'statuses' => Submission::getStatuses(), 'config' => ['filter' => $filter, 'page' => $page]], 'frameworkValid' => $formmaker->checkFramework()];
 }