function tmgmt_job_statistics_load in Translation Management Tool 7
Same name and namespace in other branches
- 8 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, count_pending, count_accepted, count_reviewed and count_translated.
Related topics
3 calls to tmgmt_job_statistics_load()
- tmgmt_handler_field_tmgmt_progress::pre_render in views/
handlers/ tmgmt_handler_field_tmgmt_progress.inc - Prefetch statistics for all jobs.
- tmgmt_handler_field_tmgmt_wordcount::pre_render in views/
handlers/ tmgmt_handler_field_tmgmt_wordcount.inc - Prefetch statistics for all jobs.
- tmgmt_job_statistic in ./
tmgmt.module - Returns a specific statistic of a job.
1 string reference to 'tmgmt_job_statistics_load'
- TMGMTCRUDTestCase::testJobItemsCounters in tests/
tmgmt.crud.test - Test the calculations of the counters.
File
- ./
tmgmt.module, line 568 - 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 = db_select('tmgmt_job_item', 'tji')
->fields('tji', array(
'tjid',
));
$query
->addExpression('SUM(word_count)', 'word_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', $tjids_to_load)
->execute();
foreach ($result as $row) {
$return[$row->tjid] = $statistics[$row->tjid] = $row;
}
}
return $return;
}