/**
  * 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;
 }