本文整理汇总了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;
}
示例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;
}