protected function DashboardForm::buildSkillsTable in Opigno statistics 8
Same name and namespace in other branches
- 3.x src/Form/DashboardForm.php \Drupal\opigno_statistics\Form\DashboardForm::buildSkillsTable()
Builds skills listing.
Return value
array Render array.
1 call to DashboardForm::buildSkillsTable()
- DashboardForm::buildForm in src/
Form/ DashboardForm.php - Form constructor.
File
- src/
Form/ DashboardForm.php, line 531
Class
- DashboardForm
- Implements the statistics dashboard.
Namespace
Drupal\opigno_statistics\FormCode
protected function buildSkillsTable() {
$query = $this->database
->select('opigno_skills_statistic', 'a')
->fields('a', [
'tid',
]);
$query
->addExpression('AVG(a.score)', 'score');
$query
->addExpression('AVG(a.progress)', 'progress');
$query
->groupBy('tid');
$rows = $query
->execute()
->fetchAllAssoc('tid');
$rows = array_map(function ($row) {
$score = [
'data' => $this
->buildScore(round($row->score)),
];
$progress = [
'data' => $this
->buildScore(round($row->progress)),
];
$term = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->load($row->tid);
if (!empty($term)) {
$skill_name = $term
->getName();
return [
'class' => 'training',
'data-training' => $row->tid,
'data' => [
$skill_name,
$score,
$progress,
],
];
}
}, $rows);
$rows = array_filter($rows);
if (empty($rows)) {
return [];
}
return [
'#type' => 'container',
'#attributes' => [
'class' => [
'skills-list',
],
],
'table' => [
'#type' => 'table',
'#attributes' => [
'class' => [
'statistics-table',
'skills-list',
'table-striped',
],
],
'#header' => [
$this
->t('Skill'),
$this
->t('Score'),
$this
->t('Progress'),
],
'#rows' => $rows,
],
];
}