Skip to content

Commit 247fdde

Browse files
author
Matt Oakes
committed
Added phpdoc comments
1 parent c680df9 commit 247fdde

File tree

1 file changed

+86
-34
lines changed

1 file changed

+86
-34
lines changed

lastfmapi/api/album.php

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
11
<?php
2-
3-
class lastfmApiAlbum extends lastfmApiBase {
4-
public $info;
5-
public $tags;
2+
/**
3+
* File that stores api calls for album api calls
4+
* @package album
5+
*/
6+
/**
7+
* Allows access to the api requests relating to albums
8+
* @package album
9+
*/
10+
class lastfmApiAlbum extends lastfmApi {
11+
/**
12+
* Stores the config values set in the call
13+
* @access public
14+
* @var array
15+
*/
616
public $config;
7-
17+
/**
18+
* Stores the auth variables used in all api calls
19+
* @access private
20+
* @var array
21+
*/
822
private $auth;
23+
/**
24+
* States if the user has full authentication to use api requests that modify data
25+
* @access private
26+
* @var boolean
27+
*/
928
private $fullAuth;
1029

30+
/**
31+
* @param array $auth Passes the authentication variables
32+
* @param array $fullAuth A boolean value stating if the user has full authentication or not
33+
* @param array $config An array of config variables related to caching and other features
34+
*/
1135
function __construct($auth, $fullAuth, $config) {
1236
$this->auth = $auth;
1337
$this->fullAuth = $fullAuth;
1438
$this->config = $config;
1539
}
1640

41+
/**
42+
* Tag an album using a list of user supplied tags. (Requires full auth)
43+
* @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>, <i>tags</i>
44+
* @return boolean
45+
*/
1746
public function addTags($methodVars) {
1847
// Only allow full authed calls
1948
if ( $this->fullAuth == TRUE ) {
@@ -67,6 +96,11 @@ public function addTags($methodVars) {
6796
}
6897
}
6998

99+
/**
100+
* Get the metadata for an album on Last.fm using the album name or a musicbrainz id
101+
* @param array $methodVars An array with the following required values: <i>album</i> and optional values: <i>artist</i>, <i>mbid</i>
102+
* @return array
103+
*/
70104
public function getInfo($methodVars) {
71105
// Set the call variables
72106
$vars = array(
@@ -76,33 +110,39 @@ public function getInfo($methodVars) {
76110
'artist' => @$methodVars['artist'],
77111
'mbid' => @$methodVars['mbid']
78112
);
113+
$info = array();
79114

80115
if ( $call = $this->apiGetCall($vars) ) {
81-
$this->info['name'] = (string) $call->album->name;
82-
$this->info['artist'] = (string) $call->album->artist;
83-
$this->info['lastfmid'] = (string) $call->album->id;
84-
$this->info['mbid'] = (string) $call->album->mbid;
85-
$this->info['url'] = (string) $call->album->url;
86-
$this->info['releasedate'] = strtotime(trim((string) $call->album->releasedate));
87-
$this->info['image']['small'] = (string) $call->album->image;
88-
$this->info['image']['medium'] = (string) $call->album->image[1];
89-
$this->info['image']['large'] = (string) $call->album->image[2];
90-
$this->info['listeners'] = (string) $call->album->listeners;
91-
$this->info['playcount'] = (string) $call->album->playcount;
116+
$info['name'] = (string) $call->album->name;
117+
$info['artist'] = (string) $call->album->artist;
118+
$info['lastfmid'] = (string) $call->album->id;
119+
$info['mbid'] = (string) $call->album->mbid;
120+
$info['url'] = (string) $call->album->url;
121+
$info['releasedate'] = strtotime(trim((string) $call->album->releasedate));
122+
$info['image']['small'] = (string) $call->album->image;
123+
$info['image']['medium'] = (string) $call->album->image[1];
124+
$info['image']['large'] = (string) $call->album->image[2];
125+
$info['listeners'] = (string) $call->album->listeners;
126+
$info['playcount'] = (string) $call->album->playcount;
92127
$i = 0;
93128
foreach ( $call->album->toptags->tag as $tags ) {
94-
$this->info['toptags'][$i]['name'] = (string) $tags->name;
95-
$this->info['toptags'][$i]['url'] = (string) $tags->url;
129+
$info['toptags'][$i]['name'] = (string) $tags->name;
130+
$info['toptags'][$i]['url'] = (string) $tags->url;
96131
$i++;
97132
}
98133

99-
return $this->info;
134+
return $info;
100135
}
101136
else {
102137
return FALSE;
103138
}
104139
}
105140

141+
/**
142+
* Get the tags applied by an individual user to an album on Last.fm
143+
* @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>
144+
* @return array
145+
*/
106146
public function getTags($methodVars) {
107147
// Only allow full authed calls
108148
if ( $this->fullAuth == TRUE ) {
@@ -119,18 +159,19 @@ public function getTags($methodVars) {
119159
// Generate a call signiture
120160
$sig = $this->apiSig($this->auth->secret, $vars);
121161
$vars['api_sig'] = $sig;
162+
$tags = array();
122163

123164
// Make the call
124165
if ( $call = $this->apiGetCall($vars) ) {
125166
if ( count($call->tags->tag) > 0 ) {
126167
$i = 0;
127168
foreach ( $call->tags->tag as $tag ) {
128-
$this->tags[$i]['name'] = (string) $tag->name;
129-
$this->tags[$i]['url'] = (string) $tag->url;
169+
$tags[$i]['name'] = (string) $tag->name;
170+
$tags[$i]['url'] = (string) $tag->url;
130171
$i++;
131172
}
132173

133-
return $this->tags;
174+
return $tags;
134175
}
135176
else {
136177
$this->handleError(90, 'User has no tags for this artist');
@@ -154,6 +195,11 @@ public function getTags($methodVars) {
154195
}
155196
}
156197

198+
/**
199+
* Remove a user's tag from an album. (Requires full auth)
200+
* @param array $methodVars An array with the following required values: <i>album</i>, <i>artist</i>, <i>tag</i>
201+
* @return boolean
202+
*/
157203
public function removeTag($methodVars) {
158204
// Only allow full authed calls
159205
if ( $this->fullAuth == TRUE ) {
@@ -193,6 +239,11 @@ public function removeTag($methodVars) {
193239
}
194240
}
195241

242+
/**
243+
* Search for an album by name. Returns album matches sorted by relevance
244+
* @param array $methodVars An array with the following required values: <i>album</i>
245+
* @return array
246+
*/
196247
public function search($methodVars) {
197248
// Check for required variables
198249
if ( !empty($methodVars['album']) ) {
@@ -207,27 +258,28 @@ public function search($methodVars) {
207258
if ( !empty($methodVars['page']) ) {
208259
$vars['page'] = $methodVars['page'];
209260
}
261+
$searchresults = array();
210262

211263
if ( $call = $this->apiGetCall($vars) ) {
212264
$opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/');
213265
if ( $opensearch->totalResults > 0 ) {
214-
$this->searchResults['totalResults'] = (string) $opensearch->totalResults;
215-
$this->searchResults['startIndex'] = (string) $opensearch->startIndex;
216-
$this->searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage;
266+
$searchresults['totalResults'] = (string) $opensearch->totalResults;
267+
$searchresults['startIndex'] = (string) $opensearch->startIndex;
268+
$searchresults['itemsPerPage'] = (string) $opensearch->itemsPerPage;
217269
$i = 0;
218270
foreach ( $call->results->albummatches->album as $album ) {
219-
$this->searchResults['results'][$i]['name'] = (string) $album->name;
220-
$this->searchResults['results'][$i]['artist'] = (string) $album->artist;
221-
$this->searchResults['results'][$i]['id'] = (string) $album->id;
222-
$this->searchResults['results'][$i]['url'] = (string) $album->url;
223-
$this->searchResults['results'][$i]['streamable'] = (string) $album->streamable;
224-
$this->searchResults['results'][$i]['image']['small'] = (string) $album->image[0];
225-
$this->searchResults['results'][$i]['image']['medium'] = (string) $album->image[1];
226-
$this->searchResults['results'][$i]['image']['large'] = (string) $album->image[2];
271+
$searchresults['results'][$i]['name'] = (string) $album->name;
272+
$searchresults['results'][$i]['artist'] = (string) $album->artist;
273+
$searchresults['results'][$i]['id'] = (string) $album->id;
274+
$searchresults['results'][$i]['url'] = (string) $album->url;
275+
$searchresults['results'][$i]['streamable'] = (string) $album->streamable;
276+
$searchresults['results'][$i]['image']['small'] = (string) $album->image[0];
277+
$searchresults['results'][$i]['image']['medium'] = (string) $album->image[1];
278+
$searchresults['results'][$i]['image']['large'] = (string) $album->image[2];
227279
$i++;
228280
}
229281

230-
return $this->searchResults;
282+
return $searchresults;
231283
}
232284
else {
233285
// No tagsare found

0 commit comments

Comments
 (0)