/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $directory = 'img/uploads/';
     $image = Input::file('img');
     $event = new CalendarEvent();
     $event->title = Input::get('title');
     $event->description = Input::get('description');
     $event->date = Input::get('date');
     $event->price = Input::get('price');
     $event->start_time = Input::get('start_time');
     $event->end_time = Input::get('end_time');
     $event->location = Input::get('location');
     $event->address = Input::get('address');
     $event->city = Input::get('city');
     $event->state = Input::get('state');
     $event->zip = Input::get('zip');
     $event->user_id = 1;
     if (Input::hasFile('img')) {
         $event->img = $image->move($directory);
     }
     $event->save();
     Log::info("Event successfully saved.", Input::all());
     Session::flash('successMessage', 'You created ' . $event->title . ' event successfully');
     return Redirect::action('EventsController@index');
 }
 protected function validateAndSave($calendarevent)
 {
     $calendarevent = new CalendarEvent();
     $calendarevent->title = Input::get('title');
     $calendarevent->description = Input::get('description');
     $calendarevent->price = Input::get('price');
     /*$calendarevent->start_date_time = Input::get('start_date');
     		$calendarevent->end_date_time = Input::get('end_date');*/
     $calendarevent->url = Input::get('url');
     $calendarevent->user_id = 148;
     $calendarevent->location_id = 1;
     if (!$calendarevent->save()) {
         Log::info('This is some useful information.');
         // set flash data
         Session::flash('errorMessage', 'Unable to save input - please try again.');
         // retrieve flash data (same as any other session variable)
         $value = Session::get('key');
         return Redirect::back();
     } else {
         // set flash data
         Session::flash('successMessage', 'Your event was successfully added.');
         // retrieve flash data (same as any other session variable)
         $value = Session::get('key');
     }
     /*need to add Auth::id() for create post to work*/
     /*$calendarevent->user_id = Auth::id();*/
     CalendarEvent::create($data);
     return Redirect::route('calendar_events.index');
 }
 public function update_event()
 {
     if (!isset($_POST['save'])) {
         Flash::set('error', __('Could not update this event!'));
     } else {
         use_helper('Kses');
         /* Prepare the data */
         $data = $_POST['event'];
         if (isset($data['id'])) {
             $data['id'] = kses(trim($data['id']), array());
         }
         $event = new CalendarEvent();
         if (isset($data['id'])) {
             $event->id = $data['id'];
             $event->created_by_id = $data['created_by_id'];
         }
         $event->title = $data['title'];
         $event->date_from = $data['date_from'];
         $event->date_to = $data['date_to'];
         $event->description = $data['description'];
         /* Check data and, if correct, save to DB */
         if ($event->checkData() && $event->save()) {
             if (isset($data['id'])) {
                 Flash::set('success', __('The event has been updated.'));
             } else {
                 Flash::set('success', __('A new event has been created.'));
             }
             redirect(get_url('plugin/calendar/events'));
         } else {
             Flash::setNow('error', __('There are errors in the form.'));
             $this->display(CALENDAR_VIEWS . '/update', array('event' => $event));
         }
     }
 }
 private function process_update_post(CalendarEvent $old_event)
 {
     $updating = (bool) $old_event->getId();
     if (isset($_POST['save']) && isset($_POST['event'])) {
         $post_data = array_map('trim', $_POST['event']);
         // validate the data and create error message
         $errors = $this->validate_post_data($post_data);
         if ($errors) {
             Flash::setNow('error', 'There are errors in the form.');
             return array('event' => $old_event, 'updating' => $updating, 'post_data' => $post_data, 'errors' => $errors);
         }
         // if we'are updating an event, some data should be added to $post_data
         if ($updating) {
             $post_data['id'] = $old_event->getId();
             $post_data['created_by_id'] = $old_event->getAuthorID();
         }
         $updated_event = new CalendarEvent($post_data);
         $saved = $updated_event->save();
         if ($saved) {
             Flash::set('success', $updating ? __('The event has been updated.') : __('A new event has been created.'));
             redirect(get_url('plugin/' . CALENDAR_ID . '/events'));
         } else {
             Flash::setNow('error', __('Could not update this event!'));
             return array('event' => $updated_event, 'updating' => $updating);
         }
     }
     // if it's not POST, just return $old_event
     return array('event' => $old_event, 'updating' => $updating);
 }
