You are here

public function TMGMTLocalTranslatorPluginController::getSupportedLanguagePairs in Translation Management Tool 7

Default implementation that gets target languages for each remote language. This approach is ineffective and therefore it is advised that a plugin should provide own implementation.

Overrides TMGMTDefaultTranslatorPluginController::getSupportedLanguagePairs

File

translators/tmgmt_local/includes/tmgmt_local.plugin.inc, line 57
Provides the user translator plugin controller.

Class

TMGMTLocalTranslatorPluginController
Local translator plugin controller.

Code

public function getSupportedLanguagePairs(TMGMTTranslator $translator) {
  if (!empty($this->language_pairs)) {
    return $this->language_pairs;
  }
  $roles = user_roles(TRUE, 'provide translation services');
  $query = db_select('field_data_tmgmt_translation_skills', 'ts');
  $query
    ->join('users', 'u', 'u.uid = ts.entity_id AND u.status = 1');
  $query
    ->addField('ts', 'tmgmt_translation_skills_language_from', 'source_language');
  $query
    ->addField('ts', 'tmgmt_translation_skills_language_to', 'target_language');
  $query
    ->condition('ts.deleted', 0);
  $query
    ->condition('ts.entity_type', 'user');
  if (!in_array(DRUPAL_AUTHENTICATED_RID, array_keys($roles))) {
    $query
      ->join('users_roles', 'ur', 'ur.uid = u.uid AND ur.rid');
    $or_conditions = db_or()
      ->condition('ur.rid', array_keys($roles))
      ->condition('u.uid', 1);
    $query
      ->condition($or_conditions);
  }
  foreach ($query
    ->execute()
    ->fetchAll() as $item) {
    $this->language_pairs[] = array(
      'source_language' => $item->source_language,
      'target_language' => $item->target_language,
    );
  }
  return $this->language_pairs;
}