Revision abd0ab13
Added by Andreas Kohlbecker almost 15 years ago
modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
235 | 235 |
* title |
236 | 236 |
* uuid 17e514f1-7a8e-4daa-87ea-8f13f8742cf9 |
237 | 237 |
* |
238 |
* @param unknown_type $mediaTO
|
|
238 |
* @param unknown_type $media |
|
239 | 239 |
* @param array $mimeTypes |
240 | 240 |
* @param unknown_type $width |
241 | 241 |
* @param unknown_type $height |
242 | 242 |
* @return unknown |
243 | 243 |
*/ |
244 |
function cdm_preferred_media_representations($mediaTO, array $mimeTypes, $width = 400, $height = 300){
|
|
244 |
function cdm_preferred_media_representations($media, array $mimeTypes, $width = 400, $height = 300){ |
|
245 | 245 |
/** |
246 | 246 |
|
247 | 247 |
* |
248 | 248 |
*/ |
249 | 249 |
$prefRepr = array(); |
250 |
if(!isset($mediaTO->representations[0])){
|
|
250 |
if(!isset($media->representations[0])){ |
|
251 | 251 |
return $prefRepr; |
252 | 252 |
} |
253 | 253 |
|
254 | 254 |
while(count($mimeTypes) > 0){ |
255 | 255 |
// getRepresentationByMimeType |
256 | 256 |
$mimeType = array_shift($mimeTypes); |
257 |
foreach($mediaTO->representations as $representationTO){
|
|
258 |
if($representationTO->mimeType == $mimeType){
|
|
257 |
foreach($media->representations as $representation){
|
|
258 |
if($representation->mimeType == $mimeType){ |
|
259 | 259 |
// preffered mimetype found -> erase all remaining mimetypes to end loop |
260 | 260 |
$mimeTypes = array(); |
261 | 261 |
$dwa = 0; |
262 | 262 |
// look for part with the best matching size |
263 |
foreach($representationTO->representationParts as $part){
|
|
263 |
foreach($representation->parts as $part){
|
|
264 | 264 |
$dw = $part->width * $part->height - $height * $width; |
265 | 265 |
if($dw < 0){ |
266 | 266 |
$dw *= -1; |
267 | 267 |
} |
268 | 268 |
$dwa+= $dw; |
269 | 269 |
} |
270 |
$dwa = (count($representationTO->representationParts)>0) ? $dwa / count($representationTO->representationParts) : 0;
|
|
271 |
$prefRepr[$dwa.'_'.$mimeTypeKey] = $representationTO;
|
|
270 |
$dwa = (count($representation->parts)>0) ? $dwa / count($representation->parts) : 0;
|
|
271 |
$prefRepr[$dwa.'_'.$mimeTypeKey] = $representation; |
|
272 | 272 |
} |
273 | 273 |
} |
274 | 274 |
} |
Also available in: Unified diff
bugfixes