Example #1
0
/**
 * Fetch item_id for item with specified value. Value must match exactly.
 *
 * @param string $ps_list_code List code
 * @param string $ps_value The item value to search for
 * @param array $pa_options Options include:
 *		transaction = transaction to execute queries within. [Default=null]
 * @return int item_id of list item or null if no matching item was found
 */
function caGetListItemIDForValue($ps_list_code, $ps_value, $pa_options = null)
{
    $vs_cache_key = md5($ps_list_code . $ps_value . serialize($pa_options));
    if (MemoryCache::contains($vs_cache_key, 'ListItemIDsForValues')) {
        return MemoryCache::fetch($vs_cache_key, 'ListItemIDsForValues');
    }
    $t_list = new ca_lists();
    if ($o_trans = caGetOption('transaction', $pa_options, null)) {
        $t_list->setTransaction($o_trans);
    }
    if ($va_item = $t_list->getItemFromListByItemValue($ps_list_code, $ps_value)) {
        $vs_ret = array_shift(array_keys($va_item));
        MemoryCache::save($vs_cache_key, $vs_ret, 'ListItemIDsForValues');
        return $vs_ret;
    }
    return null;
}
Example #2
0
 /**
  * Try to return a generic summary for the specified record
  */
 protected function getAllItemInfo()
 {
     if (!($t_instance = $this->_getTableInstance($this->ops_table, $this->opn_id))) {
         // note that $this->opn_id might be a string if we're fetching by idno; you can only use an idno for getting an item, not for editing or deleting
         return false;
     }
     $t_list = new ca_lists();
     $t_locales = new ca_locales();
     $va_locales = $t_locales->getLocaleList(array("available_for_cataloguing_only" => true));
     $va_return = array();
     // allow user-defined template to be passed; allows flexible formatting of returned "display" value
     if (!($vs_template = $this->opo_request->getParameter('template', pString))) {
         $vs_template = '';
     }
     if ($vs_template) {
         $va_return['display'] = caProcessTemplateForIDs($vs_template, $this->ops_table, array($this->opn_id));
     }
     // labels
     $va_labels = $t_instance->get($this->ops_table . ".preferred_labels", array("returnAllLocales" => true));
     $va_labels = end($va_labels);
     if (is_array($va_labels)) {
         foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) {
             foreach ($va_labels_by_locale as $va_tmp) {
                 $va_return["preferred_labels"][$va_locales[$vn_locale_id]["code"]][] = $va_tmp[$t_instance->getLabelDisplayField()];
             }
         }
     }
     $va_labels = $t_instance->get($this->ops_table . ".nonpreferred_labels", array("returnAllLocales" => true));
     $va_labels = end($va_labels);
     if (is_array($va_labels)) {
         foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) {
             foreach ($va_labels_by_locale as $va_tmp) {
                 $va_return["nonpreferred_labels"][$va_locales[$vn_locale_id]["code"]][] = $va_tmp[$t_instance->getLabelDisplayField()];
             }
         }
     }
     // "intrinsic" fields
     foreach ($t_instance->getFieldsArray() as $vs_field_name => $va_field_info) {
         $vs_list = null;
         if (!is_null($vs_val = $t_instance->get($vs_field_name))) {
             $va_return[$vs_field_name] = array("value" => $vs_val);
             if (isset($va_field_info["LIST"])) {
                 // fields like "access" and "status"
                 $va_tmp = end($t_list->getItemFromListByItemValue($va_field_info["LIST"], $vs_val));
                 foreach ($va_locales as $vn_locale_id => $va_locale) {
                     $va_return[$vs_field_name]["display_text"][$va_locale["code"]] = $va_tmp[$vn_locale_id]["name_singular"];
                 }
             }
             if (isset($va_field_info["LIST_CODE"])) {
                 // typical example: type_id
                 $va_item = $t_list->getItemFromListByItemID($va_field_info["LIST_CODE"], $vs_val);
                 $t_item = new ca_list_items($va_item["item_id"]);
                 $va_labels = $t_item->getLabels(null, __CA_LABEL_TYPE_PREFERRED__);
                 foreach ($va_locales as $vn_locale_id => $va_locale) {
                     if ($vs_label = $va_labels[$va_item["item_id"]][$vn_locale_id][0]["name_singular"]) {
                         $va_return[$vs_field_name]["display_text"][$va_locale["code"]] = $vs_label;
                     }
                 }
             }
         }
     }
     // representations for representable stuff
     if ($t_instance instanceof RepresentableBaseModel) {
         $va_reps = $t_instance->getRepresentations(array('preview170', 'original'));
         if (is_array($va_reps) && sizeof($va_reps) > 0) {
             $va_return['representations'] = $va_reps;
         }
     }
     // captions for representations
     if ($this->ops_table == "ca_object_representations") {
         $va_captions = $t_instance->getCaptionFileList();
         if (is_array($va_captions) && sizeof($va_captions) > 0) {
             $va_return['captions'] = $va_captions;
         }
     }
     // attributes
     $va_codes = $t_instance->getApplicableElementCodes();
     foreach ($va_codes as $vs_code) {
         if ($va_vals = $t_instance->get($this->ops_table . "." . $vs_code, array("convertCodesToDisplayText" => true, "returnAllLocales" => true))) {
             $va_vals_by_locale = end($va_vals);
             // I seriously have no idea what that additional level of nesting in the return format is for
             $va_attribute_values = array();
             foreach ($va_vals_by_locale as $vn_locale_id => $va_locale_vals) {
                 foreach ($va_locale_vals as $vs_val_id => $va_actual_data) {
                     $vs_locale_code = isset($va_locales[$vn_locale_id]["code"]) ? $va_locales[$vn_locale_id]["code"] : "none";
                     $va_attribute_values[$vs_val_id][$vs_locale_code] = $va_actual_data;
                 }
                 $va_return[$this->ops_table . "." . $vs_code] = array_values($va_attribute_values);
             }
         }
     }
     // relationships
     // yes, not all combinations between these tables have
     // relationships but it also doesn't hurt to query
     foreach ($this->opa_valid_tables as $vs_rel_table) {
         //
         // set-related hacks
         if ($this->ops_table == "ca_sets" && $vs_rel_table == "ca_tours") {
             // throws SQL error in getRelatedItems
             continue;
         }
         // you'd expect the set items to be included for sets but
         // we don't wan't to list set items as allowed related table
         // which is why we add them by hand here
         if ($this->ops_table == "ca_sets") {
             $va_tmp = $t_instance->getItems();
             $va_set_items = array();
             foreach ($va_tmp as $va_loc) {
                 foreach ($va_loc as $va_item) {
                     $va_set_items[] = $va_item;
                 }
             }
             $va_return["related"]["ca_set_items"] = $va_set_items;
         }
         // end set-related hacks
         //
         $va_related_items = $t_instance->get($vs_rel_table, array("returnAsArray" => true));
         if (is_array($va_related_items) && sizeof($va_related_items) > 0) {
             $va_return["related"][$vs_rel_table] = array_values($va_related_items);
         }
     }
     return $va_return;
 }
Example #3
0
function caGetListItemIDForValue($ps_list_code, $ps_value, $pa_options = null)
{
    global $g_list_item_id_for_value_cache;
    if (isset($g_list_item_id_for_value_cache[$ps_list_code . '/' . $ps_value])) {
        return $g_list_item_id_for_value_cache[$ps_list_code . '/' . $ps_value];
    }
    $t_list = new ca_lists();
    if ($o_trans = caGetOption('transaction', $pa_options, null)) {
        $t_list->setTransaction($o_trans);
    }
    if ($g_list_item_id_for_value_cache[$ps_list_code . '/' . $ps_value] = $t_list->getItemFromListByItemValue($ps_list_code, $ps_value)) {
        $va_tmp = array_keys($g_list_item_id_for_value_cache[$ps_list_code . '/' . $ps_value]);
        return array_shift($va_tmp);
    }
    return null;
}