You are here

protected static function LingotekConfigChunk::getAllSegments in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.3 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::getAllSegments()
  2. 7.4 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::getAllSegments()

Return all segments from the database that belong to a given chunk ID

Parameters

int $chunk_id:

Return value

array An array containing the translation sources from the locales_source table

2 calls to LingotekConfigChunk::getAllSegments()
LingotekConfigChunk::loadById in lib/Drupal/lingotek/LingotekConfigChunk.php
Factory method for getting a loaded LingotekConfigChunk object.
LingotekConfigChunk::__construct in lib/Drupal/lingotek/LingotekConfigChunk.php
Constructor.

File

lib/Drupal/lingotek/LingotekConfigChunk.php, line 305
Defines LingotekConfigChunk.

Class

LingotekConfigChunk
A class wrapper for Lingotek-specific behavior on ConfigChunks.

Code

protected static function getAllSegments($chunk_id) {
  $chunk_size = LINGOTEK_CONFIG_CHUNK_SIZE;
  $chunk_min = (intval($chunk_id) - 1) * intval($chunk_size) + 1;
  $chunk_max = (intval($chunk_id) - 1) * intval($chunk_size) + $chunk_size;
  $max_length = variable_get('lingotek_config_max_source_length', LINGOTEK_CONFIG_MAX_SOURCE_LENGTH);
  $textgroups_array = self::getTextgroupsForTranslation();
  $textgroups = "-1,'" . implode("','", $textgroups_array) . "'";
  $query = "SELECT ls.lid, ls.source\n      FROM {locales_source} ls\n      WHERE ls.lid >= :minLid\n      AND ls.lid <= :maxLid\n      AND LENGTH(ls.source) < :maxLen\n      ";
  if (in_array('misc', $textgroups_array)) {
    $query .= "AND (ls.textgroup IN ({$textgroups})\n        OR ls.textgroup NOT IN ('default','taxonomy','blocks','menu','views','field'))\n        ";
  }
  else {
    $query .= "AND ls.textgroup IN ({$textgroups})";
  }
  $results = db_query($query, array(
    ':minLid' => $chunk_min,
    ':maxLid' => $chunk_max,
    ':maxLen' => $max_length,
  ));
  $response = array();
  while ($r = $results
    ->fetchAssoc()) {
    $response[$r['lid']] = $r['source'];
  }

  // required to be in order ascending
  ksort($response, SORT_NUMERIC);
  return $response;
}