function tmgmt_job_item_load_all_latest

Loads all latest job entities that have a job item with the identifiers.

Parameters

$plugin: The source plugin.

$item_type: The source item type.

$item_id: The source item id.

string $source_language: The source language of the item.

Return value

\Drupal\tmgmt\Entity\JobItem[] An array of job item entities.

Related topics

1 call to tmgmt_job_item_load_all_latest()
Job::cleanSuggestionsList in src/Entity/Job.php
Removes all suggestions from the given list which should not be processed.

File

./tmgmt.module, line 215
Main module file for the Translation Management module.

Code

function tmgmt_job_item_load_all_latest($plugin, $item_type, $item_id, $source_language) {
  $query = \Drupal::database()
    ->select('tmgmt_job_item', 'tji');
  $query
    ->innerJoin('tmgmt_job', 'tj', 'tj.tjid = tji.tjid');
  $result = $query
    ->condition('tj.source_language', $source_language)
    ->condition('tji.state', JobItem::STATE_ACCEPTED, '<>')
    ->condition('tji.plugin', $plugin)
    ->condition('tji.item_type', $item_type)
    ->condition('tji.item_id', $item_id)
    ->fields('tji', array(
    'tjiid',
  ))
    ->fields('tj', array(
    'target_language',
  ))
    ->orderBy('tji.changed', 'DESC')
    ->groupBy('tj.target_language')
    ->groupBy('tji.tjiid')
    ->groupBy('tji.changed')
    ->execute();
  if ($items = $result
    ->fetchAllKeyed()) {
    $return = array();
    foreach (JobItem::loadMultiple(array_keys($items)) as $key => $item) {
      $return[$items[$key]] = $item;
    }
    return $return;
  }
  return [];
}