Example #1
0
 public static function findFirst($parameters = NULL, $hostType = NULL)
 {
     $class = get_called_class();
     $object = new $class();
     BaseModel::$tableName = $object->getSource();
     BaseModel::$hostType = $hostType;
     return parent::findFirst($parameters);
 }
Example #2
0
/**
 * Converts result set into display labels for relationship lookup
 *
 * @param SearchResult $qr_rel_items 
 * @param BaseModel $pt_rel
 * @param array $pa_options Array of options, including:
 *		stripTags = default is false
 * 		exclude = list of primary key values to omit from returned list
 *		config = 
 *		limit = maximum number of items to return; if omitted all items are returned
 *		inlineCreateMessage = 
 *		inlineCreateQuery =
 *		inlineCreateMessageDoesNotExist =
 *		template = 
 *		primaryIDs = row_ids for primary rows in related table, keyed by table name; when resolving ambiguous relationships the row_ids will be excluded from consideration. This option is rarely used and exists primarily to take care of a single
 *						edge case: you are processing a template relative to a self-relationship such as ca_entities_x_entities that includes references to the subject table (ca_entities, in the case of ca_entities_x_entities). There are
 *						two possible paths to take in this situations; primaryIDs lets you specify which ones you *don't* want to take by row_id. For interstitial editors, the ids will be set to a single id: that of the subject (Eg. ca_entities) row
 *						from which the interstitial was launched.
 * @return mixed 
 */
