public function Progress::getProgressBuildAchievementsPage in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Progress.php \Drupal\opigno_learning_path\Progress::getProgressBuildAchievementsPage()
Get get progress for achievements page.
Parameters
int $group_id: Group ID.
int $uid: User ID.
int $latest_cert_date: Latest certification date.
Return value
array Renderable array.
1 call to Progress::getProgressBuildAchievementsPage()
- Progress::getProgressBuild in src/
Progress.php - Get get progress bar it self.
File
- src/
Progress.php, line 495
Class
- Progress
- Class JoinService.
Namespace
Drupal\opigno_learning_pathCode
public function getProgressBuildAchievementsPage($group_id, $account_id, $latest_cert_date) {
$group = Group::load($group_id);
$account = User::load($account_id);
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
/** @var \Drupal\group\Entity\GroupContent $member */
$member = $group
->getMember($account)
->getGroupContent();
$registration = $member
->getCreatedTime();
$registration = $date_formatter
->format($registration, 'custom', 'm/d/Y');
// Get data from achievements.
$query = $this->database
->select('opigno_learning_path_achievements', 'a')
->fields('a', [
'score',
'progress',
'time',
'completed',
])
->condition('a.gid', $group_id)
->condition('a.uid', $account_id)
->condition('a.status', 'completed');
$achievements_data = $query
->execute()
->fetchAssoc();
if ($achievements_data) {
if ($achievements_data['completed']) {
$format = 'Y-m-d H:i:s';
$completed = DrupalDateTime::createFromFormat($format, $achievements_data['completed']);
$validation = $completed
->format('F d, Y');
}
if ($achievements_data['score']) {
$score = $achievements_data['score'];
}
if ($achievements_data['progress']) {
$progress = $achievements_data['progress'];
}
if ($achievements_data['time']) {
$time_spent = $date_formatter
->formatInterval($achievements_data['time']);
}
}
else {
$validation = opigno_learning_path_completed_on($group_id, $account_id, TRUE);
$validation = $validation > 0 ? $date_formatter
->format($validation, 'custom', 'F d, Y') : '';
$time_spent = opigno_learning_path_get_time_spent($group_id, $account_id);
$time_spent = $date_formatter
->formatInterval($time_spent);
$score = round(opigno_learning_path_get_score($group_id, $account_id, FALSE, $latest_cert_date));
$progress = $this
->getProgressRound($group_id, $account_id, $latest_cert_date);
}
$expiration_message = '';
$expiration_set = LPStatus::isCertificateExpireSet($group);
$expired = FALSE;
if ($expiration_set) {
if ($expiration_timestamp = LPStatus::getCertificateExpireTimestamp($group
->id(), $account_id)) {
if (!LPStatus::isCertificateExpired($group, $account_id)) {
$expiration_message = $this
->t('Valid until');
}
else {
$expired = TRUE;
$expiration_message = $this
->t('Expired on');
}
$expiration_message = $expiration_message . ' ' . $date_formatter
->format($expiration_timestamp, 'custom', 'F d, Y');
}
}
if ($achievements_data) {
// Use cached result.
$is_attempted = TRUE;
$is_passed = TRUE;
}
else {
// Check the actual data.
$is_attempted = opigno_learning_path_is_attempted($group, $account_id);
$is_passed = opigno_learning_path_is_passed($group, $account_id);
}
if ($is_passed) {
$state_class = 'passed';
}
elseif ($progress == 100 && !opigno_learning_path_is_passed($group, $account_id)) {
$state_class = 'failed';
}
elseif ($is_attempted) {
$state_class = 'in progress';
}
elseif ($expired) {
$state_class = 'expired';
}
else {
$state_class = 'not started';
}
$validation_message = !empty($validation) ? t('Validation date: @date<br />', [
'@date' => $validation,
]) : '';
$has_certificate = !$group
->get('field_certificate')
->isEmpty();
return [
'#theme' => 'opigno_learning_path_training_summary',
'#progress' => $progress,
'#score' => $score,
'#group_id' => $group_id,
'#has_certificate' => $has_certificate,
'#is_passed' => $is_passed,
'#state_class' => $state_class,
'#registration_date' => $registration,
'#validation_message' => $validation_message . $expiration_message,
'#time_spend' => $time_spent,
'#certificate_url' => $has_certificate && $is_passed ? Url::fromUri('internal:/certificate/group/' . $group_id . '/pdf') : FALSE,
];
}