You are here

function pmproject_build_node_index in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 pmproject/pmproject.module \pmproject_build_node_index()

Builds and inserts pmproject 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 pmproject_build_node_index()
pmproject_node_insert in pmproject/pmproject.module
Implements hook_node_insert().
pmproject_node_update in pmproject/pmproject.module
Implements hook_node_update().
pmproject_update_7301 in pmproject/pmproject.install
Build pmproject_index for all nodes.

File

pmproject/pmproject.module, line 241
Main module file for the PM Project module.

Code

function pmproject_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('pmproject_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 pmproject index for published nodes.
  if ($status) {

    // Hunt for PM Organization.
    $pmproject_nid = pm_permission_get_parent_nid_of_node($node, 'pmproject');

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