function cf_db_options_get_options in Common Functionality 7.2
Get an array of supported options for a given option type.
Parameters
string $table: A machine name that is prefixed onto the table. This is often either the name of the module or the name of the table associated with the options.
string $name: The machine name of the options and is suffixed onto the table.
int|string|null $option: (optional) Providing a valid numeric id or machine name string will cause the return value to only contain the option that matches this string or numeric id.
Return value
array An array of supported options. The array keys are the machine names for each option.
Related topics
3 calls to cf_db_options_get_options()
- cf_db_options_get_options_list in modules/
cf_db_options/ cf_db_options.module - Returns a list of options.
- cf_settings_get_variable_types in modules/
cf_settings/ cf_settings.module - Get an array of supported variable type options.
- cf_settings_register in modules/
cf_settings/ cf_settings.module - Add a variable name and type to the variables registry.
File
- modules/
cf_db_options/ cf_db_options.module, line 288 - Common Functionality - Database Options module.
Code
function cf_db_options_get_options($table, $name, $option = NULL) {
if (!is_null($option) && cf_is_empty_or_non_string('name', $name, WATCHDOG_ERROR)) {
return array();
}
$options_table = cf_db_options_get_options_name($table, $name);
if ($options_table === FALSE) {
return array();
}
// $options_table is a database table name, so only allow lowercase characters and underscores
if (preg_match('/^(\\w|_)+$/', $options_table) == 0) {
return array();
}
$options =& drupal_static(__FUNCTION__, NULL);
if (isset($options[$options_table])) {
if (!is_null($option)) {
if (is_numeric($option)) {
foreach ($options[$options_table] as $key => &$value) {
if ($value->id == $option) {
return $options[$options_table][$key];
}
}
}
else {
if (isset($options[$options_table][$option])) {
return $options[$options_table][$option];
}
}
return array();
}
return $options[$options_table];
}
$query = db_select($options_table, 'ot');
$query
->fields('ot');
$query
->orderBy('ot.id', 'ASC');
try {
$records = $query
->execute()
->fetchAll();
} catch (Exception $e) {
if (class_exists('cf_error')) {
cf_error::on_query_execution($e);
}
throw $e;
return array();
}
$options[$options_table] = array();
foreach ($records as &$record) {
if (!is_object($record)) {
continue;
}
$options[$options_table][$record->machine_name] =& $record;
}
if (!is_null($option)) {
if (is_numeric($option)) {
foreach ($options[$options_table] as $key => &$value) {
if ($value->id == $option) {
return $options[$options_table][$key];
}
}
}
else {
if (isset($options[$options_table][$option])) {
return $options[$options_table][$option];
}
}
return array();
}
return $options[$options_table];
}