You are here

function pmorganization_build_node_index in Drupal PM (Project Management) 7.3

Same name and namespace in other branches
  1. 8 pmorganization/pmorganization.module \pmorganization_build_node_index()

Builds and inserts pmorganization index entries for a given node.

The index lists all terms that are related to a given node entity, and is therefore maintained at the entity level.

Parameters

object $node: The node object.

Related topics

3 calls to pmorganization_build_node_index()
pmorganization_node_insert in pmorganization/pmorganization.module
Implements hook_node_insert().
pmorganization_node_update in pmorganization/pmorganization.module
Implements hook_node_update().
pmorganization_update_7301 in pmorganization/pmorganization.install
Build pmorganization_index for all nodes.

File

pmorganization/pmorganization.module, line 145
Main module file for PM Organization.

Code

function pmorganization_build_node_index($node) {

  // We maintain a denormalized table of term/node relationships, containing
  // only data for current, published nodes.
  $status = NULL;
  if (variable_get('pmorganization_maintain_index_table', TRUE)) {

    // If a node property is not set in the node object when node_save() is
    // called, the old value from $node->original is used.
    if (!empty($node->original)) {
      $status = (int) (!empty($node->status) || !isset($node->status) && !empty($node->original->status));
    }
    else {
      $status = (int) (!empty($node->status));
    }
  }

  // We only maintain the pmorganization index for published nodes.
  if ($status) {

    // Hunt for PM Organization.
    $pmorganization_nid = pm_permission_get_parent_nid_of_node($node, 'pmorganization');

    // Insert index entries for all the node's terms.
    if (!empty($pmorganization_nid)) {
      $query = db_insert('pmorganization_index')
        ->fields(array(
        'nid',
        'pmorganization_nid',
        'created',
      ));
      $query
        ->values(array(
        'nid' => $node->nid,
        'pmorganization_nid' => $pmorganization_nid,
        'created' => $node->created,
      ));
      $query
        ->execute();
    }
  }
}