/** * Formr action * @param Array $inputs */ public static function formAction($dataInput) { //return var_dump($dataInput); if (!isset($dataInput['formParam']) || !isset($dataInput['formParam']['formId'])) { App::abbort(404); } $form = Formr::findOrFail($dataInput['formParam']['formId']); // recuperation de l'ordre pour le nouvel input $lastOrder = self::mapping($form); // Suppression du dernier pipe et surchage de "data['rules']" $dataInput['rules'] = isset($dataInput['rules']) ? self::generateRules($dataInput['rules']) : ""; $view = Viewr::where('name', $dataInput['type'])->firstOrFail(); $dataInput['view'] = $view->id; $dataInput = array_merge($dataInput, self::generateI18n($dataInput)); $inputType = InputType::add($dataInput); $input = self::add($inputType->id, $dataInput); /** * * * * * * A FAIRE : TRAITER LES OPTIONS * * * * * * */ // Add options if the input type is a select if ($input->name = "select") { if (isset($dataInput['options'])) { foreach ($dataInput['options'] as $option) { $option['key'] = i18n::add($option['key'], 'option_key'); $option['value'] = i18n::add($option['value'], 'option_value'); SelectOption::add($input->id, $option); } } } // Add form map FormMap::add($input->id, $form->id, $lastOrder); return Redirect::route('admin.form.show', $form->id); }
public function generate($data, $pageId, $order) { $form = new self(); $fromObject = false; if (is_object($data)) { $data = $data->formr(); $form->i18n_title = NULL; $form->i18n_description = NULL; $fromObject = true; } $form->finish_on = $data['method']; $form->type = $data['type']; $form->save(); $orderMap = 0; foreach ($data['data'] as $dataInput) { // Increments the order $orderMap++; if ($fromObject) { $dataInput['title'] = NULL; $dataInput['label'] = NULL; $dataInput['placeholder'] = NULL; $dataInput['helper'] = NULL; } else { $dataInput['title'] = i18n::add($dataInput['title'], 'title'); $dataInput['label'] = i18n::add($dataInput['label'], 'label'); $dataInput['placeholder'] = i18n::add($dataInput['placeholder'], 'placeholder'); $dataInput['helper'] = i18n::add($dataInput['helper'], 'helper'); } $inputType = InputType::add($dataInput); $input = InputView::add($inputType->id, $dataInput); // Add options if the input type is a select if ($input->name = "select") { if (isset($dataInput['options'])) { foreach ($dataInput['options'] as $option) { if ($fromObject) { $option['key'] = NULL; $option['value'] = NULL; } else { $option['key'] = i18n::add($option['key'], 'option_key'); $option['value'] = i18n::add($option['value'], 'option_value'); } SelectOption::add($input->id, $option); } } } // Add form map FormMap::add($input->id, $form->id, $orderMap); } // Add a block if the form is not by a model if (!$fromObject) { $block = Block::add($pageId, $order, 'Formr'); BlockResponsive::add($block->id, 12, 3); } if ($fromObject) { // Add form model ModelForm::add($form->id, $data['model']); } // Generate a migrate file if ($form->finish_on == "database") { // Prepare migrate content $contentMigrate = $this->prepareMigrate($data['data']); $bob = new Migrator('form_' . $form->id, $contentMigrate); $bob->generate(); } return $form; }