Beispiel #1
0
 /**
  * @link http://www.last.fm/api/show/geo.getEvents
  *
  * @param float|null $long
  * @param float|null $lat
  * @param string|null $location
  * @param float|null $distance
  * @param string|null $tag
  * @param bool $festivalsonly
  * @throws \Lertify\Lastfm\Exception\NotFoundException
  * @return \Lertify\Lastfm\Api\Data\PagedCollection
  */
 public function getEvents($long = null, $lat = null, $location = null, $distance = null, $tag = null, $festivalsonly = false)
 {
     $params = array('long' => $long, 'lat' => $lat, 'location' => $location, 'distance' => $distance, 'tag' => $tag, 'festivalsonly' => $festivalsonly);
     $self = $this;
     $resultCallback = function ($page, $limit) use($params, $self) {
         $params = array_merge($params, array('page' => $page, 'limit' => $limit));
         $result = $self->get(Geo::PREFIX . 'getEvents', $params);
         $resultEvents = $result['events'];
         if (!isset($resultEvents['event'])) {
             throw new NotFoundException('No events found for this location!');
         }
         $totalResults = (int) $resultEvents['@attr']['total'];
         $totalPages = (int) $resultEvents['@attr']['totalPages'];
         if (isset($resultEvents['event'][0])) {
             $events = $resultEvents['event'];
         } else {
             $events = array($resultEvents['event']);
         }
         $List = new ArrayCollection();
         foreach ($events as $eventRow) {
             $Event = new Data\Event();
             $Event->setId((int) $eventRow['id']);
             $Event->setTitle(Util::toSting($eventRow['title']));
             if (isset($eventRow['artists']['headliner'])) {
                 $Event->setHeadliner(Util::toSting($eventRow['artists']['headliner']));
             }
             $Artists = new ArrayCollection();
             if (is_array($eventRow['artists']['artist'])) {
                 $artistList = $eventRow['artists']['artist'];
             } else {
                 $artistList = array($eventRow['artists']['artist']);
             }
             foreach ($artistList as $artistName) {
                 $Artist = new Data\Artist();
                 $Artist->setName(Util::toSting($artistName));
                 $Artists->add($Artist);
             }
             $Event->setArtists($Artists);
             $Venue = new Data\Venue();
             $venueRow = $eventRow['venue'];
             $Venue->setId((int) $venueRow['id']);
             $Venue->setName(Util::toSting($venueRow['name']));
             $Venue->setCity(Util::toSting($venueRow['location']['city']));
             $Venue->setCountry(Util::toSting($venueRow['location']['country']));
             $Venue->setStreet(Util::toSting($venueRow['location']['street']));
             $Venue->setPostalcode((int) $venueRow['location']['postalcode']);
             $Venue->setLatitude((double) $venueRow['location']['geo:point']['geo:lat']);
             $Venue->setLongitude((double) $venueRow['location']['geo:point']['geo:long']);
             $Venue->setUrl(Util::toSting($venueRow['url']));
             $Venue->setWebsite(Util::toSting($venueRow['website']));
             $Venue->setPhonenumber(Util::toSting($venueRow['phonenumber']));
             $VenueImages = new ArrayCollection();
             foreach ($venueRow['image'] as $venueRowImage) {
                 $VenueImages->set(Util::toSting($venueRowImage['size']), Util::toSting($venueRowImage['#text']));
             }
             $Venue->setImages($VenueImages);
             $Event->setVenue($Venue);
             $Event->setStartDate(Util::toSting($eventRow['startDate']));
             $Event->setDescription(Util::toSting($eventRow['description']));
             $EventImages = new ArrayCollection();
             foreach ($eventRow['image'] as $image) {
                 $EventImages->set(Util::toSting($image['size']), Util::toSting($image['#text']));
             }
             $Event->setImages($EventImages);
             $Event->setAttendance((int) $eventRow['attendance']);
             $Event->setReviews((int) $eventRow['reviews']);
             $TagsList = new ArrayCollection();
             if (isset($eventRow['tags'])) {
                 if (is_array($eventRow['tags']['tag'])) {
                     $tagList = $eventRow['tags']['tag'];
                 } else {
                     $tagList = array($eventRow['tags']['tag']);
                 }
                 foreach ($tagList as $tagRow) {
                     $TagsList->add(Util::toSting($tagRow));
                 }
             }
             if (isset($eventRow['tag'])) {
                 $Event->setTag(Util::toSting($eventRow['tag']));
             }
             $Event->setTags($TagsList);
             $Event->setUrl(Util::toSting($eventRow['url']));
             $Event->setWebsite(Util::toSting($eventRow['website']));
             $Event->setCancelled((int) $eventRow['cancelled']);
             $Tickets = new ArrayCollection();
             if (is_array($eventRow['tickets'])) {
                 foreach ($eventRow['tickets']['ticket'] as $ticketRow) {
                     $Tickets->add(array('supplier' => Util::toSting($ticketRow['supplier']), 'url' => Util::toSting($ticketRow['#text'])));
                 }
             }
             $Event->setTickets($Tickets);
             $List->add($Event);
         }
         return array('results' => $List, 'total_pages' => $totalPages, 'total_results' => $totalResults);
     };
     return new PagedCollection($resultCallback);
 }
