You are here

function mobile_tools_roles_info in Mobile Tools 5

Same name and namespace in other branches
  1. 6 mobile_tools_roles.inc \mobile_tools_roles_info()
  2. 7.2 mobile_tools_roles/mobile_tools_roles.module \mobile_tools_roles_info()
  3. 7.2 mobile_tools_roles/mobile_tools_roles.inc \mobile_tools_roles_info()

Function helping in getting information for each role:

Parameters

$identifier: array('id' => id) or array('name' => name)

Return value

a $role object with the folowing info $role->id $role->name $role->type = mobile/desktop $role->sibling[id] $role->sibling[name]

6 calls to mobile_tools_roles_info()
mobile_tools_roles_configuration_form in ./mobile_tools.module
Configuration form for configuring the mobile context in the permission system
mobile_tools_roles_configuration_form_submit in ./mobile_tools.module
Implementation of hook_submit().
mobile_tools_roles_configuration_submit in ./mobile_tools.module
Implementation of hook_submit()
mobile_tools_roles_init in ./mobile_tools.module
Being called in the hook_init() implementation This function is in charge of changing the user role
mobile_tools_user in ./mobile_tools.module
Implementation of the user_load function to assure that the right role is being assigned to the user. This is the same actions as in the hook_init() method

... See full list

File

./mobile_tools.module, line 1018
Mobile Tools provides a range of functionality assisting in creating a mobile drupal site . this functionality contains:

Code

function mobile_tools_roles_info($identifier) {
  if (array_key_exists('id', $identifier)) {
    $query = "SELECT * FROM {role} WHERE rid = %d";
    $result = db_query($query, $identifier['id']);
    $name = db_fetch_object($result)->name;
    $rid = $identifier['id'];
  }
  else {
    if (array_key_exists('name', $identifier)) {
      $query = "SELECT * FROM {role} WHERE name = '%s'";
      $result = db_query($query, $identifier['name']);
      $rid = db_fetch_object($result)->rid;
      $name = $identifier['name'];
    }
  }
  $role->id = $rid;
  $role->name = $name;
  $query = "SELECT COUNT(*) as count, mrid FROM {mobile_tools_roles_relations} WHERE rid = %d GROUP BY mrid";
  $result = db_query($query, $rid);
  $item = db_fetch_object($result);
  if ($item->count != 0) {
    $role->type = 'desktop';
    $role->has_sibling = 1;
    $result = db_query("SELECT * FROM {role} WHERE rid = %d", $item->mrid);
    $sibling = db_fetch_object($result);
  }
  else {
    $result = db_query("SELECT COUNT(*) as count, rid FROM {mobile_tools_roles_relations} WHERE mrid = %d GROUP BY rid", $rid);
    $item = db_fetch_object($result);
    if ($item->count == 0) {
      $role->has_sibling = 0;
      $role->type = 'desktop';
    }
    else {
      $role->type = 'mobile';
      $role->has_sibling = 1;
      $result = db_query("SELECT * FROM {role} WHERE rid = %d", $item->rid);
      $sibling = db_fetch_object($result);
    }
  }
  $role->sibling['id'] = $sibling->rid;
  $role->sibling['name'] = $sibling->name;
  return $role;
}