You are here

public static function LingotekSync::getDownloadableReport in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  2. 7.3 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  3. 7.4 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getDownloadableReport()
  4. 7.5 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 187
LingotekSync

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

public static function getDownloadableReport() {
  $document_ids = array_unique(array_merge(self::getConfigDocIdsByStatus(self::STATUS_PENDING), self::getConfigDocIdsByStatus(self::STATUS_READY)));
  $report = array(
    'download_targets_workflow_complete' => array(),
    // workflow complete and ready for download
    'download_targets_workflow_complete_count' => 0,
    'download_workflow_complete_targets' => array(),
    'download_targets_workflow_incomplete' => array(),
    // not workflow complete (but download if wanted)
    'download_targets_workflow_incomplete_count' => 0,
    'download_workflow_incomplete_targets' => array(),
  );
  if (empty($document_ids)) {
    return $report;
  }

  // if no documents are PENDING, then no need to make the API call.
  $response = lingotek_update_config_progress($document_ids);
  $locales = lingotek_get_target_locales();
  foreach ($document_ids as $document_id) {
    if (!$document_id) {
      continue;
    }
    foreach ($locales as $locale) {
      if (isset($response->byDocumentIdAndTargetLocale->{$document_id}->{$locale})) {
        $target_status = self::getTargetStatus($document_id, $locale);
        $doc_target = array(
          'document_id' => $document_id,
          'locale' => $locale,
          'percent_complete' => $response->byDocumentIdAndTargetLocale->{$document_id}->{$locale},
        );
        if ($target_status == self::STATUS_READY) {
          $report['download_targets_workflow_complete'][] = $doc_target;
          $report['download_targets_workflow_complete_count']++;
        }
        elseif ($target_status == self::STATUS_PENDING) {
          $report['download_targets_workflow_incomplete'][] = $doc_target;
          $report['download_targets_workflow_incomplete_count']++;
        }
      }
    }
  }
  return $report;
}