示例#5
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();
 }
 /**
  * Store a newly created event in storage.
  *
  * @return Response
  */
 public function store()
 {
     $file = Input::file('img_url');
     $destinationPath = public_path() . '/img';
     $filename = $file->getClientOriginalName();
     Input::file('img_url')->move($destinationPath, $filename);
     $event = new CalendarEvent();
     $event->event_name = Input::get('event_name');
     $event->event_description = Input::get('event_description');
     $event->event_location = Input::get('event_location');
     $event->event_start = Input::get('event_start');
     $event->event_end = Input::get('event_end');
     $event->img_url = $filename;
     $event->user_id = Auth::id();
     $event->save();
     // attempt validation
     if (!$event->save()) {
         return Redirect::to('create')->withErrors($event->getErrors())->withInput();
     } else {
         Session::flash('successMessage', 'Event created successfully!');
         return Redirect::action('EventsController@index');
     }
 }
 public function run()
 {
     $faker = Faker::create();
     for ($i = 0; $i < 25; $i += 1) {
         $event = new CalendarEvent();
         $event->start_time = '2015-09-01 12:00:00';
         $event->end_time = '2015-09-02 12:00:00';
         $event->title = $faker->catchPhrase;
         $event->description = $faker->text(100);
         $event->price = '0';
         $event->user_id = User::all()->random()->id;
         $event->location_id = Location::all()->random()->id;
         $event->game_id = Game::all()->random()->id;
         $event->save();
     }
 }
 public function run()
 {
     $faker = Faker::create();
     for ($i = 0; $i < 60; $i++) {
         $calendarEvent = new CalendarEvent();
         $calendarEvent->start = "2012-12-02 13:00";
         $calendarEvent->end = "2012-12-02 19:00";
         $calendarEvent->title = $faker->catchPhrase . " " . $faker->catchPhrase;
         $calendarEvent->description = $faker->realText(200, 2);
         $calendarEvent->price = rand(0, 10);
         $calendarEvent->user_id = User::all()->random(1)->id;
         $calendarEvent->location_id = Location::all()->random(1)->id;
         $calendarEvent->img = $faker->imageUrl($width = 640, $height = 480);
         $calendarEvent->save();
     }
 }
 /**
  * Store a newly created resource in storage.
  * POST /location
  *
  * @return Response
  */
 public function store()
 {
     $event = new CalendarEvent();
     $event->start = Input::get('start');
     $event->end = Input::get('end');
     $event->title = Input::get('title');
     $event->description = Input::get('description');
     if (Input::hasFile('img')) {
         $event->img = Input::file('img')->move("images/uploaded/");
     }
     if (Input::has('price')) {
         $event->price = Input::get('price');
     }
     $event->user_id = Auth::id();
     $event->location_id = Input::get('locationID');
     $event->save();
     Log::info('Log Message', Input::all());
     $locations = Location::orderBy('created_at', 'desc')->paginate(6);
     return Redirect::action('LocationController@index');
 }
 public function run()
 {
     $faker = Faker::create();
     for ($i = 1; $i <= 10; $i++) {
         $event = new CalendarEvent();
         $event->title = $faker->catchPhrase;
         $event->description = $faker->realText;
         $event->date = $faker->dateTime;
         $event->price = $faker->numberBetween($min = 1, $max = 100);
         $event->start_time = $faker->time($format = 'H:i:s');
         $event->location = $faker->country;
         $event->address = $faker->streetAddress;
         $event->city = $faker->city;
         $event->state = $faker->state;
         $event->zip = $faker->postcode;
         $event->img = $faker->imageUrl($width = 640, $height = 480);
         // 'http://lorempixel.com/640/480/'
         $event->user_id = User::all()->random(1)->id;
         $event->save();
     }
 }
 public function run()
 {
     $faker = Faker::create();
     /*foreach(range(1, 10) as $index)*/
     for ($i = 0; $i < 50; $i++) {
         $calendar_event = new CalendarEvent();
         // $calendar_event->user_id = 1;
         // $calendar_event->location_id = 1;
         $calendar_event->user_id = User::all()->random()->id;
         $calendar_event->location_id = Location::all()->random()->id;
         // $calendar_event->start_date_time = '2015-09-12';
         // $calendar_event->end_date_time = '2015-09-13';
         $startDate = Carbon::createFromTimeStamp($faker->dateTimeBetween('-30 days', '+30 days')->getTimestamp());
         $calendar_event->start_date_time = $startDate;
         $calendar_event->end_date_time = Carbon::createFromFormat('Y-m-d H:i:s', $startDate)->addHour();
         $calendar_event->title = $faker->title;
         $calendar_event->description = $faker->catchPhrase;
         $calendar_event->price = $faker->randomNumber(2);
         $calendar_event->url = $faker->imageUrl(640, 480, 'city');
         $calendar_event->save();
     }
 }
