You are here

function oa_core_get_nids_title_matching in Open Atrium Core 7.2

Get the nids => title matching criteria from a set of nids.

Parameters

int[] $nids: The NIDs of the nodes to check.

string|NULL $bundle: (optional) The node type (default: OA_SPACE_TYPE). If NULL is passed, it will include all node types. Can also be an array of types.

int|NULL $status: (optional) If specified, the node status (ex. NODE_PUBLISHED or NODE_NOT_PUBLISHED) to look for. If not specified, it return nodes of either status.

bool $include_archived: (optional) Whether to include archived nodes or not. By default, archived items aren't included.

stdClass|NULL $account: (optional) the account used to check access to the results. Defaults to the current user.

Return value

array Array of parent NIDs to title.

1 call to oa_core_get_nids_title_matching()
oa_core_get_parents_with_titles in includes/oa_core.util.inc
Get parent Spaces and Groups.

File

includes/oa_core.util.inc, line 364
Code for Utility functions for OpenAtrium spaces

Code

function oa_core_get_nids_title_matching($nids, $bundle = OA_SPACE_TYPE, $status = NULL, $include_archived = FALSE, $account = NULL) {
  if (is_numeric($account)) {
    $account = user_load($account);
  }
  elseif (!$account) {
    global $user;
    $account = $user;
  }
  sort($nids);
  $cid = implode(':', $nids);
  if (is_array($bundle)) {
    $cid .= implode(':', $bundle);
  }
  elseif (!empty($bundle)) {
    $cid .= ':' . $bundle;
  }
  $cid .= ':' . $status . ':' . $include_archived . ':' . $account->uid;
  $cache =& drupal_static(__FUNCTION__, array());
  if (!isset($cache[$cid])) {
    $query = db_select('node', 'n');
    if ($bundle) {
      $query
        ->condition('n.type', $bundle);
    }
    if (isset($status)) {
      $query
        ->condition('n.status', $status);
    }
    $query
      ->condition('n.nid', $nids);
    $query
      ->fields('n', array(
      'nid',
      'title',
    ))
      ->addTag('node_access')
      ->addMetaData('account', $account);
    if (module_exists('oa_archive') && !$include_archived) {
      if ($flag = flag_get_flag('trash')) {
        $query
          ->leftJoin('flagging', 'a', "a.fid = :fid AND a.entity_id = n.nid", array(
          ':fid' => $flag->fid,
        ));

        // This makes sure that archived content isn't included, because 'uid'
        // will be NULL if the join didn't connect anything.
        $query
          ->isNull('a.uid');
      }
    }
    $cache[$cid] = $query
      ->execute()
      ->fetchAllKeyed();
  }
  return $cache[$cid];
}