Exemplo n.º 1
0
 public function fileImport($filePath)
 {
     header('Content-Type: text/html; charset=UTF-8');
     // Call benefiter table in db
     $file_import_Fields = ['id', 'folder_number', 'name', 'lastname', 'fathers_name', 'mothers_name', 'gender', 'origin_country', 'nationality_country', 'birth_date', 'arrival_date', 'address', 'telephone', 'marital_status', 'number_of_children', 'relatives_residence', 'legal_status', 'education', 'language', 'language_level', 'is_benefiter_working', 'work_title', 'working_legally', 'country_abandon_reason', 'travel_route', 'travel_duration', 'detention_duration'];
     // get max id in File_import_schema so that it won't try to insert benefiters already inserted via file
     $maxIdInFileImportSchema = File_import_schema::max('id');
     if ($maxIdInFileImportSchema == null) {
         $maxIdInFileImportSchema = 0;
     }
     // Import csv
     $csvFile = file($filePath);
     // Iterate between all rows of the csv file and add each value to the benefiters table
     for ($i = 1; $i < count($csvFile); $i++) {
         $colValues = str_getcsv($csvFile[$i]);
         $file_import = new File_import_schema();
         for ($j = 1; $j < count($colValues); $j++) {
             if ($j != count($colValues) - 1) {
                 $file_import->{$file_import_Fields}[$j] = $colValues[$j];
             }
         }
         try {
             $file_import->save();
         } catch (\Exception $e) {
             array_push($this->__errors, \Lang::get('upload_file_errors.import_csv_row_error1') . $file_import->folder_number . \Lang::get('upload_file_errors.import_csv_row_error2'));
             Log::error($e);
         }
     }
     \DB::insert(\DB::raw('insert into work_title_list_lookup (work_title) select distinct f.work_title  from  File_Import_Schema f left outer join work_title_list_lookup work_title on f.work_title = work_title.work_title where work_title.id is null;'));
     $this->conversionForFile = new ConversionsForFileUpload();
     $this->selectAppropriateDBTableForEachFileRowColumns($maxIdInFileImportSchema);
     return $this->__errors;
 }
Exemplo n.º 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     $data['email'] = strtolower($data['email']);
     $data['name'] = strtolower($data['name']);
     $date = new \DateTime();
     \DB::insert('insert into users_data (name, email, avatar, gender, full_name, bio, department, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?, ?, ?)', [$data['name'], $data['email'], '0', $data['gender'], $data['full_name'], '0', $data['department'], $date, $date]);
     \Schema::create('notification.inbox_' . $data['name'], function ($table) {
         $table->text('n_message', 500);
         $table->string('n_link');
         $table->string('n_sender');
         $table->boolean('n_read');
         $table->timestamps();
     });
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }