function fieldset_helper_state_manager_get_lookup_id in Fieldset helper 6.2
Same name and namespace in other branches
- 6 fieldset_helper.module \fieldset_helper_state_manager_get_lookup_id()
- 7.2 fieldset_helper.module \fieldset_helper_state_manager_get_lookup_id()
Get the lookup id for the $element_id in the current path.
Parameters
$element_id: The DOM element id.
Return value
The numeric auto generated look up id for the $element_id. If $element_id is not set then the entire lookup id table for the current page will returned.
2 calls to fieldset_helper_state_manager_get_lookup_id()
- fieldset_helper_preprocess_page in ./
fieldset_helper.theme.inc - Implementation of hook_preprocess_page().
- fieldset_helper_state_manager_get_state in ./
fieldset_helper.module - Get fieldset's collapsed state.
File
- ./
fieldset_helper.module, line 305
Code
function fieldset_helper_state_manager_get_lookup_id($element_id = NULL) {
static $lookup_id_table;
$path = fieldset_helper_state_manager_get_path();
// Load existing lookup ids for the current path from the database.
if (!isset($lookup_id_table)) {
// Fetch lookup records for the current path. Use sorting to make sure global path (*) are last.
$query = "SELECT id, element_id FROM {fieldset_helper_state_manager} WHERE path='%s' OR path='*' ORDER BY path DESC ";
$result = db_query($query, $path);
while ($data = db_fetch_array($result)) {
$lookup_id_table[$data['element_id']] = $data['id'];
}
}
// Create a new lookup id for element_id's not associated with the lookup id table.
if ($element_id != NULL && !isset($lookup_id_table[$element_id])) {
// Get element path.
$element_path = fieldset_helper_state_manager_get_element_path($element_id, $path);
// Get id for path and element_id combination.
$sql = "INSERT INTO {fieldset_helper_state_manager} (path, element_id) VALUES ('%s', '%s')";
db_query($sql, $element_path, $element_id);
$lookup_id = db_last_insert_id('fieldset_helper_state_manager', 'id');
$lookup_id_table[$element_id] = $lookup_id;
}
// Return the look up id for the element id.
return $element_id == NULL ? $lookup_id_table : $lookup_id_table[$element_id];
}