function caProcessRelationshipLookupLabel($qr_rel_items, $pt_rel, $pa_options = null)
{
    $va_initial_values = array();
    $vs_hier_fld = $pt_rel->getProperty('HIERARCHY_ID_FLD');
    $vs_idno_fld = $pt_rel->getProperty('ID_NUMBERING_ID_FIELD');
    $vs_idno_sort_fld = $pt_rel->getProperty('ID_NUMBERING_SORT_FIELD');
    $vs_rel_pk = caGetOption('primaryKey', $pa_options, $pt_rel->primaryKey());
    $vs_rel_table = caGetOption('table', $pa_options, $pt_rel->tableName());
    $o_config = !isset($pa_options['config']) || !is_object($pa_options['config']) ? Configuration::load() : $pa_options['config'];
    $pn_limit = caGetOption('limit', $pa_options, null);
    $ps_inline_create_message = caGetOption('inlineCreateMessage', $pa_options, null);
    $ps_inline_create_does_not_exist_message = caGetOption('inlineCreateMessageDoesNotExist', $pa_options, null);
    $ps_inline_create_query = caGetOption('inlineCreateQuery', $pa_options, null);
    $ps_inline_create_query_lc = mb_strtolower($ps_inline_create_query);
    $ps_empty_result_message = caGetOption('emptyResultMessage', $pa_options, null);
    $ps_empty_result_query = caGetOption('emptyResultQuery', $pa_options, null);
    $vs_template = caGetOption('template', $pa_options, null);
    $va_exclude = caGetOption('exclude', $pa_options, array(), array('castTo' => 'array'));
    $va_display_format = $o_config->getList("{$vs_rel_table}_lookup_settings");
    $vs_display_delimiter = $o_config->get("{$vs_rel_table}_lookup_delimiter");
    if (!$vs_template) {
        $vs_template = join($vs_display_delimiter, $va_display_format);
    }
    $va_related_item_info = $va_parent_ids = $va_hierarchy_ids = array();
    $va_items = array();
    $o_dm = Datamodel::load();
    $t_rel = $o_dm->getInstanceByTableName($vs_rel_table, true);
    $vs_type_id_fld = method_exists($t_rel, 'getTypeFieldName') ? $t_rel->getTypeFieldName() : null;
    $vn_c = 0;
    $vb_include_inline_add_does_not_exist_message = $vb_include_empty_result_message = false;
    $vb_include_inline_add_message = true;
    if (is_object($qr_rel_items)) {
        if (!$qr_rel_items->numHits()) {
            if ($ps_inline_create_does_not_exist_message) {
                $vb_include_inline_add_does_not_exist_message = true;
                $vb_include_inline_add_message = false;
            } else {
                if ($ps_empty_result_message) {
                    $vb_include_empty_result_message = true;
                }
            }
        } else {
            $vs_table = $qr_rel_items->tableName();
            $vs_pk = $qr_rel_items->primaryKey();
            $va_primary_ids = method_exists($pt_rel, "isSelfRelationship") && ($vb_is_self_rel = $pt_rel->isSelfRelationship()) ? caGetOption("primaryIDs", $pa_options, null) : null;
            while ($qr_rel_items->nextHit()) {
                $vn_id = $qr_rel_items->get("{$vs_rel_table}.{$vs_rel_pk}");
                if (in_array($vn_id, $va_exclude)) {
                    continue;
                }
                $va_item = array('id' => $vn_id, $vs_rel_pk => $vn_id);
                if ($vs_type_id_fld) {
                    $va_item['type_id'] = $qr_rel_items->get("{$vs_rel_table}.{$vs_type_id_fld}");
                }
                $va_item['_display'] = caProcessTemplateForIDs($vs_template, $vs_table, array($qr_rel_items->get("{$vs_table}.{$vs_pk}")), array('returnAsArray' => false, 'returnAsLink' => false, 'delimiter' => caGetOption('delimiter', $pa_options, $vs_display_delimiter), 'resolveLinksUsing' => $vs_rel_table, 'primaryIDs' => $va_primary_ids));
                $va_item['label'] = mb_strtolower($qr_rel_items->get("{$vs_table}.preferred_labels"));
                $va_items[$vn_id] = $va_item;
                $vn_c++;
                if ($pn_limit && $pn_limit <= $vn_c) {
                    break;
                }
            }
        }
    }
    if (isset($pa_options['relatedItems']) && is_array($pa_options['relatedItems']) && sizeof($pa_options['relatedItems'])) {
        $va_tmp = array();
        foreach ($pa_options['relatedItems'] as $vn_relation_id => $va_relation) {
            $va_items[$va_relation[$vs_rel_pk]]['relation_id'] = $va_relation['relation_id'];
            $va_items[$va_relation[$vs_rel_pk]]['relationship_type_id'] = $va_items[$va_relation[$vs_rel_pk]]['type_id'] = $va_relation['direction'] ? $va_relation['direction'] . '_' . $va_relation['relationship_type_id'] : $va_relation['relationship_type_id'];
            $va_items[$va_relation[$vs_rel_pk]]['rel_type_id'] = $va_relation['relationship_type_id'];
            $va_items[$va_relation[$vs_rel_pk]]['relationship_typename'] = $va_relation['relationship_typename'];
            $va_items[$va_relation[$vs_rel_pk]]['idno'] = $va_relation[$vs_idno_fld];
            $va_items[$va_relation[$vs_rel_pk]]['idno_sort'] = $va_relation[$vs_idno_sort_fld];
            $va_items[$va_relation[$vs_rel_pk]]['label'] = $va_relation['label'];
            $va_items[$va_relation[$vs_rel_pk]]['direction'] = $va_relation['direction'];
            $va_items[$va_relation[$vs_rel_pk]]['effective_date'] = $va_relation['effective_date'];
            if (isset($va_relation['surname'])) {
                // pass forename and surname entity label fields to support proper sorting by name
                $va_items[$va_relation[$vs_rel_pk]]['surname'] = $va_relation['surname'];
                $va_items[$va_relation[$vs_rel_pk]]['forename'] = $va_relation['forename'];
            }
            if (!isset($va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk]) || !$va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk]) {
                $va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk] = $va_items[$va_relation[$vs_rel_pk]]['id'] = $va_relation[$vs_rel_pk];
            }
            if ($vs_template) {
                $va_items[$va_relation[$vs_rel_pk]]['_display'] = caProcessTemplateForIDs($vs_template, $pt_rel->tableName(), array($va_relation['relation_id'] ? $va_relation['relation_id'] : $va_relation[$vs_pk]), array('returnAsArray' => false, 'returnAsLink' => false, 'delimiter' => caGetOption('delimiter', $pa_options, $vs_display_delimiter), 'resolveLinksUsing' => $vs_rel_table, 'primaryIDs' => $va_primary_ids));
            } else {
                $va_items[$va_relation[$vs_rel_pk]]['_display'] = $va_items[$va_relation[$vs_rel_pk]]['label'];
            }
            $va_tmp[$vn_relation_id] = $va_items[$va_relation[$vs_rel_pk]];
        }
        $va_items = $va_tmp;
        unset($va_tmp);
    }
    foreach ($va_items as $va_item) {
        $vn_id = $va_item[$vs_rel_pk];
        if (in_array($vn_id, $va_exclude)) {
            continue;
        }
        $vs_display = $va_item['_display'];
        if (isset($pa_options['stripTags']) && $pa_options['stripTags']) {
            if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\\&\\-_]*>)!', $vs_display, $va_matches)) {
                // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
                array_shift($va_matches);
                foreach ($va_matches as $vs_match) {
                    $vs_display = str_replace($vs_match, htmlspecialchars($vs_match), $vs_display);
                }
            }
            $vs_display = trim(strip_tags($vs_display));
            $vs_label = $va_item['label'];
            if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\\&\\-_]*>)!', $vs_label, $va_matches)) {
                // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
                array_shift($va_matches);
                foreach ($va_matches as $vs_match) {
                    $vs_label = str_replace($vs_match, htmlspecialchars($vs_match), $vs_label);
                }
            }
            $va_item['label'] = trim(strip_tags($vs_label));
        }
        $vs_display_lc = mb_strtolower($vs_display);
        if ($vs_display_lc == $ps_inline_create_query_lc || isset($va_item['label']) && $va_item['label'] == $ps_inline_create_query_lc) {
            $vb_include_inline_add_message = false;
        }
        $po_request = caGetOption('request', $pa_options);
        if ($po_request && ca_editor_uis::loadDefaultUI($pt_rel->tableName(), $po_request, $va_item['rel_type_id'])) {
            $va_item['hasInterstitialUI'] = true;
        } else {
            $va_item['hasInterstitialUI'] = false;
        }
        $va_initial_values[$va_item['relation_id'] ? (int) $va_item['relation_id'] : $va_item[$vs_rel_pk]] = array_merge($va_item, array('label' => $vs_display));
    }
    if ($vb_include_inline_add_message && $ps_inline_create_message) {
        array_push($va_initial_values, array('label' => $ps_inline_create_message, 'id' => 0, $vs_rel_pk => 0, '_query' => $ps_inline_create_query));
    } elseif ($vb_include_inline_add_does_not_exist_message && $ps_inline_create_does_not_exist_message) {
        array_push($va_initial_values, array('label' => $ps_inline_create_does_not_exist_message, 'id' => 0, $vs_rel_pk => 0, '_query' => $ps_inline_create_query));
    } elseif ($vb_include_empty_result_message) {
        array_push($va_initial_values, array('label' => $ps_empty_result_message, 'id' => -1, $vs_rel_pk => -1, '_query' => $ps_empty_result_query));
    }
    return $va_initial_values;
}
Example #3
0
/**
 * Merges sources specified with any specified "restrict_to_sources"/"restrictToSources" option, user access settings and sources configured in app.conf
 * into a single list of source_ids suitable for enforcing source restrictions.
 *
 * @param BaseModel $t_instance A model instance for the table to which the sources apply
 * @param array $pa_options An array of options containing, if specified, a list of sources for either the "restrict_to_sources" or "restrictToSources" keys
 * 
 * @return array List of numeric source_ids for which the user has access
 */
