$name); $options = array('statement_name' => 'sel_contact_na'); $contact = chado_select_record('contact', array('contact_id'), $values, $options); if (count($contact) == 0) { $cvterm = tripal_get_cvterm(array( 'name' => $type, 'cv_id' => array('name' => 'tripal_contact') )); if (!$cvterm) { tripal_report_error('tripal_contact', TRIPAL_ERROR, "Cannot find contact type '%type'", array('%type' => $type)); return FALSE; } $values = array( 'name' => $name, 'description' => '', 'type_id' => $cvterm->cvterm_id, ); $options = array('statement_name' => 'ins_contact_nadety'); $contact = chado_insert_record('contact', $values, $options); if (!$contact) { tripal_report_error('tripal_contact', TRIPAL_ERROR, 'Could not add the contact', array()); return FALSE; } } else { $contact = (array) $contact[0]; } // add the description property. We don't store this in the contact.description // field because it is only 255 characters long and may not be enough if ($description) { chado_insert_property( 'contact', $contact['contact_id'], 'contact_description', 'tripal_contact', $description, TRUE ); } // add in the other properties provided foreach ($properties as $key => $value) { $success = chado_insert_property( 'contact', $contact['contact_id'], $key, 'tripal_contact', $value, TRUE ); if (!$success) { tripal_report_error('tripal_contact', TRIPAL_ERROR, "Could not add the contact property '%prop'", array('%prop' => $key)); return FALSE; } } return $contact; }