function tripal_contact_add_contact

2.x tripal_contact_add_contact($name, $description, $type, $properties)
1.x tripal_contact_add_contact($name, $description, $type, $properties)

Adds a contact to the Chado contact table


$name: The name of the contact

$description: Text describing the contact

$type: The type of contact. Must be a term in the tripal_contact vocabulary

$properties: An associative array containing a list of key value pairs for the properites. The key's must be valid terms in the tripal_contact vocabulary (e.g. Affiliation, Address, etc).

Return value

On success, an array is returned containing the fields of the contact record including the newly added contact_id. On failure, FALSE is returned

Related topics

1 call to tripal_contact_add_contact()


tripal_contact/api/, line 113
Provides an application programming interface (API) to manage libraries


function tripal_contact_add_contact($name, $description, $type, $properties) {

  // check to see if this contact name already exists.    
  $values = array('name' => $name);
  $options = array('statement_name' => 'sel_contact_na');
  $contact = tripal_core_chado_select('contact', array('contact_id'), $values, $options);

  if (count($contact) == 0) {
    $cvterm = tripal_cv_get_cvterm_by_name($type, NULL, 'tripal_contact');
    if (!$cvterm) {
      watchdog('tripal_contact', "Cannot find contact type '%type'", 
      array('%type' => $type), WATCHDOG_ERROR);
      return FALSE;
    $values = array(
      'name' => $name,
      'description' => '',
      'type_id' => $cvterm->cvterm_id,
    $options = array('statement_name' => 'ins_contact_nadety');
    $contact = tripal_core_chado_insert('contact', $values, $options);
    if (!$contact) {
      watchdog('tripal_contact', 'Could not add the contact', array(), WATCHDOG_ERROR);
      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) {
    tripal_contact_insert_property($contact['contact_id'], 'contact_description', $description, TRUE);

  // add in the other properties provided
  foreach ($properties as $key => $value) {
    $success = tripal_contact_insert_property($contact['contact_id'], $key, $value, TRUE);
    if (!$success) {
      watchdog('tripal_contact', "Could not add the contact property '%prop'", array('%prop' => $key), WATCHDOG_ERROR);
      return FALSE;
  return $contact;