Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     DB::beginTransaction();
     $request['role'] = 'volunteer';
     $result = $this->register($request);
     $value = $result->getData();
     if (property_exists($value, 'error')) {
         return $result;
     } else {
         $volunteer = new Volunteer();
         $volunteer['userId'] = $value->result->id;
         $volunteer['contactNumber'] = $request->input('contactNumber');
         $volunteer['firstname'] = $request->input('firstname');
         $volunteer['lastname'] = $request->input('lastname');
         try {
             $volunteer->save();
         } catch (\Exception $e) {
             DB::rollback();
             return response()->json(['error' => ['message' => 'Error while saving Volunteer' . $e, 'code' => 400]]);
         }
         DB::commit();
         $finalResult['id'] = $value->result->id;
         $finalResult['token'] = $value->result->token;
         return response()->json(['result' => $finalResult]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     // Create a faker, add en_SG providers
     $faker->addProvider(new Faker\Provider\en_SG\Address($faker));
     $faker->addProvider(new Faker\Provider\en_SG\Enhanced($faker));
     $faker->addProvider(new Faker\Provider\en_SG\Person($faker));
     $faker->addProvider(new Faker\Provider\en_SG\PhoneNumber($faker));
     $faker->seed(9876);
     // Calling the same script twice with the same seed produces the same results
     $jobTitles = array('Accountant', 'Artist', 'Artiste', 'Associate Treasury Markets', 'Bank Executive', 'Banker', 'Bus Captain', 'Cashier', 'Chemist', 'Civil Servant', 'Civil Service', 'Cleaner', 'Company Director', 'Compliance Officer', 'Credit Control VP', 'Customer Service', 'Designer', 'Director', 'Doctor', 'Driver', 'Education Officer', 'Electrician', 'Engineer', 'Entrepreneur', 'Events Industry', 'Executive', 'Finance Consultant', 'Financial Service Consultant', 'Freelancer', 'Hawker', 'Homemaker', 'Hairdresser', 'HR Manager', 'Human Resource Executive', 'Insurance Agent', 'Jobless', 'Junior Executive', 'Manager', 'Music director', 'Nurse', 'Optometrist', 'Penetration Tester', 'Pilot', 'Police', 'Project Engineer', 'Project Manager', 'Self-employed', 'Soldier', 'Surgeon', 'Taxi Driver', 'Teacher', 'Tuition Teacher', 'Unemployed');
     // Insert 10 dummy records
     foreach (range(1, 10) as $index) {
         $gender = $faker->randomElement(['male', 'female']);
         $dob = $faker->dateTimeBetween('-50 years', '-16 years');
         $fullName = explode("|", $faker->unique()->nameWithSalutation($gender));
         // Extract full name without salutation ("Full Name|Salutation" to array)
         $fullName = $fullName[0];
         $emailName = strtolower(preg_replace('/\\s+/', '', $fullName));
         // Remove whitespaces in full name, convert to lowercase
         strlen($emailName) > 8 ? $emailName = substr($emailName, 0, 8) : null;
         // Extract only 8 characters from full name
         $email = $emailName . substr($dob->format('Y'), -2) . '@' . $faker->localFreeEmailDomain;
         // 8 characters from full name + last 2 digit from birth year + email domain
         $approval = $faker->optional(0.9, 'rejected')->randomElement(['pending', 'approved']);
         // 10% chance of rejected
         $dob->diff(Carbon::now())->y > 21 ? $job = $faker->optional(0.9, 'Student')->randomElement($jobTitles) : ($job = 'Student');
         // Age 21 or younger are all students
         Volunteer::create(['nric' => $faker->unique()->nric, 'name' => $fullName, 'email' => $email, 'password' => 'qwerty123', 'gender' => ucwords($gender[0]), 'date_of_birth' => $dob, 'contact_no' => preg_replace('/-/', '', $faker->mobile), 'occupation' => $job, 'has_car' => $faker->boolean(30), 'minutes_volunteered' => $approval == 'rejected' ? 0 : $faker->optional(0.6, 0)->numberBetween(1, 9) * (60 * $faker->numberBetween(1, 3)), 'area_of_preference_1' => 'Befriend senior citizens', 'area_of_preference_2' => 'Lead games/exercises', 'image_nric_front' => 'image/image_nric_front.jpg', 'image_nric_back' => 'image/image_nric_back.jpg', 'is_approved' => $approval, 'rank_id' => 4]);
     }
 }
Exemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     if (App::environment() === 'production') {
         exit('Do not seed in production environment');
     }
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     // disable foreign key constraints
     DB::table('users')->truncate();
     DB::table('volunteers')->truncate();
     DB::table('doctors')->truncate();
     User::create(['id' => 1, 'name' => 'admin', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 2]);
     User::create(['id' => 2, 'name' => 'volunteer1', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 5]);
     User::create(['id' => 3, 'name' => 'Arun', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 4, 'name' => 'Biswas', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 5, 'name' => 'Sunil', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 6, 'name' => 'volunteer2', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 5]);
     Volunteer::create(['userId' => 3, 'firstname' => 'volunteer1', 'lastname' => 'volunteer1', 'contactNumber' => '9717017651', 'isVerified' => true]);
     Volunteer::create(['userId' => 6, 'firstname' => 'volunteer2', 'lastname' => 'volunteer2', 'contactNumber' => '9717017650', 'isVerified' => true]);
     Doctor::create(['userId' => 3, 'firstname' => 'Arun', 'lastname' => 'Jain', 'contactNumber' => '9717017650', 'specialization' => 1, 'location' => 'Delhi', 'isVerified' => true]);
     Doctor::create(['userId' => 4, 'firstname' => 'Biswas', 'lastname' => 'Rao', 'contactNumber' => '9717017651', 'specialization' => 2, 'location' => 'Bangalore', 'isVerified' => true]);
     Doctor::create(['userId' => 5, 'firstname' => 'Sunil', 'lastname' => 'Jain', 'contactNumber' => '9717017651', 'specialization' => 2, 'location' => 'Bangalore', 'isVerified' => true]);
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     // enable foreign key constraints
 }
