public function Progress::getProgressBuildGroupPage in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Progress.php \Drupal\opigno_learning_path\Progress::getProgressBuildGroupPage()
Get get progress for group 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::getProgressBuildGroupPage()
- Progress::getProgressBuild in src/
Progress.php - Get get progress bar it self.
File
- src/
Progress.php, line 255
Class
- Progress
- Class JoinService.
Namespace
Drupal\opigno_learning_pathCode
public function getProgressBuildGroupPage($group_id, $account_id, $latest_cert_date) {
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = Group::load($group_id);
$account = User::load($account_id);
$date_formatter = \Drupal::service('date.formatter');
$expiration_message = '';
$expiration_set = LPStatus::isCertificateExpireSet($group);
if ($expiration_set) {
if ($expiration_message = LPStatus::getCertificateExpireTimestamp($group
->id(), $account_id)) {
$expiration_message = ' ' . $date_formatter
->format($expiration_message, 'custom', 'F 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) {
$score = $achievements_data['score'];
$completed = $achievements_data['completed'];
if ($achievements_data['completed']) {
$format = 'Y-m-d H:i:s';
$completed = DrupalDateTime::createFromFormat($format, $achievements_data['completed']);
$completed = $completed
->format('F d, Y');
}
$state = $this
->t('Passed');
$progress = $achievements_data['progress'];
$is_passed = TRUE;
}
else {
$score = opigno_learning_path_get_score($group_id, $account_id);
$progress = $this
->getProgressRound($group_id, $account_id, $latest_cert_date);
$is_passed = opigno_learning_path_is_passed($group, $account_id);
$completed = opigno_learning_path_completed_on($group_id, $account_id);
$completed = $completed > 0 ? $date_formatter
->format($completed, 'custom', 'F d, Y') : '';
$state = $is_passed ? $this
->t('Passed') : $this
->t('Failed');
}
if ($is_passed || $progress == 100) {
// Expire message if necessary.
if ($expiration_set) {
// Expiration set, create expiration message.
if ($expiration_message) {
$expiration_message = ' - ' . $this
->t('Valid until') . $expiration_message;
}
}
$summary = [
'#type' => 'container',
'#attributes' => [
'class' => [
'lp_progress_summary',
],
],
// H2 Need for correct structure.
[
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this
->t('Progress status'),
'#attributes' => [
'class' => [
'sr-only',
],
],
],
[
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'class' => $is_passed ? [
'lp_progress_summary_passed',
] : [
'lp_progress_summary_failed',
],
],
'#value' => '',
],
[
'#type' => 'html_tag',
'#tag' => 'h3',
'#attributes' => [
'class' => [
'lp_progress_summary_title',
],
],
'#value' => $state . $expiration_message,
],
[
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'class' => [
'lp_progress_summary_score',
],
],
'#value' => $this
->t('Average score : @score%', [
'@score' => $score,
]),
],
!empty($completed) ? [
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'class' => [
'lp_progress_summary_date',
],
],
'#value' => $this
->t('Completed on @date', [
'@date' => $completed,
]),
] : [],
];
}
elseif ($expiration_set && LPStatus::isCertificateExpired($group, $account_id)) {
$summary = [
'#type' => 'container',
'#attributes' => [
'class' => [
'lp_progress_summary',
],
],
// H2 Need for correct structure.
[
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this
->t('Progress status'),
'#attributes' => [
'class' => [
'sr-only',
],
],
],
[
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'class' => [
'lp_progress_summary_expired',
],
],
'#value' => '',
],
[
'#type' => 'html_tag',
'#tag' => 'h3',
'#attributes' => [
'class' => [
'lp_progress_summary_title',
],
],
'#value' => $this
->t('Expired on') . ' ' . $expiration_message,
],
[
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => [
'class' => [
'lp_progress_summary_score',
],
],
'#value' => $this
->t('Please start this training again to get new certification'),
],
];
}
$content_progress = [
'#theme' => 'lp_progress',
'#progress' => $progress,
'#summary' => $this
->buildSummary($group, $account),
];
return $content_progress;
}