Permalink
Newer
Older
100644 153 lines (135 sloc) 2.98 KB
Dec 3, 2008
1
<?
2
3
/** Represents some kind of media and provides common information.
4
*
5
* @package php-lastfm-api
6
* @author Felix Bruns <felixbruns@web.de>
7
* @version 1.0
8
*/
Dec 3, 2008
9
class Media {
10
/** Name of this medium.
11
*
12
* @var string
Dec 3, 2008
15
private $name;
17
/** MusicBrainz ID of this medium.
18
*
19
* @var string
Dec 3, 2008
22
private $mbid;
24
/** Last.fm URL of this medium.
25
*
26
* @var string
Dec 3, 2008
29
private $url;
31
/** An array of images of this medium.
32
*
33
* @var array
Dec 3, 2008
36
private $images;
38
/** Number of listeners of this medium.
39
*
40
* @var integer
Dec 3, 2008
43
private $listeners;
45
/** Play count of this medium.
46
*
47
* @var integer
Dec 3, 2008
50
private $playCount;
52
/** Possible image sizes.
53
*
54
* @var integer
56
*/
57
const IMAGE_UNKNOWN = -1;
58
const IMAGE_SMALL = 0;
59
const IMAGE_MEDIUM = 1;
60
const IMAGE_LARGE = 2;
61
const IMAGE_HUGE = 3;
62
const IMAGE_EXTRALARGE = 4;
63
const IMAGE_ORIGINAL = 5;
65
/** Create a media object.
66
*
67
* @param string $name Name for this medium.
68
* @param string $mbid MusicBrainz ID for this medium.
69
* @param string $url Last.fm URL for this medium.
70
* @param array $images An array of images of different sizes.
71
* @param integer $listeners Number of listeners for this medium.
72
* @param integer $playCount Play count of this medium.
73
*
74
* @access public
Dec 3, 2008
76
public function __construct($name, $mbid, $url, array $images, $listeners,
77
$playCount){
78
$this->name = $name;
79
$this->mbid = $mbid;
80
$this->url = $url;
81
$this->images = $images;
82
$this->listeners = $listeners;
83
$this->playCount = $playCount;
84
}
86
/** Returns the name of this medium.
88
* @return string The mediums name.
Dec 3, 2008
91
public function getName(){
92
return $this->name;
93
}
95
/** Returns the MusicBrainz ID of this medium.
97
* @return string MusicBrainz ID.
Dec 3, 2008
100
public function getMbid(){
101
return $this->mbid;
102
}
103
104
/** Returns the last.fm URL of this medium.
105
*
106
* @return string Last.fm URL.
Dec 3, 2008
109
public function getUrl(){
110
return $this->url;
111
}
113
/** Returns an image URL of the specified size of this medium.
115
* @param integer $size Image size constant. (Optional)
116
* @return string An image URL.
119
public function getImage($size = null){
120
if($size != null){
121
return $this->images[$size];
122
}
123
124
for($size = Media::IMAGE_ORIGINAL; $size > Media::IMAGE_UNKNOWN; $size--){
125
if(array_key_exists($size, $this->images)){
126
return $this->images[$size];
127
}
128
}
129
130
return null;
Dec 3, 2008
131
}
133
/** Returns the number of listeners of this medium.
135
* @return integer Number of listeners.
Dec 3, 2008
138
public function getListeners(){
139
return $this->listeners;
140
}
142
/** Returns the play count of this medium.
144
* @return integer Play count.
Dec 3, 2008
147
public function getPlayCount(){
148
return $this->playCount;
149
}
150
}
151
152
?>