function tripal_core_update_property
2.x tripal_core.DEPRECATED.api.inc | tripal_core_update_property($basetable, $record_id, $property,
$cv_name, $value, $insert_if_missing = 0) |
3.x tripal_core.DEPRECATED.inc | tripal_core_update_property($basetable, $record_id, $property,
$cv_name, $value, $insert_if_missing = 0) |
1.x tripal_core_chado.api.inc | tripal_core_update_property($basetable, $record_id, $property,
$cv_name, $value, $insert_if_missing = 0) |
Update a property for a given base table record and property name. This function should be used only if one record of the property will be present. If the property name can have multiple entries (with increasing rank) then use the function named tripal_core_update_property_by_id
Parameters
$basetable: The base table for which the property should be updated. The property table is constructed using a combination of the base table name and the suffix 'prop' (e.g. basetable = feature then property tabie is featureprop).
$record_id: The foreign key of the basetable to update a property for. This should be in integer. For example, if the basetable is 'feature' then the $record_id should be the feature_id
$property: The cvterm name of property to be updated
$cv_name: The name of the cv that the above cvterm is part of
$value: The value of the property to be inserted (can be empty)
$insert_if_missing: A boolean indicating whether a record should be inserted if one doesn't exist to update
Note: The property to be updated is select via the unique combination of $record_id and $property and then it is updated with the supplied value
Return value
Return True on Update/Insert and False otherwise
Related topics
- tripal_analysis_update_property in tripal_analysis/
api/ tripal_analysis.api.inc - Update a given property
- tripal_contact_update_property in tripal_contact/
api/ tripal_contact.api.inc - Update a given property
- tripal_core_insert_property in tripal_core/
api/ tripal_core_chado.api.inc - Insert a property for a given base table. By default if the property already exists a new property is added with the next available rank. If $update_if_present argument is specified then the record will be updated if it exists rather than adding a…
- tripal_featuremap_update_property in tripal_featuremap/
api/ tripal_featuremap.api.inc - Update a given property
- tripal_feature_analysis_update_property in tripal_feature/
api/ tripal_feature.api.inc - Update an analysis feature property using the property name. Use this when a property only exists once for a given analysis feature. When more than one value can exist for the same property use the tripal_feature_analysis_update_property_by_id()…
File
- tripal_core/
api/ tripal_core_chado.api.inc, line 2723 - The Tripal Core API
Code
function tripal_core_update_property($basetable, $record_id, $property,
$cv_name, $value, $insert_if_missing = 0) {
// first see if the property is missing (we can't update a missing property
$prop = tripal_core_get_property($basetable, $record_id, $property, $cv_name);
if (count($prop) == 0) {
if ($insert_if_missing) {
return tripal_core_insert_property($basetable, $record_id, $property, $cv_name, $value);
}
else {
return FALSE;
}
}
// get the foreign key for this property table
$table_desc = tripal_core_get_chado_table_schema($basetable . 'prop');
$fkcol = key($table_desc['foreign keys'][$basetable]['columns']);
// construct the array that will match the exact record to update
$match = array(
$fkcol => $record_id,
'type_id' => array(
'cv_id' => array(
'name' => $cv_name,
),
'name' => $property,
),
);
// construct the array of values to be updated
$values = array(
'value' => $value,
);
return tripal_core_chado_update($basetable . 'prop', $match, $values);
}