You are here

class TMGMTLocalTranslatorPluginController in Translation Management Tool 7

Local translator plugin controller.

Hierarchy

Expanded class hierarchy of TMGMTLocalTranslatorPluginController

1 string reference to 'TMGMTLocalTranslatorPluginController'
tmgmt_local_tmgmt_translator_plugin_info in translators/tmgmt_local/tmgmt_local.module
Implements hook_tmgmt_translator_plugin_info().

File

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

View source
class TMGMTLocalTranslatorPluginController extends TMGMTDefaultTranslatorPluginController {
  protected $language_pairs = array();

  /**
   * {@inheritdoc}
   */
  public function requestTranslation(TMGMTJob $job) {
    $tuid = $job
      ->getSetting('translator');

    // Create local task for this job.
    $local_task = tmgmt_local_task_create(array(
      'uid' => $job->uid,
      'tuid' => $tuid,
      'tjid' => $job->tjid,
      'title' => t('Task for !label', array(
        '!label' => $job
          ->defaultLabel(),
      )),
    ));

    // If we have translator then switch to pending state.
    if ($tuid) {
      $local_task->status = TMGMT_LOCAL_TASK_STATUS_PENDING;
    }
    $local_task
      ->save();

    // Create task items.
    foreach ($job
      ->getItems() as $item) {
      $local_task
        ->addTaskItem($item);
    }

    // The translation job has been successfully submitted.
    $job
      ->submitted();
  }

  /**
   * {@inheritdoc}
   */
  public function getSupportedTargetLanguages(TMGMTTranslator $translator, $source_language) {
    $languages = tmgmt_local_supported_target_languages($source_language);
    if ($translator
      ->getSetting('allow_all')) {
      $languages += parent::getSupportedTargetLanguages($translator, $source_language);
    }
    return $languages;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TMGMTDefaultTranslatorPluginController::$escapeEnd protected property Characters that indicate the end of an escaped string. 1
TMGMTDefaultTranslatorPluginController::$escapeStart protected property Characters that indicate the beginning of an escaped string. 1
TMGMTDefaultTranslatorPluginController::$remoteLanguagesMappings protected property
TMGMTDefaultTranslatorPluginController::$supportedRemoteLanguages protected property
TMGMTDefaultTranslatorPluginController::abortTranslation public function Aborts a translation job. Overrides TMGMTTranslatorPluginControllerInterface::abortTranslation
TMGMTDefaultTranslatorPluginController::acceptetDataItem public function Accept a single data item. Overrides TMGMTTranslatorPluginControllerInterface::acceptetDataItem
TMGMTDefaultTranslatorPluginController::canTranslate public function Check whether this service can handle a particular translation job. Overrides TMGMTTranslatorPluginControllerInterface::canTranslate 2
TMGMTDefaultTranslatorPluginController::defaultSettings public function Defines default settings. Overrides TMGMTTranslatorPluginControllerInterface::defaultSettings 1
TMGMTDefaultTranslatorPluginController::escapeText public function Returns the escaped #text of a data item. Overrides TMGMTTranslatorPluginControllerInterface::escapeText
TMGMTDefaultTranslatorPluginController::getDefaultRemoteLanguagesMappings public function Specifies default mappings for local to remote language codes. Overrides TMGMTTranslatorPluginControllerInterface::getDefaultRemoteLanguagesMappings 1
TMGMTDefaultTranslatorPluginController::getEscapedString protected function Returns the escaped string.
TMGMTDefaultTranslatorPluginController::getNotAvailableReason public function Return a reason why the translator is not available. Overrides TMGMTTranslatorPluginControllerInterface::getNotAvailableReason
TMGMTDefaultTranslatorPluginController::getNotCanTranslateReason public function Return a reason why the translator is not able to translate this job. Overrides TMGMTTranslatorPluginControllerInterface::getNotCanTranslateReason
TMGMTDefaultTranslatorPluginController::getRemoteLanguagesMappings public function Gets existing remote languages mappings. Overrides TMGMTTranslatorPluginControllerInterface::getRemoteLanguagesMappings
TMGMTDefaultTranslatorPluginController::getSupportedRemoteLanguages public function Gets all supported languages of the translator. Overrides TMGMTTranslatorPluginControllerInterface::getSupportedRemoteLanguages
TMGMTDefaultTranslatorPluginController::hasCheckoutSettings public function Returns if the translator has any settings for the passed job. Overrides TMGMTTranslatorPluginControllerInterface::hasCheckoutSettings 2
TMGMTDefaultTranslatorPluginController::isAvailable public function Checks whether a translator is available. Overrides TMGMTTranslatorPluginControllerInterface::isAvailable
TMGMTDefaultTranslatorPluginController::mapToLocalLanguage public function Maps remote language to local language. Overrides TMGMTTranslatorPluginControllerInterface::mapToLocalLanguage
TMGMTDefaultTranslatorPluginController::mapToRemoteLanguage public function Maps local language to remote language. Overrides TMGMTTranslatorPluginControllerInterface::mapToRemoteLanguage
TMGMTDefaultTranslatorPluginController::unescapeText public function Removes escape patterns from an escaped text. Overrides TMGMTTranslatorPluginControllerInterface::unescapeText
TMGMTLocalTranslatorPluginController::$language_pairs protected property
TMGMTLocalTranslatorPluginController::getSupportedLanguagePairs public function 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
TMGMTLocalTranslatorPluginController::getSupportedTargetLanguages public function Returns all available target languages that are supported by this service when given a source language. Overrides TMGMTDefaultTranslatorPluginController::getSupportedTargetLanguages
TMGMTLocalTranslatorPluginController::requestTranslation public function @abstract Overrides TMGMTTranslatorPluginControllerInterface::requestTranslation
TMGMTPluginBase::$pluginInfo protected property
TMGMTPluginBase::$pluginType protected property
TMGMTPluginBase::pluginInfo public function Returns the info of the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginInfo
TMGMTPluginBase::pluginType public function Returns the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginType
TMGMTPluginBase::__construct public function Constructor. Overrides TMGMTPluginBaseInterface::__construct