function lingotek_get_entities_by_profile_and_entity_type in Lingotek Translation 7.5
Same name and namespace in other branches
- 7.6 lingotek.util.inc \lingotek_get_entities_by_profile_and_entity_type()
5 calls to lingotek_get_entities_by_profile_and_entity_type()
- LingotekSync::getEntitySourceCount in lib/
Drupal/ lingotek/ LingotekSync.php - LingotekSync::getEntityTargetCountByStatus in lib/
Drupal/ lingotek/ LingotekSync.php - Get a count of translation targets by entity and status.
- lingotek_get_all_entities_by_profile in ./
lingotek.util.inc - lingotek_get_enabled_entities_by_type in ./
lingotek.util.inc - Get all entities enabled for Lingotek, by entity type
- lingotek_grid_get_rows in ./
lingotek.bulk_grid.inc - Dynamic query processing function for the grid Since the header defines which columns are shown, this query gets all possible values and refines the header using the columns selected in the UI The filters are also processed here
File
- ./
lingotek.util.inc, line 1508 - Utility functions.
Code
function lingotek_get_entities_by_profile_and_entity_type($profile_id, $entity_type) {
// get all bundles that belong to the given profile
$all_bundles = lingotek_get_bundles_by_profile_id($profile_id);
// this function accepts an id or an array of ids
$bundles = array();
$entities = array();
if (isset($all_bundles[$entity_type])) {
$bundles = array(
$entity_type => $all_bundles[$entity_type],
);
}
// get all entities that belond to those bundles
foreach ($bundles as $entity_type => $entity_bundles) {
if ($entity_type == 'comment') {
$ref_tables = array();
foreach (array_keys($entity_bundles) as $key) {
$tmp_array = explode('_', $key);
$key = implode('_', array_slice($tmp_array, 2));
$ref_tables[] = $key;
}
$query = db_select('{' . $entity_type . '}', 'e')
->fields('e', array(
'cid',
));
$query
->join('{node}', 'n', "n.nid = e.nid AND n.type IN ('" . implode("','", $ref_tables) . "')");
$results = $query
->execute()
->fetchCol();
foreach ($results as $id) {
$entities[] = array(
'id' => $id,
'type' => $entity_type,
);
}
}
else {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', array_keys($entity_bundles), 'IN');
$result = $query
->execute();
unset($query);
if (isset($result[$entity_type])) {
foreach ($result[$entity_type] as $id => $entity_data) {
$entities[] = array(
'id' => $id,
'type' => $entity_type,
);
}
}
}
// END OPTIMIZED WAY
}
// subtract all entities specifically *not* set to the given profile
$query = db_select('{lingotek_entity_metadata}', 'lem')
->fields('lem', array(
'entity_id',
'entity_type',
))
->condition('lem.entity_key', 'profile')
->condition('lem.value', $profile_id, is_array($profile_id) ? 'NOT IN' : '!=')
->condition('lem.entity_type', $entity_type);
$result = $query
->execute();
$subtract_entity_ids = $result
->fetchAll();
$doc_ids = lingotek_get_document_id_tree();
$subtractions = array();
foreach ($subtract_entity_ids as $sei) {
if (!isset($subtractions[$sei->entity_type])) {
$subtractions[$sei->entity_type] = array();
}
$subtractions[$sei->entity_type][$sei->entity_id] = TRUE;
}
$filtered_entities = array();
foreach ($entities as $e) {
if (!isset($subtractions[$e['type']][$e['id']])) {
if (isset($doc_ids[$e['type']][$e['id']])) {
$e['document_id'] = $doc_ids[$e['type']][$e['id']];
}
$filtered_entities[$e['id']] = $e;
}
}
// add all entities specifically set to the given profile
$query = db_select('{lingotek_entity_metadata}', 'lem')
->fields('lem', array(
'entity_id',
'entity_type',
))
->condition('lem.entity_key', 'profile')
->condition('lem.value', $profile_id, is_array($profile_id) ? 'IN' : '=');
if ($entity_type != 'all') {
$query
->condition('lem.entity_type', $entity_type);
}
$result = $query
->execute();
$add_entity_ids = $result
->fetchAll();
foreach ($add_entity_ids as $aei) {
$addition = array(
'id' => $aei->entity_id,
'type' => $aei->entity_type,
);
if (isset($doc_ids[$aei->entity_type][$aei->entity_id])) {
$addition['document_id'] = $doc_ids[$aei->entity_type][$aei->entity_id];
}
$filtered_entities[$aei->entity_id] = $addition;
}
return $filtered_entities;
}