/** * * This method processes the file, puts it away somewhere safe * and sends you onwards. * * STEP TWO * * @param Request $request * * @return \Illuminate\Http\RedirectResponse */ public function upload(Request $request) { if (!$request->hasFile('csv')) { Session::flash('warning', 'No file uploaded.'); return redirect(route('csv.index')); } $fullPath = $this->wizard->storeCsvFile($request->file('csv')->getRealPath()); $settings = []; $settings['date-format'] = Input::get('date_format'); $settings['has-headers'] = intval(Input::get('has_headers')) === 1; $settings['specifix'] = Input::get('specifix'); $settings['import-account'] = intval(Input::get('csv_import_account')); $settings['map'] = []; $settings['mapped'] = []; $settings['roles'] = []; if ($request->hasFile('csv_config')) { // Process config file if present. $data = file_get_contents($request->file('csv_config')->getRealPath()); $json = json_decode($data, true); if (is_array($json)) { $settings = array_merge($settings, $json); } } $this->data->setCsvFileLocation($fullPath); $this->data->setDateFormat($settings['date-format']); $this->data->setHasHeaders($settings['has-headers']); $this->data->setMap($settings['map']); $this->data->setMapped($settings['mapped']); $this->data->setRoles($settings['roles']); $this->data->setSpecifix($settings['specifix']); $this->data->setImportAccount($settings['import-account']); return redirect(route('csv.column-roles')); }
/** * * This method processes the file, puts it away somewhere safe * and sends you onwards. * * STEP TWO * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // need the length. * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly 5, its ok * * @param Request $request * * @return \Illuminate\Http\RedirectResponse */ public function upload(Request $request) { if (!$request->hasFile('csv')) { Session::flash('warning', 'No file uploaded.'); return redirect(route('csv.index')); } $fullPath = $this->wizard->storeCsvFile($request->file('csv')->getRealPath()); $settings = []; $settings['date-format'] = Input::get('date_format'); $settings['has-headers'] = intval(Input::get('has_headers')) === 1; $settings['specifix'] = is_array(Input::get('specifix')) ? Input::get('specifix') : []; $settings['import-account'] = intval(Input::get('csv_import_account')); $settings['delimiter'] = Input::get('csv_delimiter', ','); // A tab character cannot be used itself as option value in HTML // See http://stackoverflow.com/questions/6064135/valid-characters-in-option-value if ($settings['delimiter'] == 'tab') { $settings['delimiter'] = "\t"; } $settings['map'] = []; $settings['mapped'] = []; $settings['roles'] = []; if ($request->hasFile('csv_config')) { // Process config file if present. $data = file_get_contents($request->file('csv_config')->getRealPath()); $json = json_decode($data, true); if (is_array($json)) { $settings = array_merge($settings, $json); } } $this->data->setCsvFileLocation($fullPath); $this->data->setDateFormat($settings['date-format']); $this->data->setHasHeaders($settings['has-headers']); $this->data->setMap($settings['map']); $this->data->setMapped($settings['mapped']); $this->data->setRoles($settings['roles']); $this->data->setSpecifix($settings['specifix']); $this->data->setImportAccount($settings['import-account']); $this->data->setDelimiter($settings['delimiter']); return redirect(route('csv.column-roles')); }
/** * @param int $index * * @return bool */ protected function parseRow($index) { return $this->data->hasHeaders() && $index >= 1 || !$this->data->hasHeaders(); }