public function LingotekProfile::getUsage in Lingotek Translation 7.7
File
- lib/Drupal/lingotek/LingotekProfile.php, line 161
- Defines LingotekProfile
Class
- LingotekProfile
- A class wrapper for Lingotek Profiles
Code
public function getUsage($by_bundle = FALSE) {
if ($by_bundle) {
$bundles_using_profile = lingotek_get_bundles_by_profile_id($this
->getId());
$count_types = 0;
foreach ($bundles_using_profile as $bup) {
$count_types += count($bup);
}
return $count_types;
}
else {
$subquery = db_select('lingotek_entity_metadata', 'lem')
->fields('lem', array(
'entity_id',
))
->condition('lem.entity_key', 'upload_status')
->condition('lem.value', 'TARGET');
$entity_ids = $subquery
->execute()
->fetchCol();
$query = db_select('lingotek_entity_metadata', 'lem')
->fields('lem', array(
'entity_type',
))
->condition('lem.entity_key', 'profile')
->condition('lem.value', $this
->getId());
if (!empty($entity_ids)) {
$query
->condition('lem.entity_id', $entity_ids, 'NOT IN');
}
$query
->groupBy('lem.entity_type');
$query
->addExpression('count(lem.entity_id)', 'COUNT');
$entities = $query
->execute()
->fetchAll();
$entity_counts = array();
foreach ($entities as $e) {
$entity_counts[$e->entity_type] = $e->COUNT;
}
return $entity_counts;
}
}