You are here

function oa_comment_find_paragraph_ids in OA Comment 7.2

Given an ID, find all the paragraph IDS for it.

Parameters

$nid: The NID of the content to find paragraph ids for.

Return value

An array with 'node' key with value of ids on node, second 'comment' with ids from the comments.

2 calls to oa_comment_find_paragraph_ids()
oa_comment_views_pre_build in ./oa_comment.module
Implements hook_views_pre_build().
views_handler_argument_oa_comment_paragraph_and_current_ids::query in views/views_handler_argument_oa_comment_paragraph_and_current_ids.inc
Set up the query for this argument.

File

./oa_comment.module, line 400

Code

function oa_comment_find_paragraph_ids($nid) {
  $ids =& drupal_static(__FUNCTION__);
  if (!isset($ids[$nid])) {
    $ids[$nid] = array(
      'node' => array(),
      'comment' => array(),
    );
    $node = node_load($nid);

    // drupal has this cached
    if (!empty($node) && ($paragraphs = field_get_items('node', $node, 'field_oa_related'))) {
      foreach ($paragraphs as $item) {
        $ids[$nid]['node'][] = $item['value'];
      }
    }

    // Query the comment table to find paragraph ids.
    $query = db_select('field_data_field_oa_related', 'r');
    $query
      ->condition('r.deleted', 0);
    $query
      ->fields('r', array(
      'field_oa_related_value',
    ));
    $query
      ->join('comment', 'c', "r.entity_type = 'comment' AND r.entity_id = c.cid");
    $query
      ->condition('c.nid', $nid);
    $query
      ->condition('c.status', COMMENT_PUBLISHED);
    $paragraph_ids = $query
      ->execute()
      ->fetchCol();
    foreach ($paragraph_ids as $paragraph_id) {
      $ids[$nid]['comment'][] = $paragraph_id;
    }
  }
  return $ids[$nid];
}