Exemplo n.º 4
0
 public function approveVolunteer($volunteerId)
 {
     try {
         Volunteer::where('userId', $volunteerId)->update(['isVerified' => true]);
     } catch (\Exception $e) {
         return array('error' => ['message' => 'Error in updating object', 'code' => 101]);
     }
     return response()->json(['result' => 'success']);
 }
 /**
  * Retrieves information for volunteer leaderboard.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array with top 10 users and position
  */
 public function volunteerLeaderboard(Request $request)
 {
     if ($request->get('token') != null) {
         $authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate();
         $id = $authenticatedUser->volunteer_id;
         $volunteerEnquired = Volunteer::findOrFail($id);
         $volunteerName = $volunteerEnquired->name;
         // user rank
         $rankid = Volunteer::where('volunteer_id', $id)->value('rank_id');
         $rank = Rank::findOrFail($rankid)->name;
         $totalMinutes = Volunteer::where('volunteer_id', $id)->value('minutes_volunteered');
         $volunteerIdList = Volunteer::where('is_approved', 'approved')->orderBy('minutes_volunteered', 'desc')->lists('volunteer_id');
         $count = 0;
         $xCount = 1;
         $pos = 0;
         $returnArray = [];
         $listSize = count($volunteerIdList) - 1;
         do {
             $volunteerID = $volunteerIdList[$count];
             $volunteer = Volunteer::find($volunteerID);
             $volunteerName = $volunteer->name;
             $volunteerMinutes = $volunteer->minutes_volunteered;
             $stringToAdd = $volunteerMinutes . "," . $volunteerName . "," . $xCount;
             $returnArray[] = $stringToAdd;
             if ($id == $volunteerID) {
                 $pos = $xCount;
             }
             $count = $count + 1;
             $xCount = $xCount + 1;
         } while ($count <= $listSize);
         return response()->json(compact('rank', 'totalMinutes', 'returnArray', 'pos'));
     } else {
         $status = ["Missing parameter"];
         return response()->json(compact('status'));
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Volunteer::destroy($id);
     return redirect('volunteers');
 }
 /**
  * Handles the withdrawal of activity from user.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array with Status
  */
 public function withdraw(Request $request)
 {
     if ($request->get('volunteer_id') == null || $request->get('activity_id') == null) {
         $status = ["Missing parameter"];
         return response()->json(compact('status'));
     } else {
         $volunteer_id = $request->get('volunteer_id');
         $activity_id = $request->get('activity_id');
         $volunteer = Volunteer::findOrFail($volunteer_id);
         $withdrawnActivity = Activity::findOrFail($activity_id);
         $task = Task::where('volunteer_id', $volunteer_id)->where('activity_id', $activity_id)->update(['approval' => 'withdrawn']);
         $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray();
         $status = ["Withdrawn from activity"];
         Mail::send('emails.volunteer_withdraw', compact('volunteer', 'withdrawnActivity'), function ($message) use($mailingList) {
             $message->subject('A volunteer has withdrawn from an activity');
             $message->to($mailingList);
         });
         return response()->json(compact('status'));
     }
 }
 /**
  * Approve a given volunteer account.
  * Responds to requests to PATCH /volunteers/{id}/approve
  *
  * @param  int  $id  the ID of the volunteer
  * @return Response
  */
 public function approveVolunteer($id)
 {
     $volunteer = Volunteer::findOrFail($id);
     if ($volunteer->is_approved !== 'approved') {
         $volunteer->is_approved = 'approved';
         $volunteer->save();
         $email = $volunteer->email;
         Mail::send('emails.volunteer_approval', compact('volunteer'), function ($message) use($email) {
             $message->subject('Your CareGuide Volunteer account has been approved.');
             $message->bcc($email);
         });
         return back()->with('success', 'Volunteer is approved!');
     } else {
         return back()->with('error', 'Volunteer is ' . $volunteer->is_approved . 'already!');
     }
 }