You are here

function flag_lists_get_content_fids in Flag Lists 6

Same name and namespace in other branches
  1. 7.3 flag_lists.module \flag_lists_get_content_fids()
  2. 7 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 314
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_result(db_query("SELECT type from {node} WHERE nid = %d", arg(1)));

    // Get current user's flags for this node.
    $fc_result = db_query("SELECT f.fid\n        FROM {flag_lists} fc\n        LEFT JOIN {flag_types} fn ON fn.fid = fc.fid\n        LEFT JOIN {flags} f ON fc.fid = f.fid\n        WHERE fc.uid = %d\n        AND fn.type = '%s'", $user->uid, $type);
    while ($row = db_fetch_array($fc_result)) {
      $fids[] = $row['fid'];
    }
  }
  elseif (arg(0) == 'flag' && (arg(1) == 'flag' || arg(1) == 'unflag')) {

    // Get the flag for this request.
    $fids[] = db_result(db_query("SELECT f.fid\n        FROM {flags} f\n        WHERE f.name = '%s'", arg(2)));
  }

  // 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.
  $f_result = db_query("SELECT f.fid\n        FROM {flags} f\n        LEFT JOIN {flag_lists} fc ON fc.fid = f.fid\n        WHERE fc.fid IS NULL");
  while ($row = db_fetch_array($f_result)) {
    $fids[] = $row['fid'];
  }
  if (is_array($fids)) {
    return array_unique($fids);
  }
  else {
    return array();
  }
}