Пример #1
0
 /**
  * Extract Album informations from object
  * @access public
  * @static
  * @param  \stdClass $album Object represent Album
  * @return Album
  */
 public static function extractInfos($album)
 {
     // create Album instance
     $albumItem = new self();
     // update informations
     $albumItem->setUri((string) isset($album->href) ? $album->href : '');
     $albumItem->setName((string) isset($album->name) ? $album->name : '');
     // is popularity available ?
     if (isset($album->popularity)) {
         // update popularity
         $albumItem->setPopularity((double) $album->popularity);
     }
     // is released date available ?
     if (isset($album->released)) {
         // update released dates
         $albumItem->setReleased((string) $album->released);
     }
     // is teritories availabality available ?
     if (isset($album->availability) && isset($album->availability->territories)) {
         // update territories availability
         $albumItem->setTerritories(explode(' ', $album->availability->territories));
     }
     // is artists available (from search service) ?
     if (isset($album->artists) && is_array($album->artists)) {
         // setup artists container
         $artists = array();
         // iterate artists
         foreach ($album->artists as $artist) {
             // create Artist and store on container
             $artists[] = Artist::extractInfos($artist);
         }
         // set artists of album
         $albumItem->setArtists($artists);
     }
     // is artists available (from lookup service) ?
     if (isset($album->{'artist-id'}) && isset($album->artist)) {
         // create and store principal artist
         $albumItem->setArtist(Artist::build($album->{'artist-id'}, $album->artist));
     }
     // is tracks available ?
     if (isset($album->tracks) && is_array($album->tracks)) {
         // setup tracks container
         $tracks = array();
         // iterate external ids
         foreach ($album->tracks as $track) {
             // create Track and store on container
             $tracks[] = Track::extractInfos($track);
         }
         // set albums tracks
         $albumItem->setTracks($tracks);
     }
     // is external ids available ?
     if (isset($album->{'external-ids'}) && is_array($album->{'external-ids'})) {
         // setup external ids container
         $externalIds = array();
         // iterate external ids
         foreach ($album->{'external-ids'} as $externalId) {
             // create ExternalId and store on container
             $externalIds[] = ExternalId::extractInfos($externalId);
         }
         // set external ids of album
         $albumItem->setExternalIds($externalIds);
     }
     // return album instance
     return $albumItem;
 }