You are here

function lingotek_grid_automatic_download in Lingotek Translation 7.7

1 string reference to 'lingotek_grid_automatic_download'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.bulk_grid.inc, line 1201

Code

function lingotek_grid_automatic_download($entity_type) {
  $or = db_or()
    ->condition('lem.value', 'READY')
    ->condition('lem.value', 'READY_INTERIM');
  $query = db_select('lingotek_entity_metadata', 'lem');
  $query
    ->addField('lem', 'entity_id');
  $query
    ->addField('lem', 'entity_key');

  //$query->condition('lem.value', 'READY');
  $query
    ->condition($or);
  $query
    ->condition('lem.entity_type', $entity_type);
  $results = $query
    ->execute();
  $ids_to_check = array();
  $translation_status = array();
  foreach ($results as $result) {
    $entity_id = $result->entity_id;
    $ids_to_check[] = $entity_id;
    $language_code = substr($result->entity_key, count($result->entity_key) - 6);
    $translation_status[$entity_id][$language_code] = $language_code;
  }
  $entities = entity_load($entity_type, $ids_to_check);
  foreach ($entities as $entity) {
    if ($entity->lingotek['auto_download'] === 1) {
      $id = $entity_type === 'node' ? $entity->nid : $entity->cid;
      foreach ($translation_status[$id] as $lang_code) {
        lingotek_entity_download($entity, $entity_type, $lang_code);
      }
    }
  }
}