Ejemplo n.º 1
0
 public function addevent()
 {
     $data = Input::all();
     $data['society_id'] = Society::where('username', Session::get('username'))->first()->id;
     $event = Event::createEvent($data);
     Session::put('event_id', $event->id);
     return Redirect::route('add_question')->with('message', 'Event Successfully Created');
 }
Ejemplo n.º 2
0
 /**
  * Gets the events for a society
  * @param  [type] $day [description]
  * @return [type]      [description]
  */
 public function eventsForSociety($society_identifier)
 {
     $society_identifier = str_replace("-", " ", $society_identifier);
     try {
         $society = Society::where('id', $society_identifier)->orWhere('facebook_ref', $society_identifier)->firstOrFail();
     } catch (\Exception $e) {
         abort(404);
     }
     $events = Event::where('time', '>', date('Y-m-d H:i:s', time()))->where('society_id', $society->id)->orderBy('time')->get();
     return ['society' => $society, 'events' => $events];
 }
Ejemplo n.º 3
0
 public function view_event()
 {
     $data = Event::where('society_id', Auth::user()->id)->get();
     if (Auth::user()->privilege > 6) {
         $data = Event::all();
         foreach ($data as $d) {
             $d->soc = Society::where('id', Event::where('id', $d->id)->first()->society_id)->first()->username;
         }
     }
     $t = $data->toArray();
     if (empty($t)) {
         $data = "";
     }
     return View::make('view_events', ['data' => $data]);
 }
Ejemplo n.º 4
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     if ($this->isSeeding) {
         $toTake = 200;
         // 200 societies
         $delay = 0;
         // Immediately
     } else {
         $toTake = 20;
         // 20 societies
         $delay = 600;
         // 10 Minutes
     }
     FacebookSession::setDefaultApplication(getenv('FB_ID'), getenv('FB_SECRET'));
     $session = FacebookSession::newAppSession();
     try {
         $session->validate();
     } catch (FacebookRequestException $ex) {
         // Session not valid, Graph API returned an exception with the reason.
         dd($ex);
     } catch (\Exception $ex) {
         // Graph API returned info, but it may mismatch the current app or have expired.
         dd($ex);
     }
     $store = \App\Setting::where('name', 'next_society')->first();
     $lastUpdated = $store->setting;
     // Get last society ID updated;
     $societies = \App\Society::where('id', '>', $lastUpdated)->take($toTake)->orderBy('id')->get();
     // Get Societies to query
     foreach ($societies as $society) {
         $request = new FacebookRequest($session, 'GET', '/' . $society->facebook_ref . '/events' . '?since=' . time() . '&fields=name,start_time,location,description,cover');
         try {
             $response = $request->execute();
         } catch (\Exception $ex) {
             continue;
             // TODO: Report errors back to us :)
         }
         $graphObject = $response->getGraphObject();
         $events = $graphObject->asArray();
         if (array_key_exists('data', $events)) {
             $events = $events['data'];
             foreach ($events as $fbEvent) {
                 $storedEvent = \App\Event::firstOrNew(['facebook_id' => $fbEvent->id]);
                 $storedEvent->society_id = $society->id;
                 $storedEvent->title = $fbEvent->name;
                 $storedEvent->time = $fbEvent->start_time;
                 if (array_key_exists("description", $fbEvent)) {
                     $storedEvent->description = $fbEvent->description;
                 }
                 if (array_key_exists("location", $fbEvent)) {
                     $storedEvent->location = $fbEvent->location;
                 }
                 if (array_key_exists("cover", $fbEvent)) {
                     $storedEvent->image = $fbEvent->cover->source;
                 }
                 $storedEvent->save();
             }
         }
     }
     if (count($societies) < $toTake) {
         $store->setting = 0;
     } else {
         $store->setting += $toTake;
     }
     $store->save();
     $job = (new \App\Jobs\UpdateEvents())->delay($delay);
     if (!$this->isSeeding) {
         $this->dispatch($job);
     }
 }