function tmgmt_local_abilities

Gets language abilities.

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 abilities with following data:

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

File

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

Code

function tmgmt_local_abilities($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 = \Drupal::database()
    ->select('user__tmgmt_translation_skills', 'ts')
    ->fields('ts', array(
    'tmgmt_translation_skills_language_from',
    'tmgmt_translation_skills_language_to',
  ))
    ->condition('ts.deleted', 0);
  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_field_data', 'u', 'u.uid = ts.entity_id AND u.status = 1');
  $query
    ->fields('u', array(
    'uid',
    'name',
    'mail',
  ));
  if (!empty($uids)) {
    $query
      ->condition('u.uid', (array) $uids, 'IN');
  }

  // 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('user__roles', 'ur', "ur.entity_id = u.uid AND ur.roles_target_id 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();
}