コード例 #1
0
 /**
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getDownloadResults(Request $request, $formId)
 {
     /** @var Form $form */
     $form = Form::find($formId);
     $data['headers'] = FormField::where(['form_id' => $formId])->get();
     $data['results'] = $form->resultsForUser(Auth::user());
     $data['tzoffset'] = intval($request->get('tzoffset', 0)) * -1;
     Excel::create('resultados', function ($excel) use($data) {
         $excel->getDefaultStyle()->getAlignment()->setWrapText(true);
         $excel->sheet('Hoja 1', function (LaravelExcelWorksheet $sheet) use($data) {
             $contents = [];
             foreach ($data['results'] as $key => $result) {
                 $row = [];
                 foreach ($data['headers'] as $header) {
                     if ($header->type == 'hidden' && object_get($header->config, 'dataType') == 'json') {
                         $row[$header->name] = json_encode(object_get($result->results, $header->alias), JSON_UNESCAPED_UNICODE);
                     } else {
                         $row[$header->name] = $this->remove_emoji(object_get($result->results, $header->alias));
                     }
                     if (gettype($row[$header->name]) === 'array') {
                         $row[$header->name] = implode(',', $row[$header->name]);
                     }
                     if (substr($row[$header->name], 0, 1) === '=') {
                         $row[$header->name] = ' ' . $row[$header->name];
                     }
                 }
                 $row['Fecha'] = $result->created_at->addMinutes($data['tzoffset']);
                 $contents[] = $row;
             }
             $sheet->fromArray($contents);
         });
     })->export('xls');
 }
コード例 #2
0
 public function postProcessFileUpload(Request $request)
 {
     $form = Form::find($request->input('form_id'));
     $files = $response = $validations = $niceNames = [];
     foreach ($form->fields as $field) {
         if ($field->type == 'file') {
             $files[$field->alias] = $request->file('field-' . $field->alias, '');
             $validations[$field->alias] = $field->getValidations();
             $errors = $files[$field->alias]->getError() > 0 ? [$files[$field->alias]->getErrorMessage()] : [];
             $fileName = $files[$field->alias]->getClientOriginalName();
             $fileCount = 0;
             if (!$errors) {
                 while (Storage::drive('modules')->exists('moduleforms/' . $fileName)) {
                     $fileName = $this->addCountToFilename($files[$field->alias], ++$fileCount);
                 }
                 Storage::drive('modules')->put('moduleforms/' . $fileName, file_get_contents($files[$field->alias]->getRealPath()));
             }
             $response[$field->alias] = ['name' => $fileName, 'size' => $files[$field->alias]->getSize(), 'error' => $errors, 'input' => $field->alias];
         }
     }
     $validator = Validator::make($files, $validations);
     if ($validator->fails()) {
         foreach ($files as $inputName => $file) {
             $response[$inputName]['error'] += $validator->errors()->get($inputName);
         }
     }
     return response()->json(['files' => array_values($response)]);
 }
コード例 #3
0
 private function getTwigForm()
 {
     $form = FormModel::where(['alias' => $this->form_alias, 'site_id' => $this->site->id])->first();
     return new FormTwig($form, $this->site, $this->isAjax);
 }