public static function LingotekSync::getEntitySourceCount in Lingotek Translation 7.6
Same name and namespace in other branches
- 7.7 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntitySourceCount()
- 7.5 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntitySourceCount()
1 call to LingotekSync::getEntitySourceCount()
- LingotekSync::getSourceCounts in lib/
Drupal/ lingotek/ LingotekSync.php
File
- lib/
Drupal/ lingotek/ LingotekSync.php, line 277 - LingotekSync
Class
- LingotekSync
- A utility class for Lingotek Syncing.
Code
public static function getEntitySourceCount($lingotek_locale, $entity_type = NULL) {
$managed_entities = lingotek_managed_entity_types();
$drupal_language_code = Lingotek::convertLingotek2Drupal($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')
->condition('t.language', $drupal_language_code);
// 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 entities (including those that have disabled bundles)
$disabled_entities = lingotek_get_entities_by_profile_and_entity_type(LingotekSync::PROFILE_DISABLED, $entity_type);
if (count($disabled_entities)) {
$disabled_entity_ids = array();
array_walk($disabled_entities, function ($a) use (&$disabled_entity_ids) {
$disabled_entity_ids[] = $a['id'];
});
$enabled_entity_ids = lingotek_get_enabled_entities_by_type($entity_type);
if (count($disabled_entity_ids) < count($enabled_entity_ids)) {
$query
->condition($properties['entity keys']['id'], array_merge(array(
-1,
), $disabled_entity_ids), "NOT IN");
//exclude disabled entities
}
else {
$query
->condition($properties['entity keys']['id'], array_merge(array(
-1,
), $enabled_entity_ids), "IN");
//include only eabled entities
}
}
$count = $query
->countQuery()
->execute()
->fetchField();
$total_count += $count;
}
return $total_count;
}