/** * Returns number of representations attached to each item referenced by primary key in $pa_ids * * @param array $pa_ids indexed array of primary key values to fetch labels for * @param array $pa_options * @return array List of representation counts indexed by primary key */ public function getMediaCountsForIDs($pa_ids, $pa_options = null) { if (!is_array($pa_ids) || !sizeof($pa_ids)) { return array(); } if (!is_array($pa_options)) { $pa_options = array(); } $va_access_values = $pa_options["checkAccess"]; if (isset($va_access_values) && is_array($va_access_values) && sizeof($va_access_values)) { $vs_access_where = ' AND orep.access IN (' . join(',', $va_access_values) . ')'; } $o_db = $this->getDb(); if (!($vs_linking_table = RepresentableBaseModel::getRepresentationRelationshipTableName($this->tableName()))) { return null; } $vs_pk = $this->primaryKey(); $qr_res = $o_db->query("\n\t\t\t\tSELECT oxor.{$vs_pk}, count(*) c\n\t\t\t\tFROM ca_object_representations orep\n\t\t\t\tINNER JOIN {$vs_linking_table} AS oxor ON oxor.representation_id = orep.representation_id\n\t\t\t\tWHERE\n\t\t\t\t\t(oxor.{$vs_pk} IN (" . join(',', $pa_ids) . ")) AND orep.deleted = 0 {$vs_access_where}\n\t\t\t\tGROUP BY oxor.{$vs_pk}\n\t\t\t"); $va_counts = array(); while ($qr_res->nextRow()) { $va_counts[$qr_res->get($vs_pk)] = (int) $qr_res->get('c'); } return $va_counts; }
/** * Returns values for bundle. Can be used to set initial state of bundle as well as to grab partial value sets for * progressive loading of bundles. * * NOTE: Currently only support ca_object_representations bundle * */ public function getBundleFormValues($ps_bundle_name, $ps_placement_code, $pa_bundle_settings, $pa_options = null) { global $g_ui_locale; // Check if user has access to this bundle if ($pa_options['request']->user->getBundleAccessLevel($this->tableName(), $ps_bundle_name) == __CA_BUNDLE_ACCESS_NONE__) { return; } // Check if user has access to this type if ((bool) $this->getAppConfig()->get('perform_type_access_checking')) { $vn_type_access = $pa_options['request']->user->getTypeAccessLevel($this->tableName(), $this->getTypeID()); if ($vn_type_access == __CA_BUNDLE_ACCESS_NONE__) { return; } if ($vn_type_access == __CA_BUNDLE_ACCESS_READONLY__) { $pa_bundle_settings['readonly'] = true; } } // Check if user has access to this source if ((bool) $this->getAppConfig()->get('perform_source_access_checking')) { $vn_source_access = $pa_options['request']->user->getSourceAccessLevel($this->tableName(), $this->getSourceID()); if ($vn_source_access == __CA_BUNDLE_ACCESS_NONE__) { return; } if ($vn_source_access == __CA_BUNDLE_ACCESS_READONLY__) { $pa_bundle_settings['readonly'] = true; } } if ((bool) $this->getAppConfig()->get('perform_item_level_access_checking') && $this->getPrimaryKey()) { $vn_item_access = $this->checkACLAccessForUser($pa_options['request']->user); if ($vn_item_access == __CA_ACL_NO_ACCESS__) { return; } if ($vn_item_access == __CA_ACL_READONLY_ACCESS__) { $pa_bundle_settings['readonly'] = true; } } $va_info = $this->getBundleInfo($ps_bundle_name); if (!($vs_type = $va_info['type'])) { return null; } if (isset($pa_options['config']) && is_object($pa_options['config'])) { $o_config = $pa_options['config']; } else { $o_config = $this->getAppConfig(); } // start and count $pn_start = caGetOption('start', $pa_options, 0); $pn_limit = caGetOption('limit', $pa_options, null); $vs_element = ''; switch ($vs_type) { # ------------------------------------------------- case 'preferred_label': case 'nonpreferred_label': break; # ------------------------------------------------- # ------------------------------------------------- case 'intrinsic': break; # ------------------------------------------------- # ------------------------------------------------- case 'attribute': break; # ------------------------------------------------- # ------------------------------------------------- case 'related_table': switch ($ps_bundle_name) { # ------------------------------- case 'ca_object_representations': foreach (array('restrict_to_types', 'restrict_to_relationship_types') as $vs_k) { $pa_options[$vs_k] = $pa_bundle_settings[$vs_k]; } $va_reps = $this->getRepresentations(array('thumbnail', 'original'), null, $pa_options); $t_item = new ca_object_representations(); $va_rep_type_list = $t_item->getTypeList(); $va_errors = array(); $vs_bundle_template = caGetOption('display_template', $pa_bundle_settings, null); // Paging $vn_primary_id = 0; $va_initial_values = array(); if (sizeof($va_reps)) { $o_type_config = Configuration::load($t_item->getAppConfig()->get('annotation_type_config')); $va_annotation_type_mappings = $o_type_config->getAssoc('mappings'); // Get display template values $va_display_template_values = array(); if ($vs_bundle_template && is_array($va_relation_ids = caExtractValuesFromArrayList($va_reps, 'relation_id')) && sizeof($va_relation_ids)) { if ($vs_linking_table = RepresentableBaseModel::getRepresentationRelationshipTableName($this->tableName())) { $va_display_template_values = caProcessTemplateForIDs($vs_bundle_template, $vs_linking_table, $va_relation_ids, array_merge($pa_options, array('returnAsArray' => true, 'returnAllLocales' => false, 'includeBlankValuesInArray' => true))); } } $vn_i = 0; foreach ($va_reps as $va_rep) { $vn_num_multifiles = $va_rep['num_multifiles']; if ($vs_extracted_metadata = caFormatMediaMetadata(caSanitizeArray(caUnserializeForDatabase($va_rep['media_metadata'])))) { $vs_extracted_metadata = "<h3>" . _t('Extracted metadata') . ":</h3>\n{$vs_extracted_metadata}\n"; } $vs_md5 = isset($va_rep['info']['original']['MD5']) ? "<h3>" . _t('MD5 signature') . ':</h3>' . $va_rep['info']['original']['MD5'] : ''; if ($va_rep['is_primary']) { $vn_primary_id = $va_rep['representation_id']; } $va_initial_values[$va_rep['representation_id']] = array('idno' => $va_rep['idno'], '_display' => $vs_bundle_template && isset($va_display_template_values[$vn_i]) ? $va_display_template_values[$vn_i] : '', 'status' => $va_rep['status'], 'status_display' => $t_item->getChoiceListValue('status', $va_rep['status']), 'access' => $va_rep['access'], 'access_display' => $t_item->getChoiceListValue('access', $va_rep['access']), 'rep_type_id' => $va_rep['type_id'], 'rep_type' => $t_item->getTypeName($va_rep['type_id']), 'rep_label' => $va_rep['label'], 'is_primary' => (int) $va_rep['is_primary'], 'is_primary_display' => $va_rep['is_primary'] == 1 ? _t('PRIMARY') : '', 'locale_id' => $va_rep['locale_id'], 'icon' => $va_rep['tags']['thumbnail'], 'mimetype' => $va_rep['info']['original']['PROPERTIES']['mimetype'], 'annotation_type' => isset($va_annotation_type_mappings[$va_rep['info']['original']['PROPERTIES']['mimetype']]) ? $va_annotation_type_mappings[$va_rep['info']['original']['PROPERTIES']['mimetype']] : null, 'type' => $va_rep['info']['original']['PROPERTIES']['typename'], 'dimensions' => $va_rep['dimensions']['original'], 'filename' => $va_rep['info']['original_filename'] ? $va_rep['info']['original_filename'] : _t('Unknown'), 'num_multifiles' => $vn_num_multifiles ? $vn_num_multifiles == 1 ? _t('+ 1 additional preview') : _t('+ %1 additional previews', $vn_num_multifiles) : '', 'metadata' => $vs_extracted_metadata, 'md5' => $vs_md5 ? "{$vs_md5}" : "", 'typename' => $va_rep_type_list[$va_rep['type_id']]['name_singular'], 'fetched_from' => $va_rep['fetched_from'], 'fetched_on' => date('c', $va_rep['fetched_on']), 'fetched' => $va_rep['fetched_from'] ? _t("<h3>Fetched from:</h3> URL %1 on %2", '<a href="' . $va_rep['fetched_from'] . '" target="_ext" title="' . $va_rep['fetched_from'] . '">' . $va_rep['fetched_from'] . '</a>', date('c', $va_rep['fetched_on'])) : ""); $vn_i++; } } return $va_initial_values; break; case 'ca_entities': case 'ca_places': case 'ca_occurrences': case 'ca_objects': case 'ca_collections': case 'ca_list_items': case 'ca_storage_locations': case 'ca_loans': case 'ca_movements': case 'ca_tour_stops': return $this->getRelatedBundleFormValues($pa_options['request'], $pa_options['formName'], $ps_bundle_name, $ps_placement_code, $pa_bundle_settings, $pa_options); break; # ------------------------------- # ------------------------------- case 'ca_object_lots': break; # ------------------------------- # ------------------------------- case 'ca_representation_annotations': break; # ------------------------------- # ------------------------------- default: return null; break; # ------------------------------- } break; } return null; }
/** * Returns associative array, keyed by primary key value with values being * the preferred label of the row from a suitable locale, ready for display * * @param array $pa_ids indexed array of primary key values to fetch labels for * @param array $pa_options * @return array List of media */ function caGetPrimaryRepresentationsForIDs($pa_ids, $pa_options = null) { if (!is_array($pa_ids) && is_numeric($pa_ids) && $pa_ids > 0) { $pa_ids = array($pa_ids); } if (!is_array($pa_ids) || !sizeof($pa_ids)) { return array(); } $pa_access_values = caGetOption("checkAccess", $pa_options, array()); $pa_versions = caGetOption("versions", $pa_options, array(), array('castTo' => 'array')); $ps_table = caGetOption("table", $pa_options, 'ca_objects'); $pa_return = caGetOption("return", $pa_options, array(), array('castTo' => 'array')); $vs_access_where = ''; if (isset($pa_access_values) && is_array($pa_access_values) && sizeof($pa_access_values)) { $vs_access_where = ' AND orep.access IN (' . join(',', $pa_access_values) . ')'; } $o_db = new Db(); $o_dm = Datamodel::load(); if (!($vs_linking_table = RepresentableBaseModel::getRepresentationRelationshipTableName($ps_table))) { return null; } $vs_pk = $o_dm->getTablePrimaryKeyName($ps_table); $qr_res = $o_db->query("\n\t\t\tSELECT oxor.{$vs_pk}, orep.media, orep.representation_id\n\t\t\tFROM ca_object_representations orep\n\t\t\tINNER JOIN {$vs_linking_table} AS oxor ON oxor.representation_id = orep.representation_id\n\t\t\tWHERE\n\t\t\t\t(oxor.{$vs_pk} IN (" . join(',', $pa_ids) . ")) AND oxor.is_primary = 1 AND orep.deleted = 0 {$vs_access_where}\n\t\t"); $vb_return_tags = sizeof($pa_return) == 0 || in_array('tags', $pa_return); $vb_return_info = sizeof($pa_return) == 0 || in_array('info', $pa_return); $vb_return_urls = sizeof($pa_return) == 0 || in_array('urls', $pa_return); $va_media = array(); while ($qr_res->nextRow()) { $va_media_tags = array(); if ($pa_versions && is_array($pa_versions) && sizeof($pa_versions)) { $va_versions = $pa_versions; } else { $va_versions = $qr_res->getMediaVersions('media'); } $vb_media_set = false; foreach ($va_versions as $vs_version) { if (!$vb_media_set && $qr_res->getMediaPath('ca_object_representations.media', $vs_version)) { $vb_media_set = true; } if ($vb_return_tags) { if (sizeof($va_versions) == 1) { $va_media_tags['tags'] = $qr_res->getMediaTag('ca_object_representations.media', $vs_version); } else { $va_media_tags['tags'][$vs_version] = $qr_res->getMediaTag('ca_object_representations.media', $vs_version); } } if ($vb_return_info) { if (sizeof($va_versions) == 1) { $va_media_tags['info'] = $qr_res->getMediaInfo('ca_object_representations.media', $vs_version); } else { $va_media_tags['info'][$vs_version] = $qr_res->getMediaInfo('ca_object_representations.media', $vs_version); } } if ($vb_return_urls) { if (sizeof($va_versions) == 1) { $va_media_tags['urls'] = $qr_res->getMediaUrl('ca_object_representations.media', $vs_version); } else { $va_media_tags['urls'][$vs_version] = $qr_res->getMediaUrl('ca_object_representations.media', $vs_version); } } } $va_media_tags['representation_id'] = $qr_res->get('ca_object_representations.representation_id'); if (!$vb_media_set) { continue; } if (sizeof($pa_return) == 1) { $va_media_tags = $va_media_tags[$pa_return[0]]; } $va_media[$qr_res->get($vs_pk)] = $va_media_tags; } // Return empty array when there's no media if (!sizeof($va_media)) { return array(); } // Preserve order of input ids $va_media_sorted = array(); foreach ($pa_ids as $vn_id) { if (!isset($va_media[$vn_id]) || !$va_media[$vn_id]) { continue; } $va_media_sorted[$vn_id] = $va_media[$vn_id]; } return $va_media_sorted; }