/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Iniciando a requisição para o webservice');
     $this->info('Carregando a lista de estados');
     $estados = $this->makeRequest('estados');
     $this->info('Foram encontrados ' . count($estados) . ' estados');
     $this->info('Carregando a lista de cargos');
     $cargos = CandidateType::all()->lists('id', 'type');
     $this->info('Foram encontrados ' . count($cargos) . ' cargos');
     $this->info('Carregando a lista de partidos');
     $partidos = Party::all()->lists('id', 'abbreviation');
     $this->info('Foram encontrados ' . count($partidos) . ' partidos');
     foreach ($estados as $estado_id => $estado) {
         $this->info("Carregando os candidatos de {$estado->sigla} ({$estado_id}/" . count($estado) . ")");
         foreach ($cargos as $cargo_nome => $cargo_id) {
             $this->info('- Procurando por ' . $cargo_nome);
             $candidatos = $this->makeRequest('candidatos', ['estado' => $estado->sigla, 'cargo' => $cargo_id]);
             foreach ($candidatos as $candidato) {
                 $candidate = Candidate::where('full_name', $candidato->nome)->first();
                 if (!$candidate) {
                     $this->info('-- Processando ' . $candidato->nome . '/' . $candidato->apelido);
                     $picture_hash = Str::random(90) . ".jpg";
                     file_put_contents(app_path() . '/../www/uploads/' . $picture_hash, file_get_contents($candidato->foto));
                     Candidate::create(['party_id' => $partidos[$candidato->partido], 'candidate_type_id' => $cargos[ucfirst(strtolower(str_replace('º', '', (string) $candidato->cargo)))], 'nickname' => $candidato->apelido, 'full_name' => $candidato->nome, 'picture' => $picture_hash]);
                 }
             }
             //$this->info('Foram encontrados ' . count($candidatos) . ' candidatos');
         }
     }
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 80) as $index) {
         $fullName = $faker->name;
         $user = User::create(['full_name' => $fullName, 'email' => $faker->email, 'password' => \Hash::make(123456), 'type' => 'candidate']);
         Candidate::create(['id' => $user->id, 'website_url' => $faker->url, 'description' => $faker->text(200), 'job_type' => $faker->randomElement(['full', 'partial', 'freelance']), 'category_id' => $faker->randomElement([1, 2, 3]), 'available' => true, 'slug' => \Str::slug($fullName)]);
     }
 }
 public function postNewCandidate()
 {
     //verify the user input and create account
     $validator = Validator::make(Input::all(), array('Students_ID' => 'required|max:15', 'Post' => 'required', 'Motto' => 'required', 'Photo' => 'image|max:3000'));
     if ($validator->fails()) {
         return Redirect::route('admin-new-candidate-get')->withErrors($validator)->withInput()->with('globalerror', 'Sorry!! The Data was not Saved, please retry');
     } else {
         $students_ID = Input::get('Students_ID');
         $post = Input::get('Post');
         $motto = Input::get('Motto');
         $file = Input::file('Photo');
         $studentsid = null;
         $user_id = null;
         //extract the users id
         $user = User::where('Identity_No', '=', $students_ID);
         //check whether the user exists
         if ($user->count()) {
             $user = $user->first();
             $user_id = $user->id;
             $student = Student::where('Users_ID', $user_id)->first();
             $studentsid = $student->id;
         } else {
             return Redirect::route('admin-new-candidate-get')->withInput()->with('globalerror', 'Sorry!! This Student Doesn\'t Exist');
         }
         //save the candidates photo to the candidate_photos directory
         $destinationPath = 'candidates_photos';
         $ext = $file->guessClientExtension();
         // Get real extension according to mime type
         $fullname = $file->getClientOriginalName();
         // Client file name, including the extension of the client
         $hashname = date('H.i.s') . '-' . md5($fullname) . '.' . $ext;
         // Hash processed file name, including the real extension
         $upload_success = $file->move($destinationPath, $hashname);
         //craete the new candidates information and save in the database
         //register the new user
         $newcandidate = Candidate::create(array('Users_Id' => $user_id, 'Students_Id' => $studentsid, 'Posts_Id' => $post, 'Motto' => $motto, 'Photo' => 'candidates_photos/' . $hashname, 'Active' => TRUE));
         if ($newcandidate) {
             return Redirect::route('admin-new-candidate-get')->with('globalsuccess', 'Candidate details have been added');
         }
     }
 }
 public function file_move()
 {
     if (Input::hasFile('image')) {
         $vote_id_temp = Session::get('vote_id_insert', '');
         $this->clean($vote_id_temp);
         $file = Input::file('image');
         //
         $fileName = "test222";
         $destinationPath = storage_path() . '/file_import/';
         $file = $file->move($destinationPath, $fileName);
         Excel::selectSheetsByIndex(0)->load($file, function ($reader) use($vote_id_temp) {
             //以第一個資料表中的資料為主
             //提醒使用ooo的使用者,不要存成 Microsoft Excel 95
             //需存成 Microsoft Excel 97/2000/xp  ***.xls
             $value = $reader->get()->toArray();
             //object -> array
             foreach ($value as $data_array1) {
                 //$vote_id_temp = Session::get('vote_id_insert', '');
                 $data_array1['vote_id'] = $vote_id_temp;
                 //var_dump($data_array1);
                 $candidate = Candidate::create($data_array1);
                 // $candidate = new Candidate;
                 // $candidate->cname=$data_array1[0];
                 // $candidate->job_title=$data_array1[1];
                 // $candidate->sex=$data_array1[2];
                 // $candidate->vote_id=42;
                 // $candidate->total_count=0;
                 // $candidate->save();
             }
         });
         // echo $file;
         //File::delete($file);
     }
     return Redirect::route('votes_not_yet');
 }
Esempio n. 5
0
 protected function createTestJohnCandidate()
 {
     self::setTestApiKey();
     $test_john = array('name_first' => 'John', 'name_last' => 'Bredenkamp');
     return Candidate::create($test_john);
 }