public function UserController::buildSkillsTable in Opigno statistics 8
Builds render array for a user skills table.
Parameters
\Drupal\user\UserInterface $user: User.
Return value
array Render array.
1 call to UserController::buildSkillsTable()
- UserController::index in src/
Controller/ UserController.php - Builds render array for a user statistics index page.
File
- src/
Controller/ UserController.php, line 1459
Class
- UserController
- Class UserController.
Namespace
Drupal\opigno_statistics\ControllerCode
public function buildSkillsTable(UserInterface $user, $tree = FALSE) {
$query = $this->database
->select('opigno_skills_statistic', 'a')
->fields('a', [
'tid',
'score',
'progress',
'stage',
])
->condition('a.uid', $user
->id());
if ($tree) {
$query
->condition('a.tid', $tree, 'IN');
}
$rows = $query
->execute()
->fetchAll();
$rows = array_map(function ($row) use ($user) {
$score = [
'data' => $this
->buildScore($row->score),
];
$progress = [
'data' => $this
->buildScore($row->progress),
];
$term = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->load($row->tid);
$skill_name = $term
->getName();
$level = 'N/A';
$levels = $term
->get('field_level_names');
if (!empty($levels)) {
$levels = $levels
->getValue();
$count_of_levels = count($levels);
}
if (!empty($levels) && $count_of_levels != $row->stage) {
$level = $levels[$row->stage]['value'];
}
return [
'class' => 'training',
'data-training' => $row->tid,
'data' => [
$skill_name,
$score,
$progress,
$level,
],
];
}, $rows);
$rows = array_filter($rows);
if ($rows) {
return [
'#type' => 'container',
'#attributes' => [
'class' => [
'skills-list',
],
],
[
'#type' => 'table',
'#attributes' => [
'class' => [
'statistics-table',
'skills-list',
'table-striped',
],
],
'#header' => [
$this
->t('Skill'),
$this
->t('Score'),
$this
->t('Progress'),
$this
->t('Level'),
],
'#rows' => $rows,
],
];
}
else {
return [];
}
}