You are here

function mobile_tools_roles_info in Mobile Tools 6

Same name and namespace in other branches
  1. 5 mobile_tools.module \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]

7 calls to mobile_tools_roles_info()
mobile_tools_mobile_user_roles in ./mobile_tools_roles.inc
Helper function to return the mobile user roles
mobile_tools_roles_boot in ./mobile_tools_roles.inc
Being called in the hook_init() implementation This function is in charge of changing the user role
mobile_tools_roles_configuration_form in ./mobile_tools_roles.inc
Configuration form for configuring the mobile context in the permission system
mobile_tools_roles_configuration_submit in ./mobile_tools_roles.inc
Submit handler for the roles configuration form. It organises the mobile context for each user role.
mobile_tools_roles_settings_submit in ./mobile_tools_roles.inc
Submit function for the mobile tools / mobile roles configuration page

... See full list

File

./mobile_tools_roles.inc, line 157
Contains the functionality to add mobile user roles

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'];
  }
  elseif (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 (is_object($item)) {
    $count = $item->count;
  }
  else {
    $count = 0;
  }
  if ($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 ($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);
    }
  }
  if (isset($sibling)) {
    $role->sibling['id'] = $sibling->rid;
    $role->sibling['name'] = $sibling->name;
  }
  return $role;
}