You are here

private static function LingotekSync::getIntegrationMethodId in Lingotek Translation 7.7

1 call to LingotekSync::getIntegrationMethodId()
LingotekSync::updateNotifyUrl in lib/Drupal/lingotek/LingotekSync.php

File

lib/Drupal/lingotek/LingotekSync.php, line 1236
LingotekSync

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

private static function getIntegrationMethodId($api) {
  $params = array(
    'regex' => ".*",
  );
  $response = $api
    ->request('searchOutboundIntegrationUrls', $params);
  if (isset($response->results) && $response->results) {
    global $base_url;
    $integration_methods = $response->integrationMethods;
    foreach ($integration_methods as $integration_method) {
      if (strpos($integration_method->url, $base_url) !== FALSE) {
        $integration_method_id = $integration_method->id;

        // prefer integration with matching base_url
      }
    }
    if (!strlen($integration_method_id)) {
      reset($integration_methods);

      // just in case the internal pointer is not pointing to the first element
      $integration_method = current($integration_methods);

      // grab the first element in the list
      $integration_method_id = $integration_method->id;

      // use the first url found (if no matching url was found previously)
    }
    variable_set('lingotek_integration_method', $integration_method_id);
  }
  return $integration_method_id;
}