Example #1
0
 /**
  * @link http://www.last.fm/api/show/user.getEvents
  *
  * @param string $user
  * @param bool $festivalsOnly
  * @throws \Lertify\Lastfm\Exception\NotFoundException
  * @return \Lertify\Lastfm\Api\Data\PagedCollection
  */
 public function getEvents($user, $festivalsOnly = true)
 {
     $params = array('user' => $user, 'festivalsonly' => $festivalsOnly);
     $self = $this;
     $resultCallback = function ($page, $limit) use($params, $self) {
         $params = array_merge($params, array('page' => $page, 'limit' => $limit));
         $result = $self->get(User::PREFIX . 'getEvents', $params);
         $resultEvents = $result['events'];
         if (!isset($resultEvents['event'])) {
             throw new NotFoundException('This user isn\'t signed up for any events!');
         }
         if (isset($resultEvents['event'][0]) && is_array($resultEvents['event'][0])) {
             $events = $resultEvents['event'];
         } else {
             $events = array($resultEvents['event']);
         }
         $totalPages = (int) $resultEvents['@attr']['totalPages'];
         $total = (int) $resultEvents['@attr']['total'];
         $List = new ArrayCollection();
         foreach ($events as $eventRow) {
             $ArtistsList = new ArrayCollection();
             foreach ($eventRow['artists']['artist'] as $artistRow) {
                 $Artist = new UserData\Artist();
                 $Artist->setName((string) $artistRow);
                 $ArtistsList->add($Artist);
             }
             $Headliner = new UserData\Artist();
             $Headliner->setName((string) $eventRow['artists']['headliner']);
             $Venue = new UserData\Venue();
             $Venue->setId((int) $eventRow['venue']['id'])->setName((string) $eventRow['venue']['name'])->setLatitude((double) $eventRow['venue']['location']['geo:point']['geo:lat'])->setLongitude((double) $eventRow['venue']['location']['geo:point']['geo:long'])->setCity((string) $eventRow['venue']['location']['city'])->setCountry((string) $eventRow['venue']['location']['country'])->setStreet((string) $eventRow['venue']['location']['street'])->setPostalcode((int) $eventRow['venue']['location']['postalcode'])->setUrl((string) $eventRow['venue']['url'])->setWebsite((string) $eventRow['venue']['website'])->setPhonenumber((string) $eventRow['venue']['phonenumber']);
             if (isset($eventRow['venue']['image'])) {
                 $Venue->setImages($self->getImageList($eventRow['venue']['image']));
             }
             $Tags = new ArrayCollection();
             if (isset($eventRow['tags']['tag'])) {
                 foreach ($eventRow['tags']['tag'] as $tagRow) {
                     $Tag = new UserData\Tag();
                     $Tag->setName((string) $tagRow);
                     $Tags->add($Tag);
                 }
             }
             $Event = new UserData\Event();
             $Event->setId((int) $eventRow['id'])->setTitle((string) $eventRow['title'])->setStartDate(new DateTime((string) $eventRow['startDate']))->setDescription((string) $eventRow['description'])->setAttendance((int) $eventRow['attendance'])->setReviews((int) $eventRow['reviews'])->setTag((string) $eventRow['tag'])->setUrl((string) $eventRow['url'])->setWebsite((string) $eventRow['website'])->setCancelled((int) $eventRow['cancelled'])->setArtists($ArtistsList)->setHeadliner($Headliner)->setVenue($Venue)->setTags($Tags);
             if (isset($eventRow['image'])) {
                 $Event->setImages($self->getImageList($eventRow['image']));
             }
             $List->add($Event);
         }
         return array('results' => $List, 'total_pages' => $totalPages, 'total_results' => $total);
     };
     return new PagedCollection($resultCallback);
 }