You are here

gl_ws_common.inc in GlobalLink Connect for Drupal 7.7

Same filename and directory in other branches
  1. 7.5 gl_ws/gl_ws_common.inc
  2. 7.6 gl_ws/gl_ws_common.inc

File

gl_ws/gl_ws_common.inc
View source
<?php

/**
 * @file
 * Miscellaneous Web Service functions for GlobalLink.
 */
require_once 'glc/GLExchange.php';
require_once 'glc/model/PDConfig.inc.php';

/**
 *
 */
function globallink_get_user_pd_projects($pd_obj) {
  $proj_arr = array();
  $connectorConfig = new PDConfig();
  $connectorConfig->url = $pd_obj->url;
  $connectorConfig->username = $pd_obj->username;
  $connectorConfig->password = $pd_obj->password;
  $connectorConfig->userAgent = $pd_obj->userAgent;
  $glExchange = new GLExchange($connectorConfig);
  $pdProjects = $glExchange
    ->getProjects();
  if (isset($pdProjects) && is_array($pdProjects)) {
    foreach ($pdProjects as $project) {
      $proj_arr[$project->shortcode] = $project->name;
    }
  }
  return $proj_arr;
}

/**
 *
 */
function globallink_get_user_pdProjects($pd_obj) {
  $proj_arr = array();
  $connectorConfig = new PDConfig();
  $connectorConfig->url = $pd_obj->url;
  $connectorConfig->username = $pd_obj->username;
  $connectorConfig->password = $pd_obj->password;
  $connectorConfig->userAgent = $pd_obj->userAgent;
  $glExchange = new GLExchange($connectorConfig);
  $pdProjects = $glExchange
    ->getProjects();
  if (isset($pdProjects) && is_array($pdProjects)) {
    foreach ($pdProjects as $project) {
      $proj_arr[$project->shortcode] = $project;
    }
  }
  return $proj_arr;
}

/**
 *
 */
function globallink_test_pd_connectivity($pd_obj) {
  $connectorConfig = new PDConfig();
  $connectorConfig->url = $pd_obj->url;
  $connectorConfig->username = $pd_obj->username;
  $connectorConfig->password = $pd_obj->password;
  $connectorConfig->userAgent = $pd_obj->userAgent;
  $proj_arr = array();
  $glExchange = new GLExchange($connectorConfig);
  $pdProjects = $glExchange
    ->getProjects();
  if (isset($pdProjects) && is_array($pdProjects)) {
    foreach ($pdProjects as $project) {
      $proj_arr[$project->shortcode] = $project;
    }
  }
  $project_short_code = $pd_obj->projectShortCode;
  if ($project_short_code != '') {
    $arr = explode(',', $project_short_code);
    foreach ($arr as $value) {
      if (!array_key_exists($value, $proj_arr)) {
        throw new Exception("Connection Failed - Invalid Project Code: " . $value);
      }
      else {
        $success = FALSE;
        $project = $proj_arr[$value];
        if (isset($project->fileFormats) && is_array($project->fileFormats)) {
          foreach ($project->fileFormats as $fileFormat) {
            if ($pd_obj->classifier == $fileFormat) {
              $success = TRUE;
              break;
            }
          }
        }
        if (!$success) {
          throw new Exception("Connection Failed - Invalid Classifier");
        }
      }
    }
  }
  return TRUE;
}