You are here

protected static function LingotekConfigChunk::getAllSegments in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.3 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::getAllSegments()
  2. 7.5 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 282
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;
  $textgroups = "-1,'" . implode("','", self::getTextgroupsForTranslation()) . "'";
  $results = db_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                        AND ls.textgroup IN ({$textgroups})\n                        ", array(
    ':minLid' => $chunk_min,
    ':maxLid' => $chunk_max,
    ':maxLen' => LINGOTEK_CONFIG_MAX_SOURCE_LENGTH,
  ));
  $response = array();
  while ($r = $results
    ->fetchAssoc()) {
    $response[$r['lid']] = $r['source'];
  }

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