Changeset 25504


Ignore:
Timestamp:
11/17/13 11:10:05 (6 years ago)
Author:
mistic100
Message:

add DerivativeImage::get_one method working like DerivateImage::get_all but returning only one size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/derivative.inc.php

    r20516 r25504  
    193193 
    194194  /** 
    195   @return an associative array of derivative images with keys all standard derivative image types: 
    196   Disabled derivative types can be still found in the return mapped to an enabled derivative (e.g. the values are not 
    197   unique in the return array). This is useful for any plugin/theme to just use $deriv[IMG_XLARGE] even if the XLARGE is 
    198   disabled. 
    199   */ 
     195   * Return associative an array of all DerivativeImage for a specific image. 
     196   * Disabled derivative types can be still found in the return mapped to an 
     197   * enabled derivative (e.g. the values are not unique in the return array). 
     198   * This is useful for any plugin/theme to just use $deriv[IMG_XLARGE] even if  
     199   * the XLARGE is disabled. 
     200   * 
     201   * @param array|SrcImage $src_image array of info from db or SrcImage 
     202   * @return DerivativeImage[] 
     203   */ 
    200204  static function get_all($src_image) 
    201205  { 
     206    if (!is_object($src_image)) 
     207    { 
     208      $src_image = new SrcImage($src_image); 
     209    } 
     210 
    202211    $ret = array(); 
    203212    // build enabled types 
     
    207216      $ret[$type] = $derivative; 
    208217    } 
    209     // disabled types fqllbqck to enqbled types 
     218    // disabled types, fallback to enabled types 
    210219    foreach (ImageStdParams::get_undefined_type_map() as $type => $type2) 
    211220    { 
     
    214223 
    215224    return $ret; 
     225  } 
     226 
     227  /** 
     228   * Returns an instance of DerivativeImage for a specific image and size. 
     229   * Disabled derivatives fallback to an enabled derivative. 
     230   * 
     231   * @param string $type 
     232   * @param array|SrcImage $src_image array of info from db or SrcImage 
     233   * @return DerivativeImage|null null if $type not found 
     234   */ 
     235  static function get_one($type, $src_image) 
     236  { 
     237    if (!is_object($src_image)) 
     238    { 
     239      $src_image = new SrcImage($src_image); 
     240    } 
     241 
     242    $defined = ImageStdParams::get_defined_type_map(); 
     243    if (isset($defined[$type])) 
     244    { 
     245      return new DerivativeImage($defined[$type], $src_image); 
     246    } 
     247 
     248    $undefined = ImageStdParams::get_undefined_type_map(); 
     249    if (isset($undefined[$type])) 
     250    { 
     251      return new DerivativeImage($defined[ $undefined[$type] ], $src_image); 
     252    } 
     253 
     254    return null; 
    216255  } 
    217256 
Note: See TracChangeset for help on using the changeset viewer.