function chado_contact_load

2.x tripal_contact.chado_node.inc chado_contact_load($nodes)
1.x tripal_contact.module chado_contact_load($node)

Implements hook_load().

Parameters

$node: The node that is to be accessed from the database

Return value

$node The node with the information to be loaded into the database

Related topics

File

tripal_contact/includes/tripal_contact.chado_node.inc, line 512
Implements drupal node hooks.

Code

function chado_contact_load($nodes) {

  foreach ($nodes as $nid => $node) {
    // find the contact and add in the details
    $contact_id = chado_get_id_from_nid('contact', $nid);

    // if the nid does not have a matching record then skip this node.
    // this can happen with orphaned nodes.
    if (!$contact_id) {
      continue;
    }

    // get the contact
    $values = array('contact_id' => $contact_id);
    $contact = chado_generate_var('contact', $values);

    // get the contact description from the contactprop table and replace
    // the contact.description field with this one (we don't use the contact.description
    // field because it is only 255 characters (too small)).
    $values = array(
      'contact_id' => $contact->contact_id,
      'type_id' => array(
        'name' => 'contact_description',
      ),
    );
    $options = array(
      'return_array' => 1,
      'include_fk' => array('type_id' => 1),
    );
    $description = chado_generate_var('contactprop', $values, $options);
    if (count($description) == 1) {
      $description = chado_expand_var($description, 'field', 'contactprop.value');
      $contact->description = $description[0]->value;
    }

    $nodes[$nid]->contact = $contact;

    // Now get the title
    $node->title = chado_get_node_title($node);
  }
}