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 |
|
modules/cdm_dataportal/theme/cdm_dataportal.page.theme | ||
---|---|---|
561 | 561 |
$mediarepresentation_uuid = $variables['mediarepresentation_uuid']; |
562 | 562 |
$partId = $variables['partId']; |
563 | 563 |
$out = ''; |
564 |
// Determine which representation and which part to show. |
|
564 |
|
|
565 |
// Determine which representation and which part to show |
|
565 | 566 |
$representationIdx = 0; |
566 |
if ($mediarepresentation_uuid) { |
|
567 |
$p_i = 0; |
|
568 |
foreach ($media->representations as $representation) { |
|
569 |
if ($representation->uuid == $mediarepresentation_uuid) { |
|
570 |
$representationIdx = $p_i; |
|
571 |
} |
|
572 |
$p_i++; |
|
567 |
|
|
568 |
if (!$mediarepresentation_uuid) { |
|
569 |
$representations = cdm_preferred_media_representations($media, array('image/png', 'image/jpeg', 'image/gif'), null, null); |
|
570 |
$mediarepresentation_uuid = isset($representations[0]) ? $representations[0]->uuid : null; |
|
571 |
} |
|
572 |
|
|
573 |
$p_i = 0; |
|
574 |
foreach ($media->representations as $representation) { |
|
575 |
if ($representation->uuid == $mediarepresentation_uuid) { |
|
576 |
$representationIdx = $p_i; |
|
573 | 577 |
} |
578 |
$p_i++; |
|
574 | 579 |
} |
575 | 580 |
|
581 |
|
|
576 | 582 |
$partIdx = 0; |
577 | 583 |
if (!is_numeric($partId)) { |
578 | 584 |
// Assuming it is an uuid. |
Also available in: Unified diff
fix #6683 using cdm_preferred_media_representations for image viewer and fixing bugs in that method