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 {
/**
*This is a representation of the query and subquery we are building to get
*the usage for each profile.
*@author t.murphy, smithworx, jbhovik, clarticus
*
*
*SELECT count(*) as COUNT, entity_type as ENTITY_TYPE
*FROM lingotek_entity_metadata
*WHERE entity_key = 'profile'
*AND value = '<profile_id>'
*AND entity_id NOT IN
* (SELECT entity_id
* FROM lingotek_entity_metadata
* WHERE entity_key = 'upload_status'
* AND value = 'TARGET')
*GROUP BY entity_type;
*
*/
$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;
}
}