function tmgmt_local_task_statistics_load in Translation Management Tool 8
Same name and namespace in other branches
- 7 translators/tmgmt_local/tmgmt_local.module \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.
2 calls to tmgmt_local_task_statistics_load()
- StatisticsBase::preRender in src/
Plugin/ views/ field/ StatisticsBase.php - Prefetch statistics for all jobs.
- tmgmt_local_task_statistic in translators/
tmgmt_local/ tmgmt_local.module - Returns a specific statistic of a task.
1 string reference to 'tmgmt_local_task_statistics_load'
- LocalTranslatorTest::testBasicWorkflow in translators/
tmgmt_local/ tests/ src/ Functional/ LocalTranslatorTest.php - Test the basic translation workflow.
File
- translators/
tmgmt_local/ tmgmt_local.module, line 286 - 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;
}