You are here

function tmgmt_local_assignees in Translation Management Tool 8

Gets local assignees for given language combination.

Parameters

string $source_language: (optional) Source language to limit on.

array $target_languages: (optional) List of target languages to limit to.

Return value

array Array of uid => name assignees or empty array if there are no assignees.

4 calls to tmgmt_local_assignees()
LocalTaskForm::form in translators/tmgmt_local/src/Form/LocalTaskForm.php
Gets the actual form array to be built.
LocalTranslatorTest::testAbilitiesAPI in translators/tmgmt_local/tests/src/Functional/LocalTranslatorTest.php
LocalTranslatorUi::checkoutSettingsForm in translators/tmgmt_local/src/LocalTranslatorUi.php
Form callback for the checkout settings form.
tmgmt_local_get_assignees_for_tasks in translators/tmgmt_local/tmgmt_local.module
Gets users able to translate all given tasks.

File

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

Code

function tmgmt_local_assignees($source_language = NULL, array $target_languages = array()) {
  $assignees =& drupal_static(__FUNCTION__);
  $key = $source_language . '_' . implode('_', $target_languages);
  if (isset($assignees[$key])) {
    return $assignees[$key];
  }

  // Get all abilities keyed by uids for given source language.
  $assignees_abilities = array();
  foreach (tmgmt_local_abilities($source_language) as $row) {
    $assignees_abilities[$row->uid][] = $row->tmgmt_translation_skills_language_to;
  }

  // Filter out assignees uids who's abilities are not sufficient for given
  // target languages.
  $assignees_uids = array();
  foreach ($assignees_abilities as $uid => $abilities) {

    // In case provided target languages exceed users abilities, exclude.
    if (!empty($target_languages) && count(array_diff($target_languages, $abilities)) > 0) {
      continue;
    }
    $assignees_uids[] = $uid;
  }

  // Finally build the assignees list.
  $assignees[$key] = array();
  if (!empty($assignees_uids)) {
    foreach (User::loadMultiple($assignees_uids) as $account) {
      $assignees[$key][$account
        ->id()] = $account
        ->getDisplayName();
    }
  }
  return $assignees[$key];
}