Ejemplo n.º 1
0
 public function index_onFlyerImport($save = true)
 {
     $events = EventModel::whereNotNull('flyer_url')->has('flyers', 0)->limit(10)->get();
     $cleaned = [];
     $imported = [];
     $failed = [];
     /** @var  EventModel  $event */
     foreach ($events as $event) {
         $event->timestamps = false;
         if (trim($event->flyer_url) == '') {
             $event->flyer_url = null;
             $cleaned[$event->id] = $event;
         } else {
             try {
                 $save and $event->importFlyer();
                 $imported[$event->id] = $event;
             } catch (FileNotFoundException $e) {
                 $failed[$event->id] = $event;
             }
         }
         $save and $event->forceSave();
     }
     $this->vars['events'] = $events;
     $this->vars['cleaned'] = $cleaned;
     $this->vars['imported'] = $imported;
     $this->vars['failed'] = $failed;
 }
Ejemplo n.º 2
0
 public function listEvents()
 {
     if ($this->events) {
         return $this->events;
     }
     /** @var  Collection  $events */
     $events = EventModel::week($this->date)->get();
     // Add date and url
     $events->each(function (EventModel $event) {
         $event->date = $event->begins_at->toDateString();
         $event->setUrl($this->eventPage, $this->controller);
     });
     return $this->events = $events;
 }
Ejemplo n.º 3
0
 public function listEvents()
 {
     if ($this->events) {
         return $this->events;
     }
     /** @var  Collection  $events */
     switch ($this->datePeriod) {
         case self::PERIOD_WEEK:
             $events = EventModel::with('flyers.image')->week($this->date)->orderDefault()->get();
             break;
         default:
             return [];
     }
     // Add date and url
     $events->each(function (EventModel $event) {
         $event->date = $event->begins_at->toDateString();
         $event->setUrl($this->eventPage, $this->controller);
     });
     return $this->events = $events;
 }
 public function listEvents()
 {
     /** @var  Collection  $events */
     switch ($this->property('listType')) {
         case self::NEW_EVENTS:
             $events = EventModel::latest()->limit(5)->get();
             break;
         case self::POPULAR_EVENTS:
             $events = EventModel::popular()->limit(5)->get();
             break;
         case self::UPDATED_EVENTS:
             $events = EventModel::recentUpdates()->limit(5)->get();
             break;
         default:
             return [];
     }
     // Add url
     $events->each(function (EventModel $event) {
         $event->setUrl($this->eventPage, $this->controller);
     });
     return $events;
 }
Ejemplo n.º 5
0
 /**
  * Parse Event model from vEvent array.
  *
  * @param   array $eventArray
  * @return  Event
  */
 public static function parseEvent(array $eventArray)
 {
     $event = Event::make(['name' => $eventArray['SUMMARY'], 'url' => $eventArray['URL'], 'begins_at' => $eventArray['DTSTART'], 'ends_at' => $eventArray['DTEND'], 'info' => $eventArray['DESCRIPTION'] ?: null, 'updated_at' => $eventArray['DTSTAMP'], 'venue_name' => $eventArray['LOCATION'] ?: null, 'facebook_id' => $eventArray['ID'], 'facebook_organizer' => $eventArray['ORGANIZER']['properties']['CN'], 'price' => null]);
     return $event;
 }
Ejemplo n.º 6
0
 public function onRun()
 {
     $this->page['event'] = $this->event = EventModel::with('flyers.image', 'venue')->findOrFail((int) $this->property('id'));
 }
 /**
  * Update Event with venue data and create/update Venue.
  *
  * @param   EventModel  $event
  * @param   GraphPage   $placeObject
  * @param   bool        $save
  * @return  string      Error message, if any
  */
 protected function updateVenue(EventModel $event, GraphPage $placeObject = null, $save = false)
 {
     static $venues = [];
     if ($placeObject) {
         $event->venue_name = $placeObject->getName();
         $locationObject = $placeObject->getLocation();
         if ($locationObject) {
             $event->city_name = $locationObject->getCity();
         }
         // Update Venue only if not already updated
         $placeId = $placeObject->getId();
         if ($placeId && !isset($venues[$placeId])) {
             /** @var  QueryBuilder  $query */
             $query = VenueModel::facebook([$placeId]);
             if ($locationObject) {
                 $query->orWhere(function ($query) use($placeObject, $locationObject) {
                     $query->where(DB::raw('lower(name)'), '=', strtolower($placeObject->getName()))->where(DB::raw('lower(city_name)'), '=', strtolower($locationObject->getCity()));
                 });
             }
             $venue = $query->first();
             if (!$venue) {
                 $newItem = true;
                 $venue = VenueModel::make(['author_id' => $this->importUserId, 'name' => $placeObject->getName()]);
             } else {
                 $newItem = false;
             }
             $venues[$placeId] = $venue;
             if ($locationObject) {
                 $venue->fill(['address' => $locationObject->getStreet(), 'zip' => $locationObject->getZip(), 'city_name' => $locationObject->getCity(), 'country' => $locationObject->getCountry(), 'latitude' => $locationObject->getLatitude(), 'longitude' => $locationObject->getLongitude(), 'facebook_id' => $placeId]);
             }
             if ($save) {
                 try {
                     if ($venue->isDirty()) {
                         $venue->save();
                         // @TODO: Move to newsfeed plugin
                         $this->createVenueNewsfeedItem($venue->id, $newItem);
                     }
                 } catch (ModelException $e) {
                     return $e->getMessage();
                 }
             }
         } elseif (isset($venues[$placeId])) {
             $venue = $venues[$placeId];
         }
         if (isset($venue)) {
             $event->venue()->associate($venue);
         }
     }
     return null;
 }