You are here

function nodereferrer_referrers in NodeReferrer 5

Same name and namespace in other branches
  1. 6 nodereferrer.module \nodereferrer_referrers()
  2. 7 nodereferrer.module \nodereferrer_referrers()

Get an array of referrer nids, by node.type & field.type

Parameters

nid: the nid we want to find referres for

fieldnames : array of fieldnames to be checked for referrers

nodetypes: array of node types to be checked for referrers

6 calls to nodereferrer_referrers()
nodereferrer_field in ./nodereferrer.module
Implementation of hook_field().
nodereferrer_nodeapi in ./nodereferrer.module
Implementation of hook_nodeapi
nodereferrer_view_handler_argument_field_filter in ./nodereferrer.module
nodereferrer_view_handler_argument_type_filter in ./nodereferrer.module
nodereferrer_view_handler_filter_field in ./nodereferrer.module

... See full list

File

./nodereferrer.module, line 260
Defines a field type for backlinking referencing nodes. @todo -clear content cache with nodeapi. -query nids for access on load/view..

Code

function nodereferrer_referrers($nid, $fieldnames = array(), $nodetypes = array(), $order = 'DESC') {
  if ($nodetypes) {
    $filter_nodetypes = "AND n.type IN ('" . implode("', '", $nodetypes) . "')";
  }
  $fields = content_fields();

  // Set default values of fieldnames..
  if (!count($fieldnames)) {
    $fieldnames = array_keys($fields);
  }
  switch ($order) {
    case 'TITLE_ASC':
      $order = 'n.title ASC';
      break;
    case 'TITLE_DESC':
      $order = 'n.title DESC';
      break;
    case 'ASC':
    case 'CREATED_ASC':
      $order = 'n.created ASC';
      break;
    default:
    case 'DESC':
    case 'CREATED_DESC':
      $order = 'n.created DESC';
      break;
  }
  $values = array();
  foreach ($fieldnames as $fieldname) {
    if ($fields[$fieldname]['type'] == 'nodereference') {
      $db_info = content_database_info($fields[$fieldname]);
      $query = "SELECT       n.nid, n.vid, n.title\n                FROM         {" . $db_info['table'] . "} nr\n                INNER JOIN   {node} n ON n.vid = nr.vid AND n.status = 1 " . $filter_nodetypes . "\n                WHERE        nr." . $db_info['columns']['nid']['column'] . " = %d\n                ORDER BY     " . $order;
      $query = db_rewrite_sql($query);
      $result = db_query($query, $nid);
      while ($value = db_fetch_array($result)) {

        // avoid duplicate referrers by using nid as key
        $values[$value['nid']] = $value;
      }
    }
  }
  return $values;
}