function user_relationships_type_save in User Relationships 5.3
Same name and namespace in other branches
- 6 user_relationships_api/user_relationships_api.api.inc \user_relationships_type_save()
- 7 user_relationships.module \user_relationships_type_save()
Create or Update a User Relationship Type
Parameters
$rtype: A User Relationship type object
1 call to user_relationships_type_save()
- user_relationships_ui_type_edit_form_submit in user_relationships_ui/
user_relationships_ui.actions.inc - Process the relationship edit page form submission.
File
- user_relationships_api/
user_relationships_api.api.inc, line 84
Code
function user_relationships_type_save(&$rtype) {
_user_relationships_invoke('presave', $rtype, TRUE);
$op = $rtype->rtid ? 'update' : 'insert';
// find a relationship type with the name we're trying to save
// if it's an update action check to see that the rtypes match
// otherwise it's just invalid
if (($found_rt = user_relationships_type_load(array(
'name' => $rtype->name,
))) && ($op == 'update' ? $found_rt->rtid != $rtype->rtid : TRUE)) {
return FALSE;
}
// ensure "expires_val" is numeric and not negative
if (!is_numeric($rtype->expires_val) || $rtype->expires_val < 0) {
$rtype->expires_val = 0;
}
if ($op == 'update') {
db_query("UPDATE {user_relationship_types} SET \n name = '%s', plural_name = '%s', is_oneway = %d, requires_approval = %d, expires_val = %d\n WHERE rtid = %d", $rtype->name, $rtype->plural_name, $rtype->is_oneway ? 1 : 0, $rtype->requires_approval ? 1 : 0, $rtype->expires_val, $rtype->rtid);
}
else {
$rtype->rtid = db_next_id('{user_relationship_types}_id');
db_query("INSERT INTO {user_relationship_types} (rtid, name, plural_name, is_oneway, requires_approval, expires_val)\n VALUES(%d, '%s', '%s', %d, %d, %d)", $rtype->rtid, $rtype->name, $rtype->plural_name, $rtype->is_oneway ? 1 : 0, $rtype->requires_approval ? 1 : 0, $rtype->expires_val);
}
_user_relationships_invoke($op, $rtype, TRUE);
}