Revision 673929dd
Added by Andreas Kohlbecker over 6 years ago
modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
480 | 480 |
* an array of mimetypes in their order of preference. e.g: |
481 | 481 |
* array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html') |
482 | 482 |
* @param int $width |
483 |
* The width of the optimal image. If null, the method will return the representation with the biggest expanse
|
|
483 |
* The width of the optimal image. If null, the method will return the representation with the biggest expansion
|
|
484 | 484 |
* @param int $height |
485 |
* The height of the optimal image. If null, the method will return the representation with the biggest expanse
|
|
485 |
* The height of the optimal image. If null, the method will return the representation with the biggest expansion
|
|
486 | 486 |
* |
487 | 487 |
* @return array |
488 | 488 |
* An array with preferred media representations or else an empty array. |
... | ... | |
509 | 509 |
// Preferred mimetype found -> erase all remaining mimetypes |
510 | 510 |
// to end loop. |
511 | 511 |
$mimeTypes = array(); |
512 |
$expanseDeltaSum = 0;
|
|
512 |
$expansionDeltaSum = 0;
|
|
513 | 513 |
$valid_parts_cnt = 0; |
514 | 514 |
// Look for part with the best matching size. |
515 | 515 |
foreach ($representation->parts as $part) { |
... | ... | |
518 | 518 |
continue; |
519 | 519 |
} |
520 | 520 |
$valid_parts_cnt++; |
521 |
$expanseDelta = PHP_INT_MAX; // biggest delta for unkown sizes
|
|
521 |
$expansionDelta = PHP_INT_MAX; // biggest delta for unkown sizes
|
|
522 | 522 |
|
523 | 523 |
// determine the optimal size |
524 | 524 |
if (isset($part->width) && isset($part->height)) { |
525 |
$expanse = $part->width * $part->height;
|
|
525 |
$expansion = $part->width * $part->height;
|
|
526 | 526 |
if ($width != null && $height != null) { |
527 |
$optimalExpanse = $height * $width;
|
|
527 |
$optimalExpansion = $height * $width;
|
|
528 | 528 |
} else { |
529 |
$optimalExpanse = PHP_INT_MAX;
|
|
529 |
$optimalExpansion = PHP_INT_MAX;
|
|
530 | 530 |
} |
531 | 531 |
// determine the difference |
532 |
$expanseDelta = $expanse > $optimalExpanse ? $expanse - $optimalExpanse : $optimalExpanse - $expanse;
|
|
532 |
$expansionDelta = $expansion > $optimalExpansion ? $expansion - $optimalExpansion : $optimalExpansion - $expansion;
|
|
533 | 533 |
} |
534 |
// sum up the expanseDeltas of all parts contained in the representation
|
|
535 |
$expanseDeltaSum += $expanseDelta;
|
|
534 |
// sum up the expansionDeltas of all parts contained in the representation
|
|
535 |
$expansionDeltaSum += $expansionDelta;
|
|
536 | 536 |
} |
537 | 537 |
if($valid_parts_cnt > 0){ |
538 |
$expanseDeltaSum = $expanseDeltaSum / $valid_parts_cnt;
|
|
539 |
$prefRepr[$expanseDeltaSum . '_'] = $representation;
|
|
538 |
$expansionDeltaSum = $expansionDeltaSum / $valid_parts_cnt;
|
|
539 |
$prefRepr[$expansionDeltaSum] = $representation;
|
|
540 | 540 |
} |
541 | 541 |
} |
542 | 542 |
} |
Also available in: Unified diff
ref #6969 fixing bug in preferred media calculation