/** * Returns information about representations linked to the currently loaded item. Use this if you want to get the urls, tags and other information for all representations associated with a given item. * * @param array $pa_versions An array of media versions to include information for. If you omit this then a single version, 'preview170', is assumed by default. * @param array $pa_version_sizes Optional array of sizes to force specific versions to. The array keys are version names; the values are arrays with two keys: 'width' and 'height'; if present these values will be used in lieu of the actual values in the database * @param array $pa_options An optional array of options to use when getting representation information. Supported options are: * return_primary_only - If true then only the primary representation will be returned * return_with_access - Set to an array of access values to filter representation through; only representations with an access value in the list will be returned * checkAccess - synonym for return_with_access * .. and options supported by getMediaTag() .. [they are passed through] * * @return array An array of information about the linked representations */ public function getRepresentations($pa_versions = null, $pa_version_sizes = null, $pa_options = null) { if (!($vn_id = $this->getPrimaryKey())) { return null; } if (!is_array($pa_options)) { $pa_options = array(); } if (caGetBundleAccessLevel($this->tableName(), 'ca_object_representations') == __CA_BUNDLE_ACCESS_NONE__) { return null; } if (!is_array($pa_versions)) { $pa_versions = array('preview170'); } if (isset($pa_options['return_primary_only']) && $pa_options['return_primary_only']) { $vs_is_primary_sql = ' AND (caoor.is_primary = 1)'; } else { $vs_is_primary_sql = ''; } if ($pa_options['checkAccess']) { $pa_options['return_with_access'] = $pa_options['checkAccess']; } if (is_array($pa_options['return_with_access']) && sizeof($pa_options['return_with_access']) > 0) { $vs_access_sql = ' AND (caor.access IN (' . join(", ", $pa_options['return_with_access']) . '))'; } else { $vs_access_sql = ''; } $o_db = $this->getDb(); if (!($vs_linking_table = RepresentableBaseModel::getRepresentationRelationshipTableName($this->tableName()))) { return null; } $vs_pk = $this->primaryKey(); $qr_reps = $o_db->query("\n\t\t\t\tSELECT caor.representation_id, caor.media, caoor.is_primary, caor.access, caor.status, l.name, caor.locale_id, caor.media_metadata, caor.type_id, caor.idno, caor.idno_sort, caor.md5, caor.mimetype, caor.original_filename, caoor.rank\n\t\t\t\tFROM ca_object_representations caor\n\t\t\t\tINNER JOIN {$vs_linking_table} AS caoor ON caor.representation_id = caoor.representation_id\n\t\t\t\tLEFT JOIN ca_locales AS l ON caor.locale_id = l.locale_id\n\t\t\t\tWHERE\n\t\t\t\t\tcaoor.{$vs_pk} = ? AND deleted = 0\n\t\t\t\t\t{$vs_is_primary_sql}\n\t\t\t\t\t{$vs_access_sql}\n\t\t\t\tORDER BY\n\t\t\t\t\tcaoor.rank, caoor.is_primary DESC\n\t\t\t", (int) $vn_id); $va_reps = array(); $t_rep = new ca_object_representations(); while ($qr_reps->nextRow()) { $vn_rep_id = $qr_reps->get('representation_id'); $va_tmp = $qr_reps->getRow(); $va_tmp['tags'] = array(); $va_tmp['urls'] = array(); $va_info = $qr_reps->getMediaInfo('media'); $va_tmp['info'] = array('original_filename' => $va_info['ORIGINAL_FILENAME']); foreach ($pa_versions as $vs_version) { if (is_array($pa_version_sizes) && isset($pa_version_sizes[$vs_version])) { $vn_width = $pa_version_sizes[$vs_version]['width']; $vn_height = $pa_version_sizes[$vs_version]['height']; } else { $vn_width = $vn_height = 0; } if ($vn_width && $vn_height) { $va_tmp['tags'][$vs_version] = $qr_reps->getMediaTag('media', $vs_version, array_merge($pa_options, array('viewer_width' => $vn_width, 'viewer_height' => $vn_height))); } else { $va_tmp['tags'][$vs_version] = $qr_reps->getMediaTag('media', $vs_version, $pa_options); } $va_tmp['urls'][$vs_version] = $qr_reps->getMediaUrl('media', $vs_version); $va_tmp['paths'][$vs_version] = $qr_reps->getMediaPath('media', $vs_version); $va_tmp['info'][$vs_version] = $qr_reps->getMediaInfo('media', $vs_version); $va_tmp['dimensions'][$vs_version] = caGetRepresentationDimensionsForDisplay($qr_reps, 'original', array()); } if (isset($va_info['INPUT']['FETCHED_FROM']) && ($vs_fetched_from_url = $va_info['INPUT']['FETCHED_FROM'])) { $va_tmp['fetched_from'] = $vs_fetched_from_url; $va_tmp['fetched_on'] = (int) $va_info['INPUT']['FETCHED_ON']; } $va_tmp['num_multifiles'] = $t_rep->numFiles($vn_rep_id); $va_reps[$vn_rep_id] = $va_tmp; } $va_labels = $t_rep->getPreferredDisplayLabelsForIDs(array_keys($va_reps)); foreach ($va_labels as $vn_rep_id => $vs_label) { $va_reps[$vn_rep_id]['label'] = $vs_label; } return $va_reps; }