/**
 * Returns text describing dimensions of object representation
 *
 * @param DbResult or ca_object_representations instance $po_rep An object containing representation data. Can be either a DbResult object (ie. a query result) or ca_object_representations instance (an instance representing a row in the ca_object_representation class)
 * @param string $ps_version the name of the media version to return dimensions information for
 * @param array $pa_options Array of options, including:
 *		returnAsArray = if set an array with elements of the dimensions display text is returned
 * @return mixed Text ready for display describing dimensions of the representation's media. Can be array if 'returnAsArray' option is set.
 */
function caGetRepresentationDimensionsForDisplay($po_rep, $ps_version, $pa_options = null)
{
    $va_tmp = $po_rep->getMediaInfo('media', $ps_version);
    $va_dimensions = array();
    if (isset($va_tmp['WIDTH']) && isset($va_tmp['HEIGHT'])) {
        if (($vn_w = $va_tmp['WIDTH']) && ($vn_h = $va_tmp['HEIGHT'])) {
            $va_dimensions[] = $va_tmp['WIDTH'] . 'p x ' . $va_tmp['HEIGHT'] . 'p';
        }
    }
    if (isset($va_tmp['PROPERTIES']['bitdepth']) && ($vn_depth = $va_tmp['PROPERTIES']['bitdepth'])) {
        $va_dimensions[] = intval($vn_depth) . ' bpp';
    }
    if (isset($va_tmp['PROPERTIES']['colorspace']) && ($vs_colorspace = $va_tmp['PROPERTIES']['colorspace'])) {
        $va_dimensions[] = $vs_colorspace;
    }
    if (isset($va_tmp['PROPERTIES']['resolution']) && is_array($va_resolution = $va_tmp['PROPERTIES']['resolution'])) {
        if (isset($va_resolution['x']) && isset($va_resolution['y']) && $va_resolution['x'] && $va_resolution['y']) {
            // TODO: units for resolution? right now assume pixels per inch
            if ($va_resolution['x'] == $va_resolution['y']) {
                $va_dimensions[] = $va_resolution['x'] . 'ppi';
            } else {
                $va_dimensions[] = $va_resolution['x'] . 'x' . $va_resolution['y'] . 'ppi';
            }
        }
    }
    if (isset($va_tmp['PROPERTIES']['duration']) && ($vn_duration = $va_tmp['PROPERTIES']['duration'])) {
        $va_dimensions[] = caFormatInterval($vn_duration);
    }
    if (isset($va_tmp['PROPERTIES']['pages']) && ($vn_pages = $va_tmp['PROPERTIES']['pages'])) {
        $va_dimensions[] = $vn_pages . ' ' . ($vn_pages == 1 ? _t('page') : _t('pages'));
    }
    if (!isset($va_tmp['PROPERTIES']['filesize']) || !($vn_filesize = $va_tmp['PROPERTIES']['filesize'])) {
        $vn_filesize = @filesize($po_rep->getMediaPath('media', $ps_version));
    }
    if ($vn_filesize) {
        $va_dimensions[] = caFormatFileSize($vn_filesize);
    }
    if (isset($pa_options['returnAsArray']) && $pa_options['returnAsArray']) {
        return $va_dimensions;
    }
    return join('; ', $va_dimensions);
}
 /**
  * Returns list of caption/subtitle files attached to a representation
  * The return value is an array key'ed on the caption_id; array values are arrays
  * with keys set to values for each file returned. They keys are:
  *		path = The absolute file path to the file
  *		url = The URL for the file
  *		caption_id = a unique identifier for each attached caption file
  *
  * @param int $pn_representation_id The representation_id of the representation to return files for. If omitted the currently loaded representation is used. If no representation_id is specified and no row is loaded null will be returned.
  * @param array $pa_locale_ids 
  * @param array $pa_options
  * @return array A list of caption files attached to the representations. If no files are associated an empty array is returned.
  */
 public function getCaptionFileList($pn_representation_id = null, $pa_locale_ids = null, $pa_options = null)
 {
     if (!($vn_representation_id = $pn_representation_id)) {
         if (!($vn_representation_id = $this->getPrimaryKey())) {
             return null;
         }
     }
     $t_locale = new ca_locales();
     $va_locale_ids = array();
     if ($pa_locale_ids) {
         if (!is_array($pa_locale_ids)) {
             $pa_locale_ids = array($pa_locale_ids);
         }
         foreach ($pa_locale_ids as $vn_i => $vm_locale) {
             if (is_numeric($vm_locale) && (int) $vm_locale) {
                 $va_locale_ids[] = (int) $vm_locale;
             } else {
                 if ($vn_locale_id = $t_locale->localeCodeToID($vm_locale)) {
                     $va_locale_ids[] = $vn_locale_id;
                 }
             }
         }
     }
     $vs_locale_sql = '';
     $va_params = array((int) $vn_representation_id);
     if (sizeof($va_locale_ids) > 0) {
         $vs_locale_sql = " AND locale_id IN (?)";
         $va_params[] = $va_locale_ids;
     }
     $o_db = $this->getDb();
     $qr_res = $o_db->query("\n \t\t\tSELECT *\n \t\t\tFROM ca_object_representation_captions\n \t\t\tWHERE\n \t\t\t\trepresentation_id = ?\n \t\t\t{$vs_locale_sql}\n \t\t", $va_params);
     $va_files = array();
     while ($qr_res->nextRow()) {
         $vn_caption_id = $qr_res->get('caption_id');
         $vn_locale_id = $qr_res->get('locale_id');
         $va_files[$vn_caption_id] = $qr_res->getRow();
         unset($va_files[$vn_caption_id]['caption_file']);
         $va_files[$vn_caption_id]['path'] = $qr_res->getFilePath('caption_file');
         $va_files[$vn_caption_id]['url'] = $qr_res->getFileUrl('caption_file');
         $va_files[$vn_caption_id]['filesize'] = caFormatFileSize(filesize($va_files[$vn_caption_id]['path']));
         $va_files[$vn_caption_id]['caption_id'] = $vn_caption_id;
         $va_files[$vn_caption_id]['locale_id'] = $vn_locale_id;
         $va_files[$vn_caption_id]['locale'] = $t_locale->localeIDToName($vn_locale_id);
         $va_files[$vn_caption_id]['locale_code'] = $t_locale->localeIDToCode($vn_locale_id);
     }
     return $va_files;
 }