function caMergeSourceRestrictionLists($t_instance, $pa_options)
{
    $va_restrict_to_source_ids = null;
    if (is_array($pa_options['restrict_to_sources']) && sizeof($pa_options['restrict_to_sources'])) {
        $pa_options['restrictToSources'] = $pa_options['restrict_to_sources'];
    }
    if (is_array($pa_options['restrictToSources']) && sizeof($pa_options['restrictToSources'])) {
        $va_restrict_to_source_ids = caMakeSourceIDList($t_instance->tableName(), $pa_options['restrictToSources'], array('noChildren' => true));
    }
    $va_sources = null;
    $o_config = Configuration::load();
    if ((bool) $o_config->get('perform_source_access_checking') && method_exists($t_instance, 'getSourceFieldName') && ($vs_source_field_name = $t_instance->getSourceFieldName())) {
        $va_sources = caGetSourceRestrictionsForUser($t_instance->tableName());
    }
    if (is_array($va_sources) && sizeof($va_sources) && is_array($va_restrict_to_source_ids) && sizeof($va_restrict_to_source_ids)) {
        if (sizeof($va_tmp = array_intersect($va_restrict_to_source_ids, $va_sources))) {
            $va_sources = $va_tmp;
        }
    } else {
        if (!is_array($va_sources) || !sizeof($va_sources)) {
            $va_sources = $va_restrict_to_source_ids;
        }
    }
    return $va_sources;
}
Example #4
0
 /**
  * get() value for intrinsic
  *
  * @param array $pa_value_list
  * @param BaseModel $pt_instance
  * @param array Options
  *
  * @return array|string
  */
 private function _getIntrinsicValue($pa_value_list, $pt_instance, $pa_options)
 {
     $vb_return_as_link = isset($pa_options['returnAsLink']) ? $pa_options['returnAsLink'] : false;
     $vb_get_direct_date = (bool) caGetOption(array('getDirectDate', 'GET_DIRECT_DATE'), $pa_options, false);
     $vb_sortable = isset($pa_options['sortable']) ? $pa_options['sortable'] : false;
     $va_path_components = $pa_options['pathComponents'];
     $va_field_info = $pa_options['fieldInfo'];
     $vs_pk = $pa_options['primaryKey'];
     $vs_table_name = $pt_instance->tableName();
     // Handle specific intrinsic types
     switch ($va_field_info['FIELD_TYPE']) {
         case FT_DATERANGE:
         case FT_HISTORIC_DATERANGE:
         case FT_TIMESTAMP:
         case FT_DATETIME:
         case FT_HISTORIC_DATETIME:
             foreach ($pa_value_list as $vn_locale_id => $va_values) {
                 if ($pa_options['useLocaleCodes']) {
                     if (!$vn_locale_id || !($vm_locale_id = $this->opo_locales->localeIDToCode($vn_locale_id))) {
                         $vm_locale_id = __CA_DEFAULT_LOCALE__;
                     }
                 } else {
                     if (!($vm_locale_id = $vn_locale_id)) {
                         $vm_locale_id = $this->opo_locales->localeCodeToID(__CA_DEFAULT_LOCALE__);
                     }
                 }
                 foreach ($va_values as $vn_i => $va_value) {
                     $va_ids[] = $vn_id = $va_value[$vs_pk];
                     if (in_array($va_field_info['FIELD_TYPE'], array(FT_TIMESTAMP, FT_DATETIME, FT_HISTORIC_DATETIME))) {
                         $vs_prop = $va_value[$va_path_components['field_name']];
                         if (!$vb_get_direct_date && !$vb_sortable) {
                             $this->opo_tep->init();
                             if ($va_field_info['FIELD_TYPE'] !== FT_HISTORIC_DATETIME) {
                                 $this->opo_tep->setUnixTimestamps($vs_prop, $vs_prop);
                             } else {
                                 $this->opo_tep->setHistoricTimestamps($vs_prop, $vs_prop);
                             }
                             $vs_prop = $this->opo_tep->getText($pa_options);
                         }
                     } elseif ($vb_get_direct_date) {
                         $vs_prop = $va_value[$va_field_info['START']];
                     } elseif ($vb_sortable) {
                         $vs_prop = $va_value[$va_field_info['START']];
                     } else {
                         $this->opo_tep->init();
                         if ($va_field_info['FIELD_TYPE'] == FT_DATERANGE) {
                             $this->opo_tep->setUnixTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                         } else {
                             $this->opo_tep->setHistoricTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                         }
                         $vs_prop = $this->opo_tep->getText($pa_options);
                     }
                     if ($vb_return_as_link) {
                         $vs_prop = array_shift(caCreateLinksFromText(array($vs_prop), $vs_table_name, array($vn_id)));
                     }
                     $va_return_values[$vn_id][$vm_locale_id] = $vs_prop;
                 }
             }
             break;
         case FT_MEDIA:
             if (!($vs_version = $va_path_components['subfield_name'])) {
                 $vs_version = "largeicon";
                 // TODO: fix
             }
             foreach ($pa_value_list as $vn_locale_id => $va_values) {
                 if ($pa_options['useLocaleCodes']) {
                     if (!$vn_locale_id || !($vm_locale_id = $this->opo_locales->localeIDToCode($vn_locale_id))) {
                         $vm_locale_id = __CA_DEFAULT_LOCALE__;
                     }
                 } else {
                     if (!($vm_locale_id = $vn_locale_id)) {
                         $vm_locale_id = $this->opo_locales->localeCodeToID(__CA_DEFAULT_LOCALE__);
                     }
                 }
                 foreach ($va_values as $vn_i => $va_value) {
                     $va_ids[] = $vn_id = $va_value[$vs_pk];
                     $o_media_settings = new MediaProcessingSettings($va_path_components['table_name'], $va_path_components['field_name']);
                     $va_versions = $o_media_settings->getMediaTypeVersions('*');
                     if (!isset($va_versions[$vs_version])) {
                         $va_tmp = array_keys($va_versions);
                         $vs_version = array_shift($va_tmp);
                     }
                     // See if an info element was passed, eg. ca_object_representations.media.icon.width should return the width of the media rather than a tag or url to the media
                     $vs_info_element = $va_path_components['num_components'] == 4 ? $va_path_components['components'][3] : null;
                     if ($pa_options['unserialize']) {
                         $va_return_values[$vn_id][$vm_locale_id] = caUnserializeForDatabase($va_value[$va_path_components['field_name']]);
                     } elseif ($vs_info_element) {
                         $va_return_values[$vn_id][$vm_locale_id] = $this->getMediaInfo($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $vs_info_element, $pa_options);
                     } elseif (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                         $va_return_values[$vn_id][$vm_locale_id] = $this->getMediaUrl($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                     } elseif (isset($pa_options['returnPath']) && $pa_options['returnPath']) {
                         $va_return_values[$vn_id][$vm_locale_id] = $this->getMediaPath($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                     } else {
                         $va_return_values[$vn_id][$vm_locale_id] = $this->getMediaTag($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                     }
                 }
             }
             break;
         default:
             // is intrinsic field in primary table
             foreach ($pa_value_list as $vn_locale_id => $va_values) {
                 if ($pa_options['useLocaleCodes']) {
                     if (!$vn_locale_id || !($vm_locale_id = $this->opo_locales->localeIDToCode($vn_locale_id))) {
                         $vm_locale_id = __CA_DEFAULT_LOCALE__;
                     }
                 } else {
                     if (!($vm_locale_id = $vn_locale_id)) {
                         $vm_locale_id = $this->opo_locales->localeCodeToID(__CA_DEFAULT_LOCALE__);
                     }
                 }
                 foreach ($va_values as $vn_i => $va_value) {
                     $va_ids[] = $vn_id = $va_value[$vs_pk];
                     $vs_prop = $va_value[$va_path_components['field_name']];
                     if ($pa_options['unserialize']) {
                         $vs_prop = caUnserializeForDatabase($vs_prop);
                     }
                     if ($pa_options['convertCodesToDisplayText']) {
                         $vs_prop = $this->_convertCodeToDisplayText($vs_prop, $va_path_components, $pt_instance, $pa_options);
                     } elseif ($pa_options['convertCodesToIdno']) {
                         $vs_prop = $this->_convertCodeToIdno($vs_prop, $va_path_components, $pt_instance, $pa_options);
                     }
                     $va_return_values[$vn_id][$vm_locale_id] = $vs_prop;
                 }
             }
             break;
     }
     if (!$pa_options['returnAllLocales']) {
         $va_return_values = caExtractValuesByUserLocale($va_return_values);
     }
     if ($pa_options['returnWithStructure']) {
         return is_array($va_return_values) ? $va_return_values : array();
     }
     //
     // Flatten array for return as string or simple array value
     //
     $va_flattened_values = $this->_flattenArray($va_return_values, $pa_options);
     if ($pa_options['returnAsArray']) {
         return $va_flattened_values;
     } else {
         return sizeof($va_flattened_values) > 0 ? join($pa_options['delimiter'], $va_flattened_values) : null;
     }
 }
/**
 * Perform mapping of extracted media metadata to CollectiveAccess bundles.
 *
 * @param BaseModel $po_instance Model instance to insert extracted metadata into
 * @param array $pa_metadata Extracted metadata
 * @param int $pn_locale_id The current locale as a numeric locale_id
 * @return bool True extracted metadata was mapped and the model changed, false if no change was made to the model
 */
function caExtractEmbeddedMetadata($po_instance, $pa_metadata, $pn_locale_id)
{
    if (!is_array($pa_metadata)) {
        return false;
    }
    $vb_did_mapping = false;
    if (!($vs_media_metadata_config = $po_instance->getAppConfig()->get('media_metadata'))) {
        return false;
    }
    $o_metadata_config = Configuration::load($vs_media_metadata_config);
    $va_mappings = $o_metadata_config->getAssoc('import_mappings');
    $vs_tablename = $po_instance->tableName();
    // set extracted georef?
    $va_georef_elements = $o_metadata_config->getList('extract_embedded_exif_georeferencing_to');
    $va_georef_containers = $o_metadata_config->getAssoc('extract_embedded_exif_georeferencing_to_container');
    $va_date_elements = $o_metadata_config->getList('extract_embedded_exif_creation_date_to');
    $va_date_containers = $o_metadata_config->getAssoc('extract_embedded_exif_creation_date_to_container');
    if (isset($pa_metadata['EXIF']) && is_array($pa_metadata['EXIF']) && (is_array($va_georef_elements) && sizeof($va_georef_elements) || is_array($va_georef_containers) && sizeof($va_georef_containers) || is_array($va_date_elements) && sizeof($va_date_elements) || is_array($va_date_containers) && sizeof($va_date_containers))) {
        $va_exif_data = $pa_metadata['EXIF'];
        if (is_array($va_georef_elements)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    $po_instance->addAttribute(array($va_tmp[1] => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id), $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_georef_containers)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $t_list = new ca_lists();
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_elements)) {
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    $po_instance->addAttribute(array($va_tmp[1] => $vs_date, 'locale_id' => $pn_locale_id), $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_containers)) {
            $t_list = new ca_lists();
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => $vs_date, 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
    }
    if (!isset($va_mappings[$po_instance->tableName()])) {
        return $vb_did_mapping;
    }
    $va_mapping = $va_mappings[$vs_tablename];
    $vs_type = $po_instance->getTypeCode();
    if (isset($va_mapping[$vs_type]) && is_array($va_mapping[$vs_type])) {
        $va_mapping = $va_mapping[$vs_type];
    } else {
        if (isset($va_mapping['__default__']) && is_array($va_mapping['__default__'])) {
            $va_mapping = $va_mapping['__default__'];
        } else {
            return $vb_did_mapping;
        }
    }
    foreach ($va_mapping as $vs_metadata => $va_attr) {
        $va_tmp = explode(":", $vs_metadata);
        foreach ($va_attr as $vs_attr) {
            $va_metadata =& $pa_metadata;
            foreach ($va_tmp as $vs_el) {
                if (isset($va_metadata[$vs_el])) {
                    $va_metadata =& $va_metadata[$vs_el];
                } else {
                    continue 2;
                }
            }
            if (is_array($va_metadata)) {
                $va_metadata = join(";", $va_metadata);
            }
            if (!is_int($va_metadata)) {
                // pass ints through for values like WhiteBalance = 0
                if (!trim($va_metadata)) {
                    continue 2;
                }
            }
            $va_tmp2 = explode(".", $vs_attr);
            switch ($va_tmp2[0]) {
                case 'preferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, true);
                    break;
                case 'nonpreferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, false);
                    break;
                default:
                    if ($po_instance->hasField($vs_attr)) {
                        $po_instance->set($vs_attr, $va_metadata);
                    } else {
                        // try as attribute
                        if (sizeof($va_tmp2) == 2) {
                            // format ca_objects.foo, we only want "foo"
                            $po_instance->replaceAttribute(array($va_tmp2[1] => $va_metadata, 'locale_id' => $pn_locale_id), $va_tmp2[1]);
                        }
                    }
            }
            $vb_did_mapping = true;
        }
    }
    return $vb_did_mapping;
}
Example #6
0
 public static function model($tableName = '', $className = __CLASS__)
 {
     self::$tableName = $tableName;
     return parent::model($className);
 }