Revision 4fa6f9ba
Added by Andreas Kohlbecker almost 7 years ago
modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
477 | 477 |
* |
478 | 478 |
* @param object $media |
479 | 479 |
* @param array $mimeTypes |
480 |
* an array of mimetypes in their order of preference. e.g: |
|
481 |
* array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html') |
|
480 | 482 |
* @param int $width |
483 |
* The width of the optimal image. If null, the method will return the representation with the biggest expanse |
|
481 | 484 |
* @param int $height |
485 |
* The height of the optimal image. If null, the method will return the representation with the biggest expanse |
|
482 | 486 |
* |
483 | 487 |
* @return array |
484 | 488 |
* An array with preferred media representations or else an empty array. |
... | ... | |
505 | 509 |
// Preferred mimetype found -> erase all remaining mimetypes |
506 | 510 |
// to end loop. |
507 | 511 |
$mimeTypes = array(); |
508 |
$dwa = 0; |
|
509 |
$dw = 0; |
|
512 |
$expanseDeltaSum = 0; |
|
510 | 513 |
$valid_parts_cnt = 0; |
511 | 514 |
// Look for part with the best matching size. |
512 | 515 |
foreach ($representation->parts as $part) { |
513 |
if(empty($part->uri)){
|
|
516 |
if (empty($part->uri)) {
|
|
514 | 517 |
// skip part if URI is missing |
515 | 518 |
continue; |
516 | 519 |
} |
517 | 520 |
$valid_parts_cnt++; |
521 |
$expanseDelta = PHP_INT_MAX; // biggest delta for unkown sizes |
|
522 |
|
|
523 |
// determine the optimal size |
|
518 | 524 |
if (isset($part->width) && isset($part->height)) { |
519 |
$dw = $part->width * $part->height - $height * $width; |
|
520 |
} |
|
521 |
if ($dw < 0) { |
|
522 |
$dw *= -1; |
|
525 |
$expanse = $part->width * $part->height; |
|
526 |
if ($width != null && $height != null) { |
|
527 |
$optimalExpanse = $height * $width; |
|
528 |
} else { |
|
529 |
$optimalExpanse = PHP_INT_MAX; |
|
530 |
} |
|
531 |
// determine the difference |
|
532 |
$expanseDelta = $expanse > $optimalExpanse ? $expanse - $optimalExpanse : $optimalExpanse - $expanse; |
|
523 | 533 |
} |
524 |
$dwa += $dw; |
|
534 |
// sum up the expanseDeltas of all parts contained in the representation |
|
535 |
$expanseDeltaSum += $expanseDelta; |
|
525 | 536 |
} |
526 | 537 |
if($valid_parts_cnt > 0){ |
527 |
$dwa = $dwa / $valid_parts_cnt;
|
|
528 |
$prefRepr[$dwa . '_'] = $representation;
|
|
538 |
$expanseDeltaSum = $expanseDeltaSum / $valid_parts_cnt;
|
|
539 |
$prefRepr[$expanseDeltaSum . '_'] = $representation;
|
|
529 | 540 |
} |
530 | 541 |
} |
531 | 542 |
} |
532 | 543 |
} |
533 |
// Sort the array.
|
|
534 |
krsort($prefRepr);
|
|
544 |
// Sort the array so that the smallest key value is the first in the array
|
|
545 |
ksort($prefRepr); |
|
535 | 546 |
return $prefRepr; |
536 | 547 |
} |
537 | 548 |
|
Also available in: Unified diff
fix #6683 using cdm_preferred_media_representations for image viewer and fixing bugs in that method