Beispiel #2
0
 /**
  * @link http://www.last.fm/api/show/event.getInfo
  *
  * @param int $eventId
  * @return \Lertify\Lastfm\Api\Data\Event\Event
  */
 public function getInfo($eventId)
 {
     $params = array('event' => $eventId);
     $result = $this->get(self::PREFIX . 'getInfo', $params);
     $resultEvent = $result['event'];
     $Event = new Data\Event\Event();
     $Event->setId((int) $resultEvent['id']);
     $Event->setTitle(Util::toSting($resultEvent['title']));
     if (isset($resultEvent['artists']['headliner'])) {
         $Event->setHeadliner(Util::toSting($resultEvent['artists']['headliner']));
     }
     $Artists = new ArrayCollection();
     if (is_array($resultEvent['artists']['artist'])) {
         $artistList = $resultEvent['artists']['artist'];
     } else {
         $artistList = array($resultEvent['artists']['artist']);
     }
     foreach ($artistList as $artistName) {
         $Artist = new Data\Artist();
         $Artist->setName(Util::toSting($artistName));
         $Artists->add($Artist);
     }
     $Event->setArtists($Artists);
     $Venue = new Data\Event\Venue();
     $venueRow = $resultEvent['venue'];
     $Venue->setId((int) $venueRow['id']);
     $Venue->setName(Util::toSting($venueRow['name']));
     $Venue->setCity(Util::toSting($venueRow['location']['city']));
     $Venue->setCountry(Util::toSting($venueRow['location']['country']));
     $Venue->setStreet(Util::toSting($venueRow['location']['street']));
     $Venue->setPostalcode((int) $venueRow['location']['postalcode']);
     $Venue->setLatitude((double) $venueRow['location']['geo:point']['geo:lat']);
     $Venue->setLongitude((double) $venueRow['location']['geo:point']['geo:long']);
     $Venue->setUrl(Util::toSting($venueRow['url']));
     $Venue->setWebsite(Util::toSting($venueRow['website']));
     $Venue->setPhonenumber(Util::toSting($venueRow['phonenumber']));
     $VenueImages = new ArrayCollection();
     foreach ($venueRow['image'] as $venueRowImage) {
         $VenueImages->set(Util::toSting($venueRowImage['size']), Util::toSting($venueRowImage['#text']));
     }
     $Venue->setImages($VenueImages);
     $Event->setVenue($Venue);
     $Event->setStartDate(Util::toSting($resultEvent['startDate']));
     $Event->setDescription(Util::toSting($resultEvent['description']));
     $EventImages = new ArrayCollection();
     foreach ($resultEvent['image'] as $image) {
         $EventImages->set(Util::toSting($image['size']), Util::toSting($image['#text']));
     }
     $Event->setImages($EventImages);
     $Event->setAttendance((int) $resultEvent['attendance']);
     $Event->setReviews((int) $resultEvent['reviews']);
     $TagsList = new ArrayCollection();
     if (isset($resultEvent['tags'])) {
         if (is_array($resultEvent['tags']['tag'])) {
             $tagList = $resultEvent['tags']['tag'];
         } else {
             $tagList = array($resultEvent['tags']['tag']);
         }
         foreach ($tagList as $tagRow) {
             $TagsList->add(Util::toSting($tagRow));
         }
     }
     if (isset($resultEvent['tag'])) {
         $Event->setTag(Util::toSting($resultEvent['tag']));
     }
     $Event->setTags($TagsList);
     $Event->setUrl(Util::toSting($resultEvent['url']));
     $Event->setWebsite(Util::toSting($resultEvent['website']));
     $Event->setCancelled((int) $resultEvent['cancelled']);
     $Tickets = new ArrayCollection();
     if (is_array($resultEvent['tickets'])) {
         foreach ($resultEvent['tickets']['ticket'] as $ticketRow) {
             $Tickets->add(array('supplier' => Util::toSting($ticketRow['supplier']), 'url' => Util::toSting($ticketRow['#text'])));
         }
     }
     $Event->setTickets($Tickets);
     return $Event;
 }