protected function DashboardForm::buildTrainingsProgress in Opigno statistics 8
Same name and namespace in other branches
- 3.x src/Form/DashboardForm.php \Drupal\opigno_statistics\Form\DashboardForm::buildTrainingsProgress()
Builds trainings progress.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $datetime: Date.
mixed $lp_ids: LP ID.
Return value
array Render array.
Throws
\Exception
1 call to DashboardForm::buildTrainingsProgress()
- DashboardForm::buildForm in src/
Form/ DashboardForm.php - Form constructor.
File
- src/
Form/ DashboardForm.php, line 147
Class
- DashboardForm
- Implements the statistics dashboard.
Namespace
Drupal\opigno_statistics\FormCode
protected function buildTrainingsProgress(DrupalDateTime $datetime, $lp_ids = NULL) {
$progress = 0;
$completion = 0;
$time_str = $datetime
->format(DrupalDateTime::FORMAT);
$query = $this->database
->select('opigno_learning_path_achievements', 'a');
$query
->addExpression('SUM(a.progress) / COUNT(a.progress) / 100', 'progress');
$query
->addExpression('COUNT(a.completed) / COUNT(a.registered)', 'completion');
$query
->fields('a', [
'name',
])
->groupBy('a.name')
->orderBy('a.name')
->condition('a.registered', $time_str, '<');
if (is_array($lp_ids)) {
$query
->condition('a.gid', $lp_ids, 'IN');
$query
->leftJoin('group_content_field_data', 'g_c_f_d', 'a.uid = g_c_f_d.entity_id AND g_c_f_d.gid = a.gid');
$query
->condition('g_c_f_d.type', 'learning_path-group_membership');
}
$query
->condition('a.uid', 0, '<>');
$or_group = $query
->orConditionGroup();
$or_group
->condition('a.completed', $time_str, '<');
$or_group
->isNull('a.completed');
$data = $query
->execute()
->fetchAll();
$count = count($data);
if ($count > 0) {
foreach ($data as $row) {
$progress += $row->progress;
$completion += $row->completion;
}
$progress /= $count;
$completion /= $count;
}
return [
'#type' => 'container',
'#attributes' => [
'class' => [
'trainings-progress',
],
],
'progress' => $this
->buildValueWithIndicator($this
->t('Training Progress'), $progress, NULL, t('Training progress is calculated as the sum of training progress for all published trainings divided by the total number of published trainings.
The training progress for a training is the sum of progress for all the users registered to the training divided by the number of users registered to the training.')),
'completion' => $this
->buildValueWithIndicator($this
->t('Training Completion'), $completion, NULL, t('Training completion is calculated as the sum of training completion rate for all published trainings divided by the total number of published trainings.
The training completion for a training is the total number of users being successful at the training divided by the number of users registered to the training.')),
'users' => $this
->buildUsersPerDay($datetime, $lp_ids),
];
}