You are here

function mobile_tools_roles_info in Mobile Tools 7.2

Same name in this branch
  1. 7.2 mobile_tools_roles/mobile_tools_roles.module \mobile_tools_roles_info()
  2. 7.2 mobile_tools_roles/mobile_tools_roles.inc \mobile_tools_roles_info()
Same name and namespace in other branches
  1. 5 mobile_tools.module \mobile_tools_roles_info()
  2. 6 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]

14 calls to mobile_tools_roles_info()
mobile_tools_mobile_user_roles in mobile_tools_roles/mobile_tools_roles.module
Helper function to return the mobile user roles
mobile_tools_mobile_user_roles in mobile_tools_roles/mobile_tools_roles.inc
Helper function to return the mobile user roles
mobile_tools_roles_boot in mobile_tools_roles/mobile_tools_roles.module
Being called in the hook_init() implementation This function is in charge of changing the user role
mobile_tools_roles_boot in mobile_tools_roles/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/mobile_tools_roles.module
Configuration form for configuring the mobile context in the permission system

... See full list

File

mobile_tools_roles/mobile_tools_roles.module, line 181
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("SELECT * FROM {role} WHERE rid = :rid", array(
      ':rid' => $identifier['id'],
    ));
    $record = $result
      ->fetchObject();
    $name = $record->name;
    $rid = $identifier['id'];
  }
  elseif (array_key_exists('name', $identifier)) {
    $query = "SELECT * FROM {role} WHERE name = '%s'";
    $result = db_query("SELECT * FROM {role} WHERE name = :name", array(
      ':name' => $identifier['name'],
    ));
    $record = $result
      ->fetchObject();
    $rid = $record->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("SELECT COUNT(*) as count, mrid FROM {mobile_tools_roles_relations} WHERE rid = :rid GROUP BY mrid", array(
    ':rid' => $rid,
  ));
  $item = $result
    ->fetchObject();
  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 = :rid", array(
      ':rid' => $item->mrid,
    ));
    $sibling = $result
      ->fetchObject();
  }
  else {
    $result = db_query("SELECT COUNT(*) as count, rid FROM {mobile_tools_roles_relations} WHERE mrid = :mrid GROUP BY rid", array(
      ':mrid' => $rid,
    ));
    $item = $result
      ->fetchObject();
    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 = :rid", array(
        ':rid' => $item->rid,
      ));
      $sibling = $result
        ->fetchObject();
    }
  }
  if (isset($sibling)) {
    $role->sibling['id'] = $sibling->rid;
    $role->sibling['name'] = $sibling->name;
  }
  return $role;
}