function tmgmt_local_task_statistics_load

Loads an array with the word and status statistics of a task.

Parameters

$tltids: An array of local task ids.

Return value

An array of objects with the keys word_count, count_pending, count_accepted, count_translated and loop_count.

1 call to tmgmt_local_task_statistics_load()
tmgmt_local_task_statistic in translators/tmgmt_local/tmgmt_local.module
Returns a specific statistic of a task.

File

translators/tmgmt_local/tmgmt_local.module, line 287
Main module file for the local translation module.

Code

function tmgmt_local_task_statistics_load(array $tltids) {
  $statistics =& drupal_static(__FUNCTION__, array());

  // First try to get the values from the cache.
  $return = array();
  $tltids_to_load = array();
  foreach ($tltids as $tltid) {
    if (isset($statistics[$tltid])) {

      // Info exists in cache, get it from there.
      $return[$tltid] = $statistics[$tltid];
    }
    else {

      // Info doesn't exist in cache, add job to the list that needs to be
      // fetched.
      $tltids_to_load[] = $tltid;
    }
  }

  // If there are remaining jobs, build a query to fetch them.
  if (!empty($tltids_to_load)) {

    // Build the query to fetch the statistics.
    $query = \Drupal::database()
      ->select('tmgmt_local_task_item', 'tlti');
    $query
      ->join('tmgmt_local_task', 'tlt', 'tlt.tltid = tlti.tltid');
    $query
      ->join('tmgmt_job_item', 'tji', 'tji.tjiid = tlti.tjiid');
    $query
      ->fields('tlt', array(
      'tltid',
    ));
    $query
      ->addExpression('SUM(tji.word_count)', 'word_count');
    $query
      ->addExpression('SUM(tlti.count_untranslated)', 'count_untranslated');
    $query
      ->addExpression('SUM(tlti.count_translated)', 'count_translated');
    $query
      ->addExpression('SUM(tlti.count_completed)', 'count_completed');
    $result = $query
      ->groupBy('tlt.tltid')
      ->condition('tlt.tltid', (array) $tltids_to_load, 'IN')
      ->execute();
    foreach ($result as $row) {
      $return[$row->tltid] = $statistics[$row->tltid] = $row;
    }
  }
  return $return;
}