当前位置: 首页>>代码示例>>PHP>>正文


PHP Album::structureData方法代码示例

本文整理汇总了PHP中Album::structureData方法的典型用法代码示例。如果您正苦于以下问题:PHP Album::structureData方法的具体用法?PHP Album::structureData怎么用?PHP Album::structureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Album的用法示例。


在下文中一共展示了Album::structureData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: searchAlbumByTitle

 /**
  * Search an album by his title.
  *
  * @param string $albumTitle
  *
  * @return bool|array Albums collection or false on failure
  */
 public function searchAlbumByTitle($albumTitle)
 {
     //set valid request
     $this->endpoint .= '2/release/';
     $this->queryParameters['query'] = "release:{$albumTitle};";
     //execute the request
     $response = $this->executeCall();
     if ($response === false) {
         //error on response
         return false;
     }
     if ($response->count === 0) {
         $this->errorMessage = 'No album found';
         //no release matched
         return array();
     }
     //order by score
     $musicBrainzReleases = $response->releases;
     usort($musicBrainzReleases, array('MusicBrainz', 'orderByScore'));
     //get high score and apply a 90% ratio
     $thresholdScore = $musicBrainzReleases[0]->score * 0.9;
     $albums = array();
     //transform MusicBrainz albums into WMP albums
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Album.php';
     foreach ($musicBrainzReleases as $musicBrainzRelease) {
         if ($musicBrainzRelease->score >= $thresholdScore) {
             $album = new Album();
             $album->mbid = $musicBrainzRelease->id;
             $album->name = $musicBrainzRelease->title;
             if (property_exists($musicBrainzRelease, 'date')) {
                 $album->year = substr($musicBrainzRelease->date, 0, 4);
             }
             if (property_exists($musicBrainzRelease, 'country')) {
                 $album->country = $musicBrainzRelease->country;
             }
             if (property_exists($musicBrainzRelease, 'artist-credit') && count($musicBrainzRelease->{'artist-credit'}) > 0) {
                 $artists = $musicBrainzRelease->{'artist-credit'};
                 $album->artistName = $artists[0]->artist->name;
             }
             $album->mbidGroup = $musicBrainzRelease->{'release-group'}->id;
             $status = '?';
             $packaging = '?';
             $type = '?';
             $media = '?';
             if (property_exists($musicBrainzRelease, 'status')) {
                 $status = $musicBrainzRelease->status;
             }
             if (property_exists($musicBrainzRelease, 'packaging')) {
                 $packaging = $musicBrainzRelease->packaging;
             }
             if (property_exists($musicBrainzRelease->{'release-group'}, 'primary-type')) {
                 $type = $musicBrainzRelease->{'release-group'}->{'primary-type'};
             }
             if (count($musicBrainzRelease->media) > 0 && property_exists($musicBrainzRelease->media[0], 'format')) {
                 $media = $musicBrainzRelease->media[0]->format;
             }
             $album->description = $type . ' - ' . $status . ' - ' . $packaging . ' - ' . $media;
             //propose a cover URL with Cover Art Archive
             require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/CoverArtArchive.php';
             $coverArtArchive = new CoverArtArchive();
             $album->coverPath = $coverArtArchive->getCoverURL($musicBrainzRelease->id);
             $album->structureData();
             unset($album->id, $album->tracks, $album->disk);
             array_push($albums, $album);
         }
     }
     //return albums
     return $albums;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:76,代码来源:MusicBrainz.php

示例2: Album

        }
        $album = new Album($id);
        if (!$album->populate(['id' => $id])) {
            $api->output(404, 'Album not found');
            //indicate the album was not found
            return;
        }
        //store previous MBID
        $previousMBID = $album->mbid;
        //adapt and validate object received
        $updatedAlbum = $api->query['body'];
        if (!$album->validateModel($updatedAlbum, $errorMessage)) {
            $api->output(400, 'Album is not valid: ' . $errorMessage);
            //provided album is not valid
            return;
        }
        if (!$album->update($errorMessage)) {
            $api->output(500, 'Error during album update' . $errorMessage);
            //something gone wrong :(
            return;
        }
        //if MBID has changed, update cover
        if ($previousMBID !== $album->mbid) {
            $album->deleteCoverImage();
            $album->getCoverImage();
        }
        $album->populate(['id' => $id]);
        $album->getTracks();
        $api->output(200, $album->structureData());
        break;
}
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:album.php


注:本文中的Album::structureData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。