function chado_node_get_unique_constraint_format
2.x tripal_core.chado_nodes.title_and_path.api.inc | chado_node_get_unique_constraint_format($base_table, $format_type = 'title') |
3.x tripal_core.chado_nodes.title_and_path.inc | chado_node_get_unique_constraint_format($base_table, $format_type = 'title') |
Generate the unique constraint for a given base table using the Chado Schema API definition
Parameters
$base_table: The base table to generate the unique constraint format for
$format_type: The type of format to return. This should be one of 'title' or 'url'.
Return value
A format string including tokens describing the unique constraint including all name fields
2 calls to chado_node_get_unique_constraint_format()
- chado_node_get_title_format in tripal_core/
api/ tripal_core.chado_nodes.title_and_path.api.inc - Get the title format for a specific content type
- chado_node_get_url_format in tripal_core/
api/ tripal_core.chado_nodes.title_and_path.api.inc - Get the url format for a specific content type
File
- tripal_core/
api/ tripal_core.chado_nodes.title_and_path.api.inc, line 1207 - Contains API functions to set titles and paths for all chado nodes
Code
function chado_node_get_unique_constraint_format($base_table, $format_type = 'title') {
$table_descrip = chado_get_schema($base_table);
// Find the name/uniquename from the base table
$names = array();
foreach ($table_descrip['fields'] as $field_name => $field) {
if (preg_match('/name/', $field_name)) {
$names[$field_name] = "[$base_table.$field_name]";
}
}
uksort($names, 'tripal_sort_key_length_asc');
// Get tokens to match the unique key
$tokens = array();
foreach ($table_descrip['unique keys'] as $keyset) {
foreach ($keyset as $key) {
if (isset($names[$key])) {
// Do not add it into the tokens if it's already in the names
// since we don't want it repeated 2X
}
elseif ($key == 'type_id') {
$tokens[$key] = "[$base_table.type_id>cvterm.name]";
}
elseif ($key == 'organism_id') {
$tokens[$key] = "[$base_table.organism_id>organism.abbreviation]";
}
else {
$tokens[$key] = "[$base_table.$key]";
}
}
}
if ($format_type == 'title') {
$format = implode(', ', $names) . ' (' . implode(', ', $tokens) . ')';
}
elseif ($format_type == 'url') {
// We don't want to put more than one name in the URL. Thus we are
// arbitrarily grabbing the longest name token since it it likely the
// uniquename.
$format = implode('/', $tokens) . '/' . array_pop($names);
}
else {
$format = FALSE;
tripal_report_error(
'tripal_node_api',
TRIPAL_ERROR,
'Unable to determine the format for the unique contraint since the format type (%format-type) is not supported (only "title" and "url" are at this time).',
array('%format-type' => $format_type)
);
}
return $format;
}