You are here

public function UserStatisticsManager::renderUserTrainingsCharts in Opigno statistics 3.x

Prepare the render array to display the user training charts.

Parameters

int $uid: The user ID to get stats for.

Return value

array The render array to display the user training charts.

File

src/Services/UserStatisticsManager.php, line 473

Class

UserStatisticsManager
User statistics manager service definition.

Namespace

Drupal\opigno_statistics\Services

Code

public function renderUserTrainingsCharts(int $uid = 0) : array {
  $uid = $uid ?: $this->currentUid;
  $completed = $this
    ->getGroupedUserTrainingsNumber($uid);
  $current = $this
    ->getGroupedUserTrainingsNumber($uid, 'pending');
  return [
    '#theme' => 'opigno_user_training_charts',
    '#attached' => [
      'library' => [
        'opigno_statistics/opigno_charts',
      ],
      'drupalSettings' => [
        'opignoCharts' => [
          'completedTrainings' => $this
            ->buildBarChart($completed, "#user-completed-trainings-chart"),
          'currentTrainings' => $this
            ->buildBarChart($current, "#user-current-trainings-chart"),
        ],
      ],
    ],
  ];
}