You are here

function TMGMTLocaleSourceUIController::getStrings in Translation Management Tool 7

Gets locale strings.

Parameters

string $textgroup: The locale textgroup.

string $search_label: Label to search for.

string $missing_target_language: Missing translation language.

Return value

array List of i18n strings data.

1 call to TMGMTLocaleSourceUIController::getStrings()
TMGMTLocaleSourceUIController::overviewForm in sources/locale/tmgmt_locale.ui.inc
Implements TMGMTSourceUIControllerInterface::overviewForm().

File

sources/locale/tmgmt_locale.ui.inc, line 28
Provides the I18nString source controller.

Class

TMGMTLocaleSourceUIController
Class TMGMTI18nStringDefaultSourceUIController

Code

function getStrings($textgroup, $search_label = NULL, $missing_target_language = NULL) {
  $languages = drupal_map_assoc(array_keys(language_list()));
  $select = db_select('locales_source', 'ls')
    ->fields('ls', array(
    'lid',
    'source',
  ));
  $select
    ->addTag('tmgmt_sources_search');
  $select
    ->addMetaData('plugin', 'locale');
  $select
    ->addMetaData('type', $textgroup);
  $select
    ->condition('ls.textgroup', $textgroup);
  if (!empty($search_label)) {
    $select
      ->condition('ls.source', "%{$search_label}%", 'LIKE');
  }
  if (!empty($missing_target_language) && in_array($missing_target_language, $languages)) {
    $select
      ->isNull("lt_{$missing_target_language}.language");
  }

  // Join locale targets for each language.
  // We want all joined fields to be named as langcodes, but langcodes could
  // contain hyphens in their names, which is not allowed by the most database
  // engines. So we create a langcode-to-filed_alias map, and rename fields
  // later.
  $langcode_to_filed_alias_map = array();
  foreach ($languages as $langcode) {
    $table_alias = $select
      ->leftJoin('locales_target', db_escape_field("lt_{$langcode}"), "ls.lid = %alias.lid AND %alias.language = '{$langcode}'");
    $langcode_to_filed_alias_map[$langcode] = $select
      ->addField($table_alias, 'language');
  }
  $select = $select
    ->extend('PagerDefault')
    ->limit(variable_get('tmgmt_source_list_limit', 20));
  $rows = $select
    ->execute()
    ->fetchAll();
  foreach ($rows as $row) {
    foreach ($langcode_to_filed_alias_map as $langcode => $field_alias) {
      $row->{$langcode} = $row->{$field_alias};
      unset($row->{$field_alias});
    }
  }
  return $rows;
}