You are here

function flag_lists_is_owner in Flag Lists 7

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

Helper function to test if a flag is owned by the current user, or current user can administer flags.

2 calls to flag_lists_is_owner()
flag_lists_handler_field_list_delete::render in includes/flag_lists_handler_field_list_delete.inc
Render the field.
flag_lists_handler_field_list_edit::render in includes/flag_lists_handler_field_list_edit.inc
Render the field.
1 string reference to 'flag_lists_is_owner'
flag_lists_menu in ./flag_lists.module
Implementation of hook_menu().

File

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

Code

function flag_lists_is_owner($action, $name) {
  global $user;
  if (user_access('administer flags')) {
    return TRUE;
  }

  // If we don't have an fid, then we have the flag name.
  if (is_numeric($name)) {
    $query = db_select('flag_lists_flags', 'f')
      ->condition('fid', $name);
    $query
      ->addField('f', 'name');
    $name = $query
      ->execute()
      ->fetchField();
  }
  if (!user_access($action . ' own flag lists')) {
    return FALSE;
  }
  if (db_select('flag_lists_flags', 'f')
    ->fields('f')
    ->condition('f.name', $name)
    ->condition('f.uid', $user->uid)
    ->countQuery()
    ->execute()
    ->fetchField()) {
    return TRUE;
  }
  return FALSE;
}