diff --git a/main/exercise/overview.php b/main/exercise/overview.php
index 09e51a2fd6..7f8b781b97 100755
--- a/main/exercise/overview.php
+++ b/main/exercise/overview.php
@@ -28,6 +28,7 @@ $htmlHeadXtra[] = $js;
// Notice for unauthorized people.
api_protect_course_script(true);
$sessionId = api_get_session_id();
+$courseCode = api_get_course_id();
$exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$objExercise = new Exercise();
@@ -210,9 +211,22 @@ if (in_array(
}
}
+$certificateBlock = '';
+
if (!empty($attempts)) {
$i = $counter;
foreach ($attempts as $attempt_result) {
+ if (empty($certificateBlock)) {
+ $certificateBlock = ExerciseLib::generateAndShowCertificateBlock(
+ $attempt_result['exe_result'],
+ $attempt_result['exe_weighting'],
+ $objExercise,
+ $attempt_result['exe_user_id'],
+ $courseCode,
+ $sessionId
+ );
+ }
+
$score = ExerciseLib::show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
$attempt_url = api_get_path(WEB_CODE_PATH).'exercise/result.php?';
$attempt_url .= api_get_cidreq().'&show_headers=1&';
@@ -241,7 +255,7 @@ if (!empty($attempts)) {
),
'userIp' => $attempt_result['user_ip'],
];
- $attempt_link .= ' '.$teacher_revised;
+ $attempt_link .= PHP_EOL.$teacher_revised;
if (in_array(
$objExercise->results_disabled,
@@ -430,6 +444,11 @@ $html .= Display::tag(
['class' => 'table-responsive']
);
$html .= '';
+
+if ($certificateBlock) {
+ $html .= PHP_EOL.$certificateBlock;
+}
+
echo $html;
Display::display_footer();
diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php
index ac8a0cb863..f24a0eb0e6 100755
--- a/main/gradebook/lib/be/category.class.php
+++ b/main/gradebook/lib/be/category.class.php
@@ -2242,7 +2242,8 @@ class Category implements GradebookItem
get_lang('DisplayCertificate'),
$url,
'eye',
- 'primary'
+ 'primary',
+ ['target' => '_blank']
);
$exportToPDF = Display::url(
@@ -2743,4 +2744,34 @@ class Category implements GradebookItem
return api_float_val($categoryScore);
}
+
+ /**
+ * Return HTML code with links to download and view certificate.
+ *
+ * @param array $certificate
+ *
+ * @return string
+ */
+ public static function getDownloadCertificateBlock(array $certificate)
+ {
+ if (!isset($certificate['pdf_url'])) {
+ return '';
+ }
+
+ $downloadLink = Display::toolbarButton(
+ get_lang('DownloadCertificatePdf'),
+ $certificate['pdf_url'],
+ 'file-pdf-o'
+ );
+ $viewLink = $certificate['certificate_link'];
+
+ return "
+
+
+
".get_lang('NowDownloadYourCertificateClickHere')."
+
$downloadLink $viewLink
+
+
+ ";
+ }
}
diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php
index 9043df6b8a..8bd35304bc 100644
--- a/main/inc/lib/exercise.lib.php
+++ b/main/inc/lib/exercise.lib.php
@@ -4405,9 +4405,13 @@ EOT;
$remainingMessage = ''
) {
$origin = api_get_origin();
+ $courseCode = api_get_course_id();
+ $courseId = api_get_course_int_id();
+ $sessionId = api_get_session_id();
// Getting attempt info
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
+ $studentInfo = api_get_user_info($exercise_stat_info['exe_user_id']);
// Getting question list
$question_list = [];
@@ -4521,11 +4525,10 @@ EOT;
if (($show_results || $show_only_score) && $origin !== 'embeddable') {
if (isset($exercise_stat_info['exe_user_id'])) {
- $user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
- if ($user_info) {
+ if ($studentInfo) {
// Shows exercise header
echo $objExercise->showExerciseResultHeader(
- $user_info,
+ $studentInfo,
$exercise_stat_info
);
}
@@ -4737,6 +4740,8 @@ EOT;
}
$totalScoreText = null;
+ $certificateBlock = '';
+
if (($show_results || $show_only_score) && $showTotalScore) {
if ($result['answer_type'] == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
echo ''.get_lang('YourResults').'
';
@@ -4770,6 +4775,15 @@ EOT;
);
}
$totalScoreText .= '';
+
+ $certificateBlock = self::generateAndShowCertificateBlock(
+ $total_score,
+ $total_weight,
+ $objExercise,
+ $studentInfo['id'],
+ $courseCode,
+ $sessionId
+ );
}
if ($result['answer_type'] == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
@@ -4804,6 +4818,7 @@ EOT;
);
echo $totalScoreText;
+ echo $certificateBlock;
// Ofaj change BT#11784
if (api_get_configuration_value('quiz_show_description_on_results_page') &&
@@ -5393,4 +5408,70 @@ EOT;
return $countAll === $countOfAllowed;
}
+
+ /**
+ * Generate a certificate linked to current quiz and.
+ * Return the HTML block with links to download and view the certificate.
+ *
+ * @param float $totalScore
+ * @param float $totalWeight
+ * @param Exercise $objExercise
+ * @param int $studentId
+ * @param string $courseCode
+ * @param int $sessionId
+ *
+ * @return string
+ */
+ public static function generateAndShowCertificateBlock(
+ $totalScore,
+ $totalWeight,
+ Exercise $objExercise,
+ $studentId,
+ $courseCode,
+ $sessionId = 0
+ )
+ {
+ if (!api_get_configuration_value('quiz_generate_certificate_ending') ||
+ !self::isSuccessExerciseResult($totalScore, $totalWeight, $objExercise->selectPassPercentage())
+ ) {
+ return '';
+ }
+
+ /** @var Category $category */
+ $category = Category::load(null, null, $courseCode, null, null, $sessionId, 'ORDER By id');
+
+ if (empty($category)) {
+ return '';
+ }
+
+ /** @var Category $category */
+ $category = $category[0];
+ $categoryId = $category->get_id();
+ $link = LinkFactory::load(
+ null,
+ null,
+ $objExercise->selectId(),
+ null,
+ $courseCode,
+ $categoryId
+ );
+
+ if (empty($link)) {
+ return '';
+ }
+
+ $resourceDeletedMessage = $category->show_message_resource_delete($courseCode);
+
+ if (false !== $resourceDeletedMessage || api_is_allowed_to_edit() || api_is_excluded_user_type()) {
+ return '';
+ }
+
+ $certificate = Category::generateUserCertificate($categoryId, $studentId);
+
+ if (!is_array($certificate)) {
+ return '';
+ }
+
+ return Category::getDownloadCertificateBlock($certificate);
+ }
}
diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php
index 141cb1ceca..0fa38887c9 100755
--- a/main/install/configuration.dist.php
+++ b/main/install/configuration.dist.php
@@ -575,6 +575,9 @@ $_configuration['send_all_emails_to'] = [
// Callback get the $exerciseId and $iconSize as parameters.
// e.g. ['myplugin' => ['MyPlugin', 'urlGeneratorCallback']]
//$_configuration['exercise_additional_teacher_modify_actions'] = []
+// Generate certificate when ending a quiz.
+// The quiz needs to be linked to a gradebook category and have set the pass percentage.
+//$_configuration['quiz_generate_certificate_ending'] = false;
// Hide search form in session list
//$_configuration['hide_search_form_in_session_list'] = false;
diff --git a/main/lp/lp_final_item.php b/main/lp/lp_final_item.php
index 8ee476a673..22fd1a5a0d 100644
--- a/main/lp/lp_final_item.php
+++ b/main/lp/lp_final_item.php
@@ -146,12 +146,8 @@ if ($accessGranted == false) {
if (!empty($certificate['pdf_url']) ||
!empty($certificate['badge_link'])
) {
- if (is_array($certificate) &&
- isset($certificate['pdf_url'])
- ) {
- $downloadCertificateLink = generateLPFinalItemTemplateCertificateLinks(
- $certificate
- );
+ if (is_array($certificate)) {
+ $downloadCertificateLink = Category::getDownloadCertificateBlock($certificate);
}
if (is_array($certificate) &&
@@ -287,30 +283,3 @@ function generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId =
return $badgeLink;
}
-
-/**
- * Return HTML string with certificate links.
- *
- * @param array $certificate
- *
- * @return string HTML string for certificates
- */
-function generateLPFinalItemTemplateCertificateLinks($certificate)
-{
- $downloadCertificateLink = Display::url(
- Display::returnFontAwesomeIcon('file-pdf-o').get_lang('DownloadCertificatePdf'),
- $certificate['pdf_url'],
- ['class' => 'btn btn-default']
- );
- $viewCertificateLink = $certificate['certificate_link'];
- $downloadCertificateLink = "
-
-
-
".get_lang('NowDownloadYourCertificateClickHere')."
-
$downloadCertificateLink $viewCertificateLink
-
-
- ";
-
- return $downloadCertificateLink;
-}