You are here

function tmgmt_local_capabilities in Translation Management Tool 7

Gets language capabilities.

Parameters

string $source_language: (optional) Limit the source language.

string $target_language: (optional) Limit the target language.

array $uids: (optional) Limit to specific users.

Return value

array Array of language capabilities with following data:

  • tmgmt_translation_skills_language_from
  • tmgmt_translation_skills_language_to
  • uid
  • name
  • mail
2 calls to tmgmt_local_capabilities()
tmgmt_local_supported_language_pairs in translators/tmgmt_local/tmgmt_local.module
Gets list of language pairs.
tmgmt_local_translators in translators/tmgmt_local/tmgmt_local.module
Gets local translator for given language combination.

File

translators/tmgmt_local/tmgmt_local.module, line 827
Main module file for the local translation module.

Code

function tmgmt_local_capabilities($source_language = NULL, $target_language = NULL, $uids = array()) {
  $roles = tmgmt_local_translator_roles();

  // If there are no roles that have the required permission, return an empty
  // array.
  if (empty($roles)) {
    return array();
  }
  $query = db_select('field_data_tmgmt_translation_skills', 'ts')
    ->fields('ts', array(
    'tmgmt_translation_skills_language_from',
    'tmgmt_translation_skills_language_to',
  ))
    ->condition('ts.deleted', 0)
    ->condition('ts.entity_type', 'user');
  if ($source_language) {
    $query
      ->condition('ts.tmgmt_translation_skills_language_from', $source_language);
  }
  if ($target_language) {
    $query
      ->condition('ts.tmgmt_translation_skills_language_to', $target_language);
  }

  // Join only active users.
  $query
    ->innerJoin('users', 'u', 'u.uid = ts.entity_id AND u.status = 1');
  $query
    ->fields('u', array(
    'uid',
    'name',
    'mail',
  ));
  if (!empty($uids)) {
    $query
      ->condition('u.uid', $uids);
  }

  // If the authenticated user role has the required permission we do not have
  // to do the role check.
  if (!in_array('authenticated user', $roles)) {
    $query
      ->leftJoin('users_roles', 'ur', "ur.uid = u.uid AND ur.rid IN (:roles)", array(
      ':roles' => array_keys($roles),
    ));
  }

  // Add a tag so other modules can alter this query at will.
  $query
    ->addTag('tmgmt_translation_combination');
  return $query
    ->execute()
    ->fetchAll();
}