function tmgmt_local_translation_access in Translation Management Tool 7
Same name and namespace in other branches
- 8 translators/tmgmt_local/tmgmt_local.module \tmgmt_local_translation_access()
Determine whether the current user is allowed to translate a given translation task.
Parameters
$task: The translation task to be translated.
$account: (Optional) A user object representing the user that is trying to obtain translation access. Determines access for a user other than the current user.
Return value
bool TRUE if the user is allowed to translate the given translation job, FALSE otherwise.
1 call to tmgmt_local_translation_access()
- tmgmt_local_task_handler_field_operations::render in translators/
tmgmt_local/ views/ handlers/ tmgmt_local_task_handler_field_operations.inc - Render the field.
1 string reference to 'tmgmt_local_translation_access'
- tmgmt_local_menu in translators/
tmgmt_local/ tmgmt_local.module - Implements hook_menu().
File
- translators/
tmgmt_local/ tmgmt_local.module, line 257 - Main module file for the local translation module.
Code
function tmgmt_local_translation_access(TMGMTLocalTask $task, $account = NULL) {
$job = $task
->getJob();
if (!$job || !$job
->isActive()) {
return FALSE;
}
$rights =& drupal_static(__FUNCTION__);
// If no user object is supplied, the access check is for the current user.
if (empty($account)) {
$account = $GLOBALS['user'];
}
// If we've already checked access for this job and user, return from cache.
if (isset($rights[$account->uid][$job->tjid])) {
return $rights[$account->uid][$job->tjid];
}
// We grant access to the translation if both of the following conditions are
// met:
// - User is assigned as a translator to the given task.
// - User has 'provide translation services' permission.
// - No modules say to deny access.
// - At least one module says to grant access.
// - User has translation capabilities for this task.
if (!user_access('provide translation services')) {
$rights[$account->uid][$job->tjid] = FALSE;
return FALSE;
}
if ($task->tuid == $account->uid) {
$rights[$account->uid][$job->tjid] = TRUE;
return TRUE;
}
$access = module_invoke_all('tmgmt_local_translation_access', $job, $account);
if (in_array(TMGMT_LOCAL_TRANSLATION_ACCESS_DENY, $access, TRUE)) {
$rights[$account->uid][$job->tjid] = FALSE;
return FALSE;
}
elseif (in_array(TMGMT_LOCAL_TRANSLATION_ACCESS_ALLOW, $access, TRUE)) {
$rights[$account->uid][$job->tjid] = TRUE;
return TRUE;
}
// Lastly, check for the translation capabilities.
$target_languages = tmgmt_local_supported_target_languages($job->source_language, array(
$account->uid,
));
$rights[$account->uid][$job->tjid] = in_array($job->target_language, $target_languages);
return $rights[$account->uid][$job->tjid];
}