示例#12
0
 public function createEvent()
 {
     if (Input::get('type') == "") {
         return Redirect::to(URL::to('/calendar/' . Input::get('wingman_id') . '/' . Input::get('student_id')));
     }
     if (Input::get('subject') == "" && Input::get('type') == 'volunteer_time') {
         return Redirect::to(URL::to('/calendar/' . Input::get('wingman_id') . '/' . Input::get('student_id')))->with('error', 'Subject not selected.');
     }
     //Foreach because in case there are multiple student ids (in case of asv calendar)
     $students = (array) Input::get('student_id');
     $length = count($students);
     foreach ($students as $index => $student) {
         $ce = new CalendarEvent();
         $ce->type = Input::get('type');
         $ce->start_time = new DateTime(Input::get('on_date') . ' ' . Input::get('start_time'));
         $ce->end_time = new DateTime(Input::get('end_date') . ' ' . Input::get('end_time'));
         $ce->student_id = $student;
         $ce->status = 'created';
         $ce->save();
         switch ($ce->type) {
             case 'wingman_time':
                 $wt = new WingmanTime();
                 $wt->wingman_id = Input::get('wingman_id');
                 $wt->wingman_module_id = Input::get('wingman_module');
                 $wt->calendar_event_id = $ce->id;
                 $wt->save();
                 break;
             case 'volunteer_time':
                 $vt = new VolunteerTime();
                 $vt->volunteer_id = Input::get('volunteer_id');
                 $vt->subject_id = Input::get('subject');
                 $vt->calendar_event_id = $ce->id;
                 $vt->save();
                 //To ensure that in case of request from ASV calendar, where there would be multiple students chosen, the SMS is only sent once and not multiple times.
                 //Here it is sent on the last iteration.
                 if ($index == $length - 1) {
                     //Send SMS to the volunteer informing them about the class
                     $volunteer = Volunteer::find(Input::get('volunteer_id'));
                     //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(Input::get('on_date')));
                     $on_time = Input::get('start_time');
                     $student = Student::find($ce->student_id);
                     $center_name = $student->center()->first()->name;
                     $sms = new SMSController();
                     $sms->message = "Hi {$volunteer_name},\n\nYou have a class scheduled at {$center_name} on {$on_date}({$on_time}).\n\nPlease contact {$user_name}({$user->phone}) for more details.";
                     $sms->number = $volunteer->phone;
                     $sms->send();
                 }
                 break;
         }
     }
     //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')));
     }
 }