You are here

function globallink_update_status in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_node.inc \globallink_update_status()
  2. 7.6 globallink_node.inc \globallink_update_status()

Updates the translation status.

Parameters

object $globallink: The GlobalLink translation data.

4 calls to globallink_update_status()
globallink_background_import in ./globallink_background_jobs.inc
Imports the documents
globallink_background_pull in ./globallink_background_jobs.inc
Pull submissions or documents
globallink_upload_translation_all_form_submit in ./globallink_workbench_all_active_submissions.inc
globallink_upload_translation_node_form_submit in ./globallink_workbench_all_submissions.inc
Submit handler of XML file upload for direct translation

File

./globallink_background_jobs.inc, line 1132
To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor.

Code

function globallink_update_status(&$globallink, $sub_rid = NULL) {
  if ($sub_rid != NULL) {
    $status = $globallink->status;
    if ($status != '' && $globallink->type != GLOBALLINK_ENTITY_TYPE_WEBFORM) {
      db_update('globallink_document')
        ->fields(array(
        'target_status' => $status,
        'target_last_updated' => REQUEST_TIME,
      ))
        ->condition('submission_rid', $sub_rid, '=')
        ->condition('target_lang_code', $globallink->targetLocale, '=')
        ->condition('document_ticket', $globallink->documentTicket, '=')
        ->execute();
    }
    elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
      db_update('globallink_document')
        ->fields(array(
        'target_status' => $status,
        'target_last_updated' => REQUEST_TIME,
      ))
        ->condition('submission_rid', $sub_rid, '=')
        ->condition('object_id', $globallink->lids, 'IN')
        ->condition('target_lang_code', $globallink->targetLocale, '=')
        ->condition('document_ticket', $globallink->documentTicket, '=')
        ->execute();
    }
    $query = db_select('globallink_document', 'gd');
    $query
      ->condition('submission_rid', $sub_rid, '=');
    $query
      ->condition('target_lang_code', $globallink->targetLocale, '=');
    $query
      ->fields('gd');
    $results = $query
      ->execute()
      ->fetchAll();
    $row_count = count($results);
    $published_count = 0;
    $completed_count = 0;
    $sub_status = '';
    foreach ($results as $row) {
      if ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_ERROR) {
        $sub_status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
        break;
      }
      if ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_IMPORTED) {
        $published_count++;
      }
      elseif ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_COMPLETED) {
        $completed_count++;
      }
    }
    if ($published_count == $row_count) {
      $sub_status = GLOBALLINK_STATUS_TRANSLATION_IMPORTED;
    }
    elseif ($completed_count == $row_count) {
      $sub_status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
    }
    if ($sub_status != '') {
      db_update('globallink_submission')
        ->fields(array(
        'status' => $sub_status,
        'updated' => REQUEST_TIME,
      ))
        ->condition('rid', $sub_rid, '=')
        ->execute();
    }
  }
}