You are here

function globallink_get_ready_translations_details_from_pd in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 gl_ws/gl_ws_receive_translations.inc \globallink_get_ready_translations_details_from_pd()
16 calls to globallink_get_ready_translations_details_from_pd()
globallink_block_receive_form in globallink_block/globallink_block_receive.inc
Builds form to receive a block submission.
globallink_block_receive_form_submit in globallink_block/globallink_block_receive.inc
Handles block form submission.
globallink_dashboard_receive in ./globallink_receive_translations.inc
Builds form to receive a GlobalLink submission.
globallink_dashboard_receive_submit in ./globallink_receive_translations.inc
Handles GlobalLink form submission.
globallink_entity_receive_form in globallink_entity/globallink_entity_receive.inc
Builds form to receive an entity submission.

... See full list

File

gl_ws/gl_ws_receive_translations.inc, line 13

Code

function globallink_get_ready_translations_details_from_pd($pd_obj, $type = 'node') {
  $username = $pd_obj->username;
  $password = $pd_obj->password;
  $url = $pd_obj->url;
  $project_short_code = $pd_obj->projectShortCode;
  $proj_arr = array();
  if ($project_short_code != '') {
    $arr = explode(',', $project_short_code);
    foreach ($arr as $value) {
      $proj_arr[$value] = $value;
    }
  }
  $session_service = new SessionService2(GL_WSDL_PATH . 'SessionService2.wsdl', array(
    'location' => $url . '/services/SessionService2',
  ));
  $project_service = new ProjectService2(GL_WSDL_PATH . 'ProjectService2.wsdl', array(
    'location' => $url . '/services/ProjectService2',
  ));
  $target_service = new TargetService2(GL_WSDL_PATH . 'TargetService2.wsdl', array(
    'location' => $url . '/services/TargetService2',
  ));
  $globallink_arr = array();
  $token = globallink_login($session_service, $username, $password);
  $projects = globallink_get_user_projects($project_service, $token);
  $proj_ticket_arr = array();
  foreach ($projects as $project) {
    $short_code = $project->projectInfo->shortCode;
    foreach ($proj_arr as $conf_proj) {
      if ($conf_proj == $short_code) {
        $proj_ticket_arr[] = $project->ticket;
      }
    }
  }
  if (count($proj_ticket_arr) > 0) {
    $targets = globallink_get_completed_targets_by_projects($target_service, $proj_ticket_arr, $token, $pd_obj);
    $count = 1;
    if (is_array($targets)) {
      foreach ($targets as $target) {
        if (!is_null($target->ticket) && $target->ticket != '') {
          $source_file = $target->document->documentInfo->name;
          $m_arr = $target->document->documentInfo->metadata;
          $source_type = '';
          $type_id = '';
          if (is_array($m_arr)) {
            foreach ($m_arr as $m) {
              if ($m->key == 'type') {
                $source_type = $m->value;
              }
              else {
                $type_id = $m->value;
              }
            }
          }
          else {
            $source_type = $target->document->documentInfo->metadata->value;
          }
          switch ($type) {
            case 'entity':
              if ($source_type != 'entity') {
                continue;
              }
              break;
            case 'menu':
              if ($source_type != 'menu') {
                continue;
              }
              break;
            case 'block':
              if ($source_type != 'block') {
                continue;
              }
              break;
            case 'taxonomy':
              if ($source_type != 'taxonomy') {
                continue;
              }
              break;
            case 'interface':
              if ($source_type != 'interface') {
                continue;
              }
              break;
            case 'webform':
              if ($source_type != 'webform') {
                continue;
              }
              break;
            case 'fieldable_panels':
              if ($source_type != 'fieldable_panels_panes') {
                continue;
              }
              break;
            default:
              if ($source_type == 'entity' || $source_type == 'menu' || $source_type == 'block' || $source_type == 'taxonomy' || $source_type == 'interface' || $source_type == 'webform' || $source_type == 'fieldable_panels_panes') {
                continue;
              }
          }
          $globallink = new GlobalLink();
          $globallink->submissionTicket = $target->document->documentGroup->submission->ticket;
          $globallink->submissionName = $target->document->documentGroup->submission->submissionInfo->name;
          $globallink->documentTicket = $target->document->ticket;
          $globallink->sourceFileName = $source_file;
          $globallink->targetTicket = $target->ticket;
          $globallink->sourceLocale = str_replace('-', '_', $target->sourceLanguage->locale);
          $globallink->targetLocale = str_replace('-', '_', $target->targetLanguage->locale);
          $globallink->type = $source_type;
          if ($source_type != 'node' && $source_type != 'entity') {
            $globallink->otherObjectId = $type_id;
          }
          else {
            $globallink->nid = $type_id;
          }
          $globallink_arr[$count] = $globallink;
          $count++;
        }
      }
    }
    elseif (!is_null($targets)) {
      $target = $targets;
      if (!is_null($target->ticket) && $target->ticket != '') {
        $source_file = $target->document->documentInfo->name;
        $m_arr = $target->document->documentInfo->metadata;
        $source_type = '';
        $type_id = '';
        if (is_array($m_arr)) {
          foreach ($m_arr as $m) {
            if ($m->key == 'type') {
              $source_type = $m->value;
            }
            else {
              $type_id = $m->value;
            }
          }
        }
        else {
          $source_type = $target->document->documentInfo->metadata->value;
        }
        switch ($type) {
          case 'entity':
            if ($source_type != 'entity') {
              return $globallink_arr;
            }
            break;
          case 'menu':
            if ($source_type != 'menu') {
              return $globallink_arr;
            }
            break;
          case 'block':
            if ($source_type != 'block') {
              return $globallink_arr;
            }
            break;
          case 'taxonomy':
            if ($source_type != 'taxonomy') {
              return $globallink_arr;
            }
            break;
          case 'interface':
            if ($source_type != 'interface') {
              return $globallink_arr;
            }
            break;
          case 'webform':
            if ($source_type != 'webform') {
              return $globallink_arr;
            }
            break;
          case 'fieldable_panels':
            if ($source_type != 'fieldable_panels_panes') {
              return $globallink_arr;
            }
            break;
          default:
            if ($source_type == 'entity' || $source_type == 'menu' || $source_type == 'block' || $source_type == 'taxonomy' || $source_type == 'interface' || $source_type == 'webform' || $source_type == 'fieldable_panels_panes') {
              return $globallink_arr;
            }
        }
        $globallink = new GlobalLink();
        $globallink->submissionTicket = $target->document->documentGroup->submission->ticket;
        $globallink->submissionName = $target->document->documentGroup->submission->submissionInfo->name;
        $globallink->documentTicket = $target->document->ticket;
        $globallink->sourceFileName = $source_file;
        $globallink->targetTicket = $target->ticket;
        $globallink->sourceLocale = str_replace('-', '_', $target->sourceLanguage->locale);
        $globallink->targetLocale = str_replace('-', '_', $target->targetLanguage->locale);
        $globallink->type = $source_type;
        if ($source_type != 'node' && $source_type != 'entity') {
          $globallink->otherObjectId = $type_id;
        }
        else {
          $globallink->nid = $type_id;
        }
        $globallink_arr[$count] = $globallink;
      }
    }
  }
  return $globallink_arr;
}