You are here

public static function LingotekSync::getDownloadableReport in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  2. 7.4 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  3. 7.5 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  4. 7.6 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
1 call to LingotekSync::getDownloadableReport()
LingotekSync::getReport in lib/Drupal/lingotek/LingotekSync.php

File

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

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

public static function getDownloadableReport() {
  $project_id = variable_get('lingotek_project', NULL);
  $document_ids = LingotekSync::getDocIdsByStatus(LingotekSync::STATUS_PENDING);
  $report = array(
    'download_targets_workflow_complete' => array(),
    // workflow complete and ready for download
    'download_targets_workflow_complete_count' => 0,
    'download_targets_workflow_incomplete' => array(),
    // not workflow complete (but download if wanted)
    'download_targets_workflow_incomplete_count' => 0,
  );
  if (empty($document_ids)) {
    return $report;
  }

  // if no documents are PENDING, then no need to make the API call.
  $api = LingotekApi::instance();
  $response = $api
    ->getProgressReport($project_id, $document_ids, TRUE);
  if (isset($response->workflowCompletedByDocumentIdAndTargetLocale)) {
    $progress_report = $response->workflowCompletedByDocumentIdAndTargetLocale;
    foreach ($progress_report as $doc_id => $target_locales) {
      foreach ($target_locales as $lingotek_locale => $workflow_completed) {
        $doc_target = array(
          'document_id' => $doc_id,
          'locale' => $lingotek_locale,
        );
        if ($workflow_completed) {
          if (self::getTargetStatus($doc_id, $lingotek_locale) == self::STATUS_PENDING) {
            $report['download_targets_workflow_complete'][] = $doc_target;
            $report['download_targets_workflow_complete_count']++;
          }
          else {

            // Target already downloaded
          }
        }
        else {
          $report['download_targets_workflow_incomplete'][] = $doc_target;
          $report['download_targets_workflow_incomplete_count']++;
        }
      }
    }
  }
  return $report;
}