You are here

public static function LingotekSync::getEntityTargetCountByStatus in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntityTargetCountByStatus()
  2. 7.6 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntityTargetCountByStatus()

Get a count of translation targets by entity and status.

Parameters

mixed $status: a string or array of strings containing the desired status(es) to count

string $lingotek_locale: the desired locale to count

string $entity_type: the desired entity type to count

Return value

array

1 call to LingotekSync::getEntityTargetCountByStatus()
LingotekSync::getCountsByStatus in lib/Drupal/lingotek/LingotekSync.php

File

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

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

public static function getEntityTargetCountByStatus($status, $lingotek_locale, $entity_type = NULL) {
  if (!is_array($status)) {
    $status = array(
      -1,
      $status,
    );
  }
  $managed_entities = lingotek_managed_entity_types();
  $drupal_language_code = Lingotek::convertLingotek2Drupal($lingotek_locale);
  $target_prefix = 'target_sync_status_';
  $target_key = $target_prefix . $lingotek_locale;
  $q = array();
  $total_count = 0;
  foreach ($managed_entities as $m_entity_type => $properties) {
    if (!is_null($entity_type) && $entity_type != $m_entity_type) {
      continue;
    }
    $entity_base_table = $properties['base table'];
    $query = db_select($entity_base_table, 't');
    $query
      ->leftJoin('lingotek_entity_metadata', 'l', 'l.entity_id = ' . $properties['entity keys']['id'] . ' AND l.entity_type = \'' . $m_entity_type . '\'' . ' AND l.entity_key = \'' . $target_key . '\' ');

    // exclude translation sets (only for nodes)
    if ($entity_base_table == 'node') {
      $tnid_query = db_or();
      $tnid_query
        ->condition('t.tnid', 0);
      $tnid_query
        ->where('t.tnid = t.nid');
      $query
        ->condition($tnid_query);
    }

    // exclude disabled nodes (including those that have disabled bundles)
    $disabled_profile = LingotekProfile::loadById(LingotekSync::PROFILE_DISABLED);
    $disabled_entities = $disabled_profile
      ->getEntities($entity_base_table);
    if (!empty($disabled_entities)) {
      $disabled_entity_ids = array();
      array_walk($disabled_entities, function ($a) use (&$disabled_entity_ids) {
        $disabled_entity_ids[] = $a['id'];
      });
      $query
        ->condition("t." . $properties['entity keys']['id'], $disabled_entity_ids, "NOT IN");

      //exclude disabled entities
    }
    $query
      ->condition('l.value', $status, 'IN');

    // exclude orphaned targets (targets whose source language has been deleted)
    if (db_field_exists($entity_base_table, 'language')) {
      $query
        ->condition('t.language', '', '!=');
    }
    $count = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    $total_count += $count;
  }
  return $total_count;
}