You are here

function globallink_background_send in GlobalLink Connect for Drupal 7.7

1 call to globallink_background_send()
globallink_create_submission_form_submit in ./globallink_send_translations.inc
Handles GlobalLink form submission.
1 string reference to 'globallink_background_send'
globallink_create_submission_form_submit in ./globallink_send_translations.inc
Handles GlobalLink form submission.

File

./globallink_background_jobs.inc, line 13
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_background_send($all_content, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $parents) {
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_send_translations');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_common');
  module_load_include('php', 'globallink', 'gl_ws/glc/model/Submission.inc.php');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink_entity/globallink_entity');
  module_load_include('inc', 'globallink', 'globallink_block/globallink_block');
  module_load_include('inc', 'globallink', 'globallink_fieldable_panels/globallink_fieldable_panels');
  module_load_include('inc', 'globallink', 'globallink_interface/globallink_interface');
  module_load_include('inc', 'globallink', 'globallink_menu/globallink_menu');
  module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
  module_load_include('inc', 'globallink', 'globallink_webform/globallink_webform');
  module_load_include('inc', 'globallink', 'globallink_beans/globallink_beans');
  module_load_include('inc', 'globallink', 'globallink_file_entity/globallink_file_entity');
  module_load_include('inc', 'globallink', 'globallink_commerce/globallink_commerce');
  watchdog(GLOBALLINK_MODULE, 'Sending submission [%submission_name] in background', array(
    '%submission_name' => $submission_name,
  ), WATCHDOG_INFO);
  $globallink_arr = array();
  try {
    if (isset($all_content['eids'])) {
      $eids = $all_content['eids'];
      $entity_content = globallink_entity_send_for_translations($eids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($entity_content) && !empty($entity_content) && isset($entity_content[GLOBALLINK_ENTITY_TYPE_ENTITY])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_ENTITY] = $entity_content[GLOBALLINK_ENTITY_TYPE_ENTITY];
      }
    }
    if (isset($all_content['bids'])) {
      $bids = $all_content['bids'];
      $block_content = globallink_block_send_blocks_for_translations($bids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($block_content) && !empty($block_content) && isset($block_content[GLOBALLINK_ENTITY_TYPE_BLOCK])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_BLOCK] = $block_content[GLOBALLINK_ENTITY_TYPE_BLOCK];
      }
    }
    if (isset($all_content['int_ids'])) {
      $int_ids = $all_content['int_ids'];
      $int_content = globallink_interface_send_for_translations($int_ids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($int_content) && !empty($int_content) && isset($int_content[GLOBALLINK_ENTITY_TYPE_INTERFACE])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_INTERFACE] = $int_content[GLOBALLINK_ENTITY_TYPE_INTERFACE];
      }
    }
    if (isset($all_content['fpids'])) {
      $fpids = $all_content['fpids'];
      $fpp_content = globallink_fieldable_panels_pane_send_for_translations($fpids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($fpp_content) && !empty($fpp_content) && isset($fpp_content[GLOBALLINK_ENTITY_TYPE_FPP])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_FPP] = $fpp_content[GLOBALLINK_ENTITY_TYPE_FPP];
      }
    }
    if (isset($all_content['mids'])) {
      $mids = $all_content['mids'];
      $menu_content = globallink_menu_send_for_translations($mids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($menu_content) && !empty($menu_content) && isset($menu_content[GLOBALLINK_ENTITY_TYPE_MENU])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_MENU] = $menu_content[GLOBALLINK_ENTITY_TYPE_MENU];
      }
    }
    if (isset($all_content['tids'])) {
      $tids = $all_content['tids'];
      $tax_content = globallink_taxonomy_send_for_translations($tids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($tax_content) && !empty($tax_content) && isset($tax_content[GLOBALLINK_ENTITY_TYPE_TAXONOMY])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_TAXONOMY] = $tax_content[GLOBALLINK_ENTITY_TYPE_TAXONOMY];
      }
    }
    if (isset($all_content['wfids'])) {
      $wfids = $all_content['wfids'];
      $webform_content = globallink_webform_send_for_translations($wfids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $parents);
      if (isset($webform_content) && !empty($webform_content) && isset($webform_content[GLOBALLINK_ENTITY_TYPE_WEBFORM])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_WEBFORM] = $webform_content[GLOBALLINK_ENTITY_TYPE_WEBFORM];
      }
    }
    if (isset($all_content['nids'])) {
      $nids = $all_content['nids'];
      $node_content = globallink_send_for_translations($nids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($node_content) && !empty($node_content) && isset($node_content[GLOBALLINK_ENTITY_TYPE_NODE])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_NODE] = $node_content[GLOBALLINK_ENTITY_TYPE_NODE];
      }
    }
    if (isset($all_content['bnids'])) {
      $bnids = $all_content['bnids'];
      $bean_content = globallink_beans_send_for_translations($bnids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($bean_content) && !empty($bean_content) && isset($bean_content[GLOBALLINK_ENTITY_TYPE_BEAN])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_BEAN] = $bean_content[GLOBALLINK_ENTITY_TYPE_BEAN];
      }
    }
    if (isset($all_content['fids'])) {
      $fids = $all_content['fids'];
      $file_content = globallink_send_file_entity_for_translations($fids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($file_content) && !empty($file_content) && isset($file_content[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY] = $file_content[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY];
      }
    }
    if (isset($all_content['pids'])) {
      $pids = $all_content['pids'];
      $product_content = globallink_commerce_send_for_translations($pids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
      if (isset($product_content) && !empty($product_content) && isset($product_content[GLOBALLINK_ENTITY_TYPE_COM])) {
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_COM] = $product_content[GLOBALLINK_ENTITY_TYPE_COM];
      }
    }
  } catch (Exception $e) {
    watchdog(GLOBALLINK_MODULE, 'Error in getting GlobalLink XML objects for submission [%submission_name]', array(
      '%submission_name' => $submission_name,
    ), WATCHDOG_ERROR);
    watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
      '%function' => __FUNCTION__,
      '%file' => $e
        ->getFile(),
      '%line' => $e
        ->getLine(),
      '%code' => $e
        ->getCode(),
      '%message' => $e
        ->getMessage(),
    ), WATCHDOG_ERROR);
    return;
  }
  $submission_info = array(
    'source_locale' => $source_locale,
    'target_locale' => $target_locale_arr,
    'submission_name' => $submission_name,
    'due_date' => $due_date,
    'submission_details' => $submission_details,
    'project_code' => $project_code,
  );
  $submitter = $submission_details['submitter'];
  drupal_alter('transperfect_node_send', $globallink_arr, $submission_info);
  if (!empty($globallink_arr)) {
    if (globallink_debug_enabled()) {
      watchdog(GLOBALLINK_MODULE, 'Final GlobalLink Array - %arr', array(
        '%arr' => print_r($globallink_arr, TRUE),
      ), WATCHDOG_DEBUG);
      watchdog(GLOBALLINK_MODULE, 'Submission Info - %arr', array(
        '%arr' => print_r($submission_info, TRUE),
      ), WATCHDOG_DEBUG);
    }
    try {
      $submission = new PDSubmission();
      if ($submission_priority == 2) {
        $submission->isUrgent = TRUE;
      }
      $projects = globallink_get_user_pdProjects($pd4);
      if (isset($projects[$project_code])) {
        $submission->project = $projects[$project_code];
        $project_name = $projects[$project_code]->name;
      }
      else {
        throw new Exception("Invalid Project Code");
      }
      $submission->name = $submission_name;
      $submission->dueDate = $due_date;
      $submission->submitter = $pd4->username;
      $submission->instructions = $submission_details['instructions'] . "\nSubmitter: " . $submitter;
      globallink_send_documents_for_translation_to_pd($globallink_arr, $pd4, $submission);
      if (globallink_debug_enabled()) {
        watchdog(GLOBALLINK_MODULE, 'Submission [%sub] sent successfully to GlobalLink Project Director', array(
          '%sub' => $submission_info['submission_name'],
        ), WATCHDOG_DEBUG);
      }
      $sub_arr = array();
      foreach ($globallink_arr as $gl_arr) {
        foreach ($gl_arr as $globallink) {
          foreach ($globallink->targetLocale as $target_locale) {
            if (!isset($sub_arr[$target_locale]) && !isset($sub_arr[$target_locale][[
              'globallink_submission',
            ]])) {
              $sub_arr[$target_locale] = array();
              $sub_arr[$target_locale]['globallink_submission'] = array();
              $sub_arr[$target_locale]['globallink_submission']['submission'] = $globallink->submissionName;
              $sub_arr[$target_locale]['globallink_submission']['submission_ticket'] = $globallink->submissionTicket;

              // Todo - Update it with real PD Id.
              $sub_arr[$target_locale]['globallink_submission']['pd_submission_id'] = 12345678;
              $sub_arr[$target_locale]['globallink_submission']['source_lang_code'] = $source_locale;
              $sub_arr[$target_locale]['globallink_submission']['project_code'] = $project_code;
              $sub_arr[$target_locale]['globallink_submission']['project_name'] = $project_name;
              $sub_arr[$target_locale]['globallink_submission']['due_date'] = $globallink->dueDate;
            }
            if (isset($sub_arr[$target_locale]) && isset($sub_arr[$target_locale]['globallink_document'])) {
              $sub_arr[$target_locale]['globallink_document'][] = $globallink;
            }
            else {
              $sub_arr[$target_locale]['globallink_document'] = array(
                $globallink,
              );
            }
          }
        }
      }
      globallink_create_submission($sub_arr);
      watchdog(GLOBALLINK_MODULE, 'Submission [%submission_name] created successfully.', array(
        '%submission_name' => $submission_name,
      ), WATCHDOG_INFO);
    } catch (SoapFault $se) {
      watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
        '%function' => __FUNCTION__,
        '%faultcode' => $se->faultcode,
        '%faultstring' => $se->faultstring,
      ), WATCHDOG_ERROR);
      return;
    } catch (Exception $e) {
      watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
        '%function' => __FUNCTION__,
        '%file' => $e
          ->getFile(),
        '%line' => $e
          ->getLine(),
        '%code' => $e
          ->getCode(),
        '%message' => $e
          ->getMessage(),
      ), WATCHDOG_ERROR);
      return;
    }
  }
}