/** */ function __getItemHTTPVars(&$itemObj) { $attribute_type_rs = $this->__getItemTypeAttribs($itemObj->getItemType()); if (is_array($attribute_type_rs)) { // this will be set if array encountered, but not lookup value. $processing_s_attribute_type = FALSE; $new_attributes_rs = $itemObj->getAttributes(); reset($attribute_type_rs); while (list(, $attribute_type_r) = each($attribute_type_rs)) { if ($attribute_type_r['s_field_type'] != 'DURATION' && $attribute_type_r['s_field_type'] != 'TITLE' && $attribute_type_r['s_field_type'] != 'STATUSTYPE' && $attribute_type_r['s_field_type'] != 'STATUSCMNT' && $attribute_type_r['s_field_type'] != 'ITEM_ID') { $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); if (isset($new_attributes_rs[$attribute_type_r['s_attribute_type']])) { // TODO: Consider adding values not found in the lookup table to the s_attribute_type_lookup. if ($attribute_type_r['lookup_attribute_ind'] == 'Y') { // reset $value_r = NULL; // here is where we want some sanity checking of the options if (is_not_empty_array($new_attributes_rs[$attribute_type_r['s_attribute_type']])) { $value_r = $new_attributes_rs[$attribute_type_r['s_attribute_type']]; } else { $value_r[] = $new_attributes_rs[$attribute_type_r['s_attribute_type']]; } $lookup_value_r = array(); for ($i = 0; $i < count($value_r); $i++) { $raw_value = trim($value_r[$i]); if (strlen($raw_value) > 0) { $value = fetch_attribute_type_lookup_value($attribute_type_r['s_attribute_type'], $raw_value); if ($value !== FALSE) { $lookup_value_r[] = $value; } else { $lookup_value_r[] = $raw_value; } } } $item_attributes_rs[$fieldname] = $lookup_value_r; } else { if (is_not_empty_array($new_attributes_rs[$attribute_type_r['s_attribute_type']])) { // This indicates we have a repeated s_attribute_type, and so should act appropriately. if ($processing_s_attribute_type != NULL && $attribute_type_r['s_attribute_type'] == $processing_s_attribute_type) { $item_attributes_rs[$fieldname] = $new_attributes_rs[$attribute_type_r['s_attribute_type']][0]; array_splice($new_attributes_rs[$attribute_type_r['s_attribute_type']], 0, 1); } else { if (count($new_attributes_rs[$attribute_type_r['s_attribute_type']]) > 1) { // this is the first occurence of the s_attribute_type, so lets see if its repeated at least once. if (is_numeric(fetch_s_item_attribute_type_next_order_no($itemObj->getItemType(), $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']))) { $item_attributes_rs[$fieldname] = $new_attributes_rs[$attribute_type_r['s_attribute_type']][0]; array_splice($new_attributes_rs[$attribute_type_r['s_attribute_type']], 0, 1); $processing_s_attribute_type = $attribute_type_r['s_attribute_type']; } else { // otherwise just copy the whole thing. $item_attributes_rs[$fieldname] = $new_attributes_rs[$attribute_type_r['s_attribute_type']]; } } else { $item_attributes_rs[$fieldname] = $new_attributes_rs[$attribute_type_r['s_attribute_type']][0]; } } } else { if (!is_array($new_attributes_rs[$attribute_type_r['s_attribute_type']])) { $item_attributes_rs[$fieldname] = $new_attributes_rs[$attribute_type_r['s_attribute_type']]; } } } } } else { // instance class if (strcasecmp(get_class($itemObj), 'ItemInstance') === 0) { if ($attribute_type_r['s_field_type'] == 'DURATION' && is_numeric($itemObj->getBorrowDuration())) { $item_attributes_rs['borrow_duration'] = $itemObj->getBorrowDuration(); } else { if ($attribute_type_r['s_field_type'] == 'STATUSTYPE') { $item_attributes_rs['s_status_type'] = $itemObj->getStatusType(); } else { if ($attribute_type_r['s_field_type'] == 'STATUSCMNT' && strlen($itemObj->getStatusComment()) > 0) { $item_attributes_rs['status_comment'] = $itemObj->getStatusComment(); } } } } else { if ($attribute_type_r['s_field_type'] == 'TITLE') { $item_attributes_rs['title'] = $itemObj->getTitle(); } } } } //while return $item_attributes_rs; } else { return FALSE; } }
/** * The $site_plugin_attributes_r will consist of array entries, each identified by a * alphakey. The value may in fact be another array and this has to be handled * appropriately. */ function get_expanded_and_mapped_site_plugin_item_variables_r($site_type, $s_item_type, $site_item_attributes_r) { $query = "SELECT variable, s_attribute_type, lookup_attribute_val_restrict_ind " . "FROM s_site_plugin_s_attribute_type_map " . "WHERE site_type = '" . $site_type . "' "; $query .= "AND (s_item_type = '*' OR s_item_type = '" . $s_item_type . "') AND "; $query .= "(s_item_type_group = '*' "; $item_type_group_arr = fetch_item_type_groups_for_item_type_r($s_item_type); if (is_array($item_type_group_arr)) { $query .= "OR s_item_type_group IN (" . format_sql_in_clause($item_type_group_arr) . ")) "; } else { $query .= ") "; } $query .= "ORDER BY variable, s_attribute_type"; $new_attributes_r = array(); // cache this, so we can check if lookup_attribute_val_restrict_ind = 'Y' $lookup_attribute_val_restrict_ind = array(); $mapped_attributes_r = array(); $results = db_query($query); if ($results && db_num_rows($results) > 0) { $variable = NULL; while ($attribute_type_map_r = db_fetch_assoc($results)) { $value = NULL; $variable = $attribute_type_map_r['variable']; if (isset($site_item_attributes_r[$variable])) { $value = $site_item_attributes_r[$variable]; // at least one direct mapping - title should not be flagged - as there is requirement for multiple mappings if ($variable != 'title') { $mapped_attributes_r[] = $variable; } } $key = strtolower($attribute_type_map_r['s_attribute_type']); if ($value !== NULL) { if (isset($new_attributes_r[$key])) { if (!is_array($new_attributes_r[$key])) { $new_attributes_r[$key] = array($new_attributes_r[$key]); } if (is_array($value)) { $new_attributes_r[$key] = array_merge($new_attributes_r[$key], $value); } else { $new_attributes_r[$key][] = $value; } } else { $new_attributes_r[$key] = $value; } } if ($attribute_type_map_r['lookup_attribute_val_restrict_ind'] == 'Y') { $lookup_attribute_val_restrict_ind_r[$key] = 'Y'; } } db_free_result($results); } // now for any variables that do not have a mapping, add them to the $new_attributes_r reset($site_item_attributes_r); while (list($key, $value) = @each($site_item_attributes_r)) { $key = strtolower($key); if (isset($new_attributes_r[$key])) { $oldValue = NULL; // we want the direct mapping attributes first. if (is_array($new_attributes_r[$key])) { $oldValue = $new_attributes_r[$key]; } else { $oldValue[] = $new_attributes_r[$key]; } unset($new_attributes_r[$key]); if (is_array($value)) { $new_attributes_r[$key] = $value; } else { $new_attributes_r[$key][] = $value; } while (list(, $value) = each($oldValue)) { if (!in_array($value, $new_attributes_r[$key])) { $new_attributes_r[$key][] = $value; } } } else { if (!in_array($key, $mapped_attributes_r)) { $new_attributes_r[$key] = $value; } } } $site_item_attributes_r = NULL; // now we need to check to see if any lookup mappings exist for each // of the attribute values, and update the $value's appropriately. reset($new_attributes_r); while (list($key, $value) = @each($new_attributes_r)) { // temporary UPPER so we can work with actual s_attribute_type records in database $s_attribute_type = strtoupper($key); if (is_lookup_attribute_type($s_attribute_type)) { $values_r = NULL; // if a lookup attribute type, we want to make sure that the $value's // are all arrays anyway, so lets do that check each time. if (is_array($value)) { $values_r = $value; } else { $values_r[] = $value; } $results = fetch_site_plugin_s_attribute_type_lookup_map_rs($site_type, $s_attribute_type); if ($results) { $found_entries_r = array(); $new_values_r = array(); while ($lookup_map_r = db_fetch_assoc($results)) { for ($i = 0; $i < count($values_r); $i++) { if (strcasecmp($values_r[$i], $lookup_map_r['value']) === 0) { $found_entries_r[] = $values_r[$i]; if (!in_array($lookup_map_r['lookup_attribute_val'], $new_values_r)) { $new_values_r[] = $lookup_map_r['lookup_attribute_val']; } } } } db_free_result($results); // now process all back into $values_r for ($i = 0; $i < count($values_r); $i++) { if (!in_array($values_r[$i], $found_entries_r) && !in_array($values_r[$i], $new_values_r)) { $new_values_r[] = $values_r[$i]; } } $values_r = $new_values_r; } //if($results) // now reassign back. $site_item_attributes_r[strtolower($s_attribute_type)] = $values_r; } else { // the next process prefers arrays to deal with, even if single element $site_item_attributes_r[strtolower($s_attribute_type)] = $value; } } // // now that we have expanded mappings, we need to map to s_item_attribute_type order number mappings // $new_attributes_r = $site_item_attributes_r; $site_item_attributes_r = NULL; // now we want to expand the $new_attributes_r, so we have a set of // variables that include the order_no $fieldname type format. $results = fetch_item_attribute_type_rs($s_item_type, NULL, 's_attribute_type'); if ($results) { // this will be set if array encountered, but not lookup value. $processing_s_attribute_type = FALSE; while ($attribute_type_r = db_fetch_assoc($results)) { $variable = strtolower($attribute_type_r['s_attribute_type']); if (isset($new_attributes_r[$variable])) { $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); if (is_not_empty_array($new_attributes_r[$variable])) { // TODO: Consider adding values not found in the lookup table to the s_attribute_type_lookup. if (is_lookup_attribute_type($attribute_type_r['s_attribute_type'])) { $lookup_attribute_val_restrict_ind = $lookup_attribute_val_restrict_ind_r[strtolower($attribute_type_r['s_attribute_type'])]; // here is where we want some sanity checking of the options $value_r = $new_attributes_r[$variable]; $lookup_value_r = array(); for ($i = 0; $i < count($value_r); $i++) { $raw_value = trim($value_r[$i]); if (strlen($raw_value) > 0) { $value = fetch_attribute_type_lookup_value($attribute_type_r['s_attribute_type'], $raw_value); if ($value !== FALSE) { $lookup_value_r[] = $value; } else { if ($lookup_attribute_val_restrict_ind != 'Y') { // do not include if restricted to lookup values $lookup_value_r[] = $raw_value; } } } } $site_item_attributes_r[$fieldname] = array_unique($lookup_value_r); } else { // This indicates we have a repeated s_attribute_type, and so should act appropriately. if ($processing_s_attribute_type != NULL && $attribute_type_r['s_attribute_type'] == $processing_s_attribute_type) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; // remove it array_splice($new_attributes_r[$variable], 0, 1); } else { if (count($new_attributes_r[$variable]) > 1) { // this is the first occurence of the s_attribute_type, so lets see if its repeated at least once. if (is_numeric(fetch_s_item_attribute_type_next_order_no($s_item_type, $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']))) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; // remove it array_splice($new_attributes_r[$variable], 0, 1); $processing_s_attribute_type = $attribute_type_r['s_attribute_type']; } else { // otherwise just copy the whole thing. $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable]; unset($new_attributes_r[$variable]); } } else { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; unset($new_attributes_r[$variable]); } } } } else { if (!is_array($new_attributes_r[$variable])) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable]; unset($new_attributes_r[$variable]); } } } else { if ($attribute_type_r['s_field_type'] == 'TITLE' && isset($new_attributes_r['title'])) { // in case developer forgot to setup title mapping. $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); $site_item_attributes_r[$fieldname] = $new_attributes_r['title']; } } } //while db_free_result($results); } return $site_item_attributes_r; }