function tmgmt_job_statistics_load in Translation Management Tool 8
Same name and namespace in other branches
- 7 tmgmt.module \tmgmt_job_statistics_load()
Loads an array with the word and status statistics of a job.
Parameters
$tjids: An array of job ids.
Return value
An array of objects with the keys word_count, tags_count, count_pending, count_accepted, count_reviewed and count_translated.
Related topics
2 calls to tmgmt_job_statistics_load()
- StatisticsBase::preRender in src/
Plugin/ views/ field/ StatisticsBase.php - Prefetch statistics for all jobs.
- tmgmt_job_statistic in ./
tmgmt.module - Returns a specific statistic of a job.
2 string references to 'tmgmt_job_statistics_load'
- CrudTest::testJobItemsCounters in tests/
src/ Kernel/ CrudTest.php - Test the calculations of the counters.
- JobItem::preSave in src/
Entity/ JobItem.php - Acts on an entity before the presave hook is invoked.
File
- ./
tmgmt.module, line 317 - Main module file for the Translation Management module.
Code
function tmgmt_job_statistics_load(array $tjids) {
$statistics =& drupal_static(__FUNCTION__, array());
// First try to get the values from the cache.
$return = array();
$tjids_to_load = array();
foreach ($tjids as $tjid) {
if (isset($statistics[$tjid])) {
// Info exists in cache, get it from there.
$return[$tjid] = $statistics[$tjid];
}
else {
// Info doesn't exist in cache, add job to the list that needs to be
// fetched.
$tjids_to_load[] = $tjid;
}
}
// If there are remaining jobs, build a query to fetch them.
if (!empty($tjids_to_load)) {
// Build the query to fetch the statistics.
$query = \Drupal::database()
->select('tmgmt_job_item', 'tji')
->fields('tji', array(
'tjid',
));
$query
->addExpression('SUM(word_count)', 'word_count');
$query
->addExpression('SUM(tags_count)', 'tags_count');
$query
->addExpression('SUM(count_accepted)', 'count_accepted');
$query
->addExpression('SUM(count_reviewed)', 'count_reviewed');
$query
->addExpression('SUM(count_pending)', 'count_pending');
$query
->addExpression('SUM(count_translated)', 'count_translated');
$result = $query
->groupBy('tjid')
->condition('tjid', (array) $tjids_to_load, 'IN')
->execute();
foreach ($result as $row) {
$return[$row->tjid] = $statistics[$row->tjid] = $row;
}
}
return $return;
}