You are here

function lingotek_config_start_query in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lingotek.config.inc \lingotek_config_start_query()
2 calls to lingotek_config_start_query()
lingotek_config_get_rows in ./lingotek.config.inc
lingotek_row_status_query in ./lingotek.config.inc

File

./lingotek.config.inc, line 145
Config grid form elements

Code

function lingotek_config_start_query($form_state, $union_part_desc) {
  $query = db_select('locales_source', 's');

  // Gets sync statuses for each language.
  $query
    ->addExpression("(SELECT COUNT(*) FROM {locales_target} WHERE i18n_status = 0 AND lid = (SELECT lid FROM {lingotek_config_map} WHERE lid = s.lid AND current = 1))", 'current_target_count');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='PENDING')", 'pending');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='READY')", 'ready');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='CURRENT')", 'current');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='READY_INTERIM')", 'ready_interim');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='INTERIM')", 'interim');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='EDITED_INTERIM')", 'edited_interim');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='EDITED')", 'edited');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='UNTRACKED')", 'untracked');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='ERROR')", 'error');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(SUBSTRING(config_key, 20, 10)) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key LIKE 'target_sync_status_%' AND value='NONE')", 'none');
  $query
    ->addExpression("(SELECT GROUP_CONCAT(language) FROM {locales_target} WHERE lid = s.lid AND i18n_status = 1)", 'source_edited');
  $query
    ->addExpression("(SELECT set_id FROM {lingotek_config_map} lcm WHERE lcm.lid = s.lid)", 'set_id');
  $query
    ->addExpression("(SELECT value FROM {lingotek_config_metadata} lcm WHERE lcm.id = (SELECT set_id FROM lingotek_config_map WHERE lid = s.lid) AND config_key = 'upload_error')", 'upload_error');
  $query
    ->addExpression("(SELECT value FROM {lingotek_config_metadata} lcm WHERE lcm.value = s.lid AND config_key = 'marked')", 'marked');
  $query
    ->addExpression("(SELECT set_id FROM {lingotek_config_map} lcm WHERE lcm.lid = s.lid)", 'config_set_id');

  // Lingotek Document ID
  $query
    ->addExpression("(SELECT GROUP_CONCAT(value) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key = 'document_id')", 'document_id');

  //Config Workflow ID
  $query
    ->addExpression("(SELECT GROUP_CONCAT(value) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key = 'workflow_id')", 'workflow_id');

  // Entity Upload Status
  $query
    ->addExpression("(SELECT GROUP_CONCAT(value) FROM {lingotek_config_metadata} WHERE id = (SELECT set_id FROM {lingotek_config_map} WHERE lid = s.lid) AND config_key = 'upload_status' AND value <> '" . LingotekSync::STATUS_TARGET . "' AND value <> '" . LingotekSync::STATUS_DELETED . "')", 'upload_status');
  $query
    ->fields('s', array(
    'source',
    'location',
    'context',
    'lid',
    'textgroup',
  ));

  // Only show items in textgroups that are selected for translation on Config Settings page.
  $translatable_textgroups = LingotekConfigSet::getTextgroupsForTranslation() ?: array(
    'no textgroups selected',
  );
  if (in_array('misc', $translatable_textgroups)) {
    $all_textgroup_categories = array(
      'blocks',
      'default',
      'menu',
      'taxonomy',
      'views',
      'field',
    );
    $qor = db_or();
    $qor
      ->condition('s.textgroup', $translatable_textgroups, 'IN');
    $qor
      ->condition('s.textgroup', $all_textgroup_categories, 'NOT IN');
    $query
      ->condition($qor);
  }
  else {
    $query
      ->condition('s.textgroup', $translatable_textgroups, 'IN');
  }

  // Hide taxonomy terms that use translate for i18n_mode.
  $translate_terms_subquery = db_select('taxonomy_vocabulary', 'tv');
  $translate_terms_subquery
    ->fields('tv', array(
    'vid',
  ));
  $translate_terms_subquery
    ->condition('tv.i18n_mode', LINGOTEK_TAXONOMY_TRANSLATE_VALUE);
  $translate_ids = $translate_terms_subquery
    ->execute()
    ->fetchCol();

  // Hide taxonomy terms that have custom fields.
  $advanced_vids = array_keys(lingotek_get_advanced_vocabularies());
  if ($union_part_desc == 'taxonomy name') {
    $advanced_vid_expression = empty($advanced_vids) ? '' : ' AND term_name.vid NOT IN (' . implode(',', $advanced_vids) . ')';
    $query
      ->leftJoin('taxonomy_term_data', 'term_name', 'SUBSTRING_INDEX(SUBSTRING_INDEX(s.context , \':\', 2 ),\':\',-1) = term_name.tid AND term_name.name = s.source AND term_name.vid NOT IN (' . implode(',', array_merge(array(
      -1,
    ), $translate_ids)) . ')' . $advanced_vid_expression);
    $query
      ->addExpression('term_name.tid', 'tid_from_name');

    //DO NOT do addField here, it puts the column name in the wrong place and messes with the union
  }
  else {
    $query
      ->addExpression('NULL', 'tid_from_name');
  }
  if ($union_part_desc == 'taxonomy desc') {
    $advanced_vid_expression = empty($advanced_vids) ? '' : ' AND term_description.vid NOT IN (' . implode(',', $advanced_vids) . ')';
    $query
      ->leftJoin('taxonomy_term_data', 'term_description', 'SUBSTRING_INDEX(SUBSTRING_INDEX(s.context , \':\', 2 ),\':\',-1) = term_description.tid AND term_description.description = s.source AND term_description.vid NOT IN (' . implode(',', array_merge(array(
      -1,
    ), $translate_ids)) . ')' . $advanced_vid_expression);
    $query
      ->addExpression('term_description.tid', 'tid_from_description');

    //DO NOT do addField here, it puts the column name in the wrong place and messes with the union
  }
  else {
    $query
      ->addExpression('NULL', 'tid_from_description');
  }

  // For all taxonomy terms, only show if it has a name or description.
  if ($union_part_desc == 'not taxonomy') {
    $query
      ->condition('s.textgroup', 'taxonomy', '<>');
  }
  elseif ($union_part_desc == 'taxonomy name') {
    $query
      ->isNotNull('term_name.tid');
  }
  elseif ($union_part_desc = 'taxonomy desc') {
    $query
      ->isNotNull('term_description.tid');
  }
  return $query;
}