Пример #1
0
 public static function submitData($data, $dataFiles)
 {
     $bResult = false;
     $formId = array_get($data, 'formbuilder_id');
     $locale = array_get($data, 'formbuilder_locale');
     $clientIp = array_get($data, 'client_ip');
     $formBuilder = Forms::find($formId);
     if ($formBuilder->id) {
         DB::beginTransaction();
         try {
             $formSubmit = new self();
             $formSubmit->form_id = $formId;
             $formSubmit->locale = $locale;
             $formSubmit->client_ip = $clientIp;
             $formSubmit->save();
             $formSubmitId = $formSubmit->id;
             $order = 0;
             foreach ($data as $key => $value) {
                 if (!in_array($key, $formSubmit->unSaveField)) {
                     $formSubmitData = new FormSubmitData();
                     $formSubmitData->submit_id = $formSubmitId;
                     $formSubmitData->field_name = $key;
                     $formSubmitData->field_value = $value;
                     $formSubmitData->field_order = $order;
                     $formSubmitData->save();
                     ++$order;
                     FormbuilderShortcode::registerSubmitShortcode($key, $value);
                 }
             }
             foreach ($dataFiles as $key => $value) {
                 if (!in_array($key, $formSubmit->unSaveField)) {
                     $formSubmitData = new FormSubmitData();
                     $formSubmitData->submit_id = $formSubmitId;
                     $formSubmitData->field_name = $key;
                     $formSubmitData->field_value = $value;
                     $formSubmitData->field_order = $order;
                     $formSubmitData->is_file = 1;
                     $formSubmitData->save();
                     ++$order;
                     FormbuilderShortcode::registerSubmitShortcode($key, $value);
                 }
             }
             DB::commit();
             $formMail = new FormMail();
             $formMail->sendMail($formSubmitId, $locale);
             event(new FormbuilderEvent('submit_form', $data));
             $bResult = true;
         } catch (\Exception $ex) {
             Log::info($ex);
             DB::rollback();
         }
     }
     return $bResult;
 }
Пример #2
0
 public static function storeForm($data)
 {
     $bResult = false;
     $languages = LaravelLocalization::getSupportedLocales();
     DB::beginTransaction();
     try {
         $id = !empty(array_get($data, 'id', 0)) ? array_get($data, 'id', 0) : null;
         $formBuilder = self::firstOrNew(['id' => $id]);
         $formBuilder->fill($data)->save();
         $formId = $formBuilder->id;
         foreach ($languages as $locale => $value) {
             $dataOfLocale = array_get($data, $locale);
             $dataForm = array_get($dataOfLocale, 'form');
             $dataMail = array_get($dataOfLocale, 'mail');
             $dataMessages = array_get($dataOfLocale, 'messages');
             $editedContent = array_get($dataForm, 'content_edited', '');
             if ($editedContent) {
                 $dataForm['content'] = $editedContent;
                 $dataForm['edited'] = 1;
             }
             $formContent = FormContent::firstOrNew(array('form_id' => $formId, 'locale' => $locale));
             $formContent->fill($dataForm)->save();
             $formMail = FormMail::firstOrNew(array('form_id' => $formId, 'locale' => $locale));
             $formMail->fill($dataMail)->save();
             $formMessages = FormMessages::firstOrNew(array('form_id' => $formId, 'locale' => $locale));
             $formMessages->fill($dataMessages)->save();
         }
         DB::commit();
         $bResult = true;
     } catch (\Exception $ex) {
         Log::info($ex);
         DB::rollback();
     }
     return $bResult;
 }