You are here

private function GLExchange::_validateDocument in GlobalLink Connect for Drupal 7.7

1 call to GLExchange::_validateDocument()
GLExchange::uploadTranslatable in gl_ws/glc/GLExchange.php
* Uploads the document to project director for translation * *

File

gl_ws/glc/GLExchange.php, line 182

Class

GLExchange

Code

private function _validateDocument($document) {
  if (!isset($document) || !isset($document->data) || strlen($document->data) <= 0) {
    throw new Exception("Document is empty");
  }
  if (!isset($document->name)) {
    throw new Exception("Document name not set");
  }
  $project = $this->submission->project;
  if (strcasecmp($document->fileformat, "Non-Parsable") != 0) {
    $isFileFormatCorrect = false;
    foreach ($project->fileFormats as $fileFormat) {
      if ($fileFormat == $document->fileformat) {
        $isFileFormatCorrect = true;
        break;
      }
    }
    if (!$isFileFormatCorrect) {
      throw new Exception("Specified file format " . $document->fileformat . " doesn`t exist in specified project");
    }
  }
  if (!isset($document->sourceLanguage) || strlen($document->sourceLanguage) <= 1) {
    throw new Exception("Source language not set");
  }
  if (!isset($document->targetLanguages) || count($document->targetLanguages) <= 0) {
    throw new Exception("Target languages are not set");
  }
  foreach ($document->targetLanguages as $language) {
    $isTargetLanguageFound = false;
    foreach ($project->languageDirections as $languageDirection) {
      if ($languageDirection->sourceLanguage == $document->sourceLanguage && $languageDirection->targetLanguage == $language) {
        $isTargetLanguageFound = true;
        break;
      }
    }
    if (!$isTargetLanguageFound) {
      throw new Exception("Project is not configured for language direction " . $document->sourceLanguage . "->" . $language);
    }
  }
}