function tmgmt_job_item_load_latest

Loads active 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

9 calls to tmgmt_job_item_load_latest()
ConfigSourcePluginUi::overviewRow in sources/tmgmt_config/src/ConfigSourcePluginUi.php
Builds a table row for overview form.
ConfigSourcePluginUi::overviewRowSimple in sources/tmgmt_config/src/ConfigSourcePluginUi.php
Builds a table row for simple configuration.
ConfigTranslateForm::buildForm in sources/tmgmt_config/src/Form/ConfigTranslateForm.php
ContentEntitySourcePluginUi::overviewRow in sources/content/src/ContentEntitySourcePluginUi.php
Builds a table row for overview form.
ContentTranslateForm::buildForm in sources/content/src/Form/ContentTranslateForm.php

... See full list

File

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

Code

function tmgmt_job_item_load_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('tj.state', [
    Job::STATE_UNPROCESSED,
    Job::STATE_ACTIVE,
    Job::STATE_CONTINUOUS,
  ], 'IN')
    ->condition('tji.state', [
    JobItem::STATE_ACCEPTED,
    JobItem::STATE_ABORTED,
  ], 'NOT IN')
    ->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 FALSE;
}