private function UserStatisticsManager::prepareChartData in Opigno statistics 3.x
Prepare the data to build the bar chart by user trainings.
Parameters
array $data: The data for the chart.
Return value
array The data to build the bar chart by user trainings.
1 call to UserStatisticsManager::prepareChartData()
- UserStatisticsManager::getGroupedUserTrainingsNumber in src/
Services/ UserStatisticsManager.php - Get the number of user trainings with status grouped by the period of time.
File
- src/
Services/ UserStatisticsManager.php, line 224
Class
- UserStatisticsManager
- User statistics manager service definition.
Namespace
Drupal\opigno_statistics\ServicesCode
private function prepareChartData(array $data) : array {
$result = [];
$timestamp = strtotime('today');
// Get the first week number. We'll display 5 weeks for each month.
$i = 5;
do {
$week = $this->dateFormatter
->format($timestamp, 'custom', 'W');
$key = $this
->t('Week') . $i;
$result[$key] = isset($data[$week]) ? $data[$week]->count : 0;
// Subtract 1 week from the timestamp.
$timestamp -= 604800;
$i--;
} while ($i > 0);
ksort($result);
return $result;
}