Exemple #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     DB::table('propel_fellow_wingman')->delete();
     DB::table('propel_student_wingman')->delete();
     Subject::truncate();
     DB::table('propel_city_subject')->delete();
     CalendarEvent::truncate();
     CancelledCalendarEvent::truncate();
     WingmanModule::truncate();
     WingmanTime::truncate();
     VolunteerTime::truncate();
     WingmanJournal::truncate();
     $fellow = Fellow::find(1);
     $wingman1 = Wingman::find(2);
     $wingman2 = Wingman::find(3);
     $fellow->wingman()->attach($wingman1);
     $fellow->wingman()->attach($wingman2);
     $student1 = Student::find(3);
     $student2 = Student::find(4);
     $wingman1->student()->attach($student1);
     $wingman1->student()->attach($student2);
     $cEvent1 = new CalendarEvent();
     $cEvent1->type = 'volunteer_time';
     $cEvent1->student()->associate($student1);
     $cEvent1->status = 'created';
     $cEvent1->save();
     $vTime1 = new VolunteerTime();
     $vTime1->calendarEvent()->associate($cEvent1);
     $volunteer1 = Volunteer::find(4);
     $vTime1->volunteer()->associate($volunteer1);
     $subject1 = new Subject();
     $subject1->name = "English";
     $subject1->save();
     $vTime1->subject()->associate($subject1);
     $vTime1->save();
     $cEvent2 = new CalendarEvent();
     $cEvent2->type = 'wingman_time';
     $cEvent2->student()->associate($student1);
     $cEvent2->status = 'created';
     $cEvent2->save();
     $wTime1 = new WingmanTime();
     $wTime1->calendarEvent()->associate($cEvent2);
     $wTime1->wingman()->associate($wingman1);
     $wModule1 = new WingmanModule();
     $wModule1->name = "Programming";
     $wModule1->save();
     $wTime1->wingmanModule()->associate($wModule1);
     $wTime1->save();
     $city1 = City::find(1);
     $subject1->city()->attach($city1);
     $wJournal1 = new WingmanJournal();
     $wJournal1->type = 'formal';
     $wJournal1->title = "Day at Navy Camp";
     $wJournal1->mom = "It was awesome";
     $wJournal1->student()->associate($student1);
     $wJournal1->wingman()->associate($wingman1);
     $wJournal1->save();
 }
 public function cancelEvent()
 {
     $existing_ce = CalendarEvent::where('id', '=', Input::get('calendar_event_id'))->first();
     if ($existing_ce->type == "volunteer_time") {
         //Info required to send SMS
         $volunteer = $existing_ce->volunteerTime()->first()->volunteer()->first();
         //To get the first name
         list($volunteer_name) = explode(" ", $volunteer->name);
         $user = Volunteer::find($_SESSION['user_id']);
         list($user_name) = explode(" ", $user->name);
         //To get correctly formatted date and time
         $on_date = date("d-M", strtotime($existing_ce->start_time));
         $on_time = Input::get('start_time');
         $student = Student::find($existing_ce->student_id);
         $center_name = $student->center()->first()->name;
         //Send SMS to the volunteer informing them about the class
         $sms = new SMSController();
         switch (Input::get('reason')) {
             case 'mistaken_entry':
                 $sms->message = "Hi {$volunteer_name},\n\nYour class at {$center_name} on {$on_date} has been cancelled since it was a mistaken entry.\n\nPlease contact {$user_name}({$user->phone}) for more details.";
                 break;
             case 'volunteer_not_available':
                 $sms->message = "Hi {$volunteer_name},\n\nYour class at {$center_name} on {$on_date} has been cancelled since you are not available.\n\nPlease contact {$user_name}({$user->phone}) for more details.";
                 break;
             case 'student_not_available':
                 $sms->message = "Hi {$volunteer_name},\n\nYour class at {$center_name} on {$on_date} has been cancelled since the student is not available.\n\nPlease contact {$user_name}({$user->phone}) for more details.";
                 break;
         }
         $sms->number = $volunteer->phone;
         $sms->send();
     }
     if (Input::get('reason') == 'mistaken_entry') {
         $existing_ce->delete();
     } else {
         $existing_ce->status = 'cancelled';
         $existing_ce->save();
         $existing_cancelled_ce = CancelledCalendarEvent::where('calendar_event_id', '=', Input::get('calendar_event_id'))->first();
         if (!empty($existing_cancelled_ce)) {
             $existing_cancelled_ce->delete();
         }
         $cancelled_event = new CancelledCalendarEvent();
         $cancelled_event->calendar_event_id = $existing_ce->id;
         $cancelled_event->reason = Input::get('reason');
         $cancelled_event->comment = Input::get('comment');
         $cancelled_event->save();
     }
     //To check whether the request is coming from the child calendar or the asv calendar
     if (Request::segment(2) == 'asv') {
         return Redirect::to(URL::to('/calendar/asv/' . Input::get('volunteer_id')));
     } else {
         return Redirect::to(URL::to('/calendar/' . Input::get('wingman_id') . '/' . Input::get('student_id')));
     }
 }