/** * @param array $params * @throws \Lertify\Lastfm\Exception\NotFoundException * @return \Lertify\Lastfm\Api\Data\PagedCollection */ private function fetchEvents(array $params) { $self = $this; $resultCallback = function ($page, $limit) use($params, $self) { $params = array_merge($params, array('page' => $page, 'limit' => $limit)); /** @var $self Artist */ $result = $self->get(Artist::PREFIX . 'getEvents', $params); $resultEvents = $result['events']; if (!isset($resultEvents['event'])) { throw new NotFoundException('No events found for this artist!'); } $List = new ArrayCollection(); $totalResults = (int) $resultEvents['@attr']['total']; $totalPages = (int) $resultEvents['@attr']['totalPages']; foreach ($resultEvents['event'] as $eventRow) { $Event = new 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(); $Artist->setName(Util::toSting($artistName)); $Artists->add($Artist); } $Event->setArtists($Artists); $Venue = new 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 $eventImage) { $EventImages->set(Util::toSting($eventImage['size']), Util::toSting($eventImage['#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); }