You are here

function flag_lists_get_content_fids in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.module \flag_lists_get_content_fids()
  2. 7.3 flag_lists.module \flag_lists_get_content_fids()

Helper function to build an array of all lists available to or owned by the current user and that are available on the current content type.

File

./flag_lists.module, line 637
The Flag Lists module.

Code

function flag_lists_get_content_fids() {
  global $user;

  // This is a node view. We only care about nodes for now.
  if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
    $type = db_select('node', 'n')
      ->fields('n', array(
      'type',
    ))
      ->condition('nid', arg(1))
      ->execute()
      ->fetchField();

    // Get current user's flags for this node.
    $query = db_select('flag_lists', 'fc')
      ->fields('f', 'fid')
      ->condition('fc.uid', $user->uid)
      ->condition('fn.type', $type);
    $query
      ->leftJoin('flag_types', 'fn', 'fn.fid = fc.fid');
    $query
      ->leftJoin('flags', 'f', 'fc.fid = f.fid');
    $fc_result = $query
      ->execute();
    foreach ($fc_result as $row) {
      $fids[] = $row->fid;
    }
  }
  elseif (arg(0) == 'flag' && (arg(1) == 'flag' || arg(1) == 'unflag')) {

    // Get the flag for this request.
    $fids[] = db_select('flags', 'f')
      ->fields('f', array(
      'fid',
    ))
      ->condition('name', arg(2))
      ->execute()
      ->fetchField();
  }

  // Get the regular flags for this node. The flag module will narrow by role,
  // etc. when flag_get_flags() is called. These flag ids are always returned.
  $query = db_select('flags', 'f')
    ->fields('f', array(
    'fid',
  ))
    ->condition('fc.fid', NULL);
  $query
    ->leftJoin('flag_lists', 'fc', 'fc.fid = f.fid');
  $f_result = $query
    ->execute();
  foreach ($f_result as $obj) {
    $fids[] = $obj->fid;
  }
  if (is_array($fids)) {
    return array_unique($fids);
  }
  else {
    return array();
  }
}