You are here

function i18n_access_load_permissions in Translation Access 7

Same name and namespace in other branches
  1. 6 i18n_access.module \i18n_access_load_permissions()

Load the language permissions for a given user

7 calls to i18n_access_load_permissions()
i18nAccessTestCase::setLanguagePermissions in ./i18n_access.test
Sets the language permission for the specified user. Must be logged in as an 'administer users' privileged user before calling this.
i18nAccessTestCase::testAdminUser in ./i18n_access.test
Test admin user. User with 'administer nodes' permission should be able to create and edit nodes regardless of the language
i18nAccessTestCase::testTranslatorUser in ./i18n_access.test
Test translator user. User with 'create story content' and 'edit own story content' permissions should be able to create and edit story nodes only in the languages that they have permissions for.
i18n_access_form_alter in ./i18n_access.module
Implements hook_form_alter().
i18n_access_form_node_form_alter in ./i18n_access.module
Implements hook_form_node_form_alter().

... See full list

File

./i18n_access.module, line 59
file_description

Code

function i18n_access_load_permissions($uid = NULL) {
  static $perms = array();

  // use the global user id if none is passed
  if (!isset($uid)) {
    $uid = $GLOBALS['user']->uid;
    $account = NULL;
  }
  else {
    $account = user_load($uid);
  }
  if (!isset($perms[$uid])) {
    $perm_string = db_query('SELECT perm FROM {i18n_access} WHERE uid = :uid', array(
      ':uid' => $uid,
    ))
      ->fetchField();
    if ($perm_string) {
      $perms[$uid] = drupal_map_assoc(explode(', ', $perm_string));
    }
    else {
      $perms[$uid] = array();
    }
  }

  // adding the default languages if permission has been granted
  if (user_access('access selected languages', $account)) {
    $perms[$uid] = array_merge($perms[$uid], drupal_map_assoc(variable_get('i18n_access_languages', array())));
  }
  return $perms[$uid];
}