Add quiz_generate_certificate_ending conf setting - refs BT#15760

Generate certificate when ending a quiz.
The quiz needs to be linked to a gradebook category and have set the pass percentage.
pull/2926/head
Angel Fernando Quiroz Campos 7 years ago
parent a32a49c965
commit 34f57596fc
  1. 21
      main/exercise/overview.php
  2. 33
      main/gradebook/lib/be/category.class.php
  3. 87
      main/inc/lib/exercise.lib.php
  4. 3
      main/install/configuration.dist.php
  5. 35
      main/lp/lp_final_item.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 .= '</div>';
if ($certificateBlock) {
$html .= PHP_EOL.$certificateBlock;
}
echo $html;
Display::display_footer();

@ -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 "
<div class='panel panel-default'>
<div class='panel-body'>
<h3 class='text-center'>".get_lang('NowDownloadYourCertificateClickHere')."</h3>
<div class='text-center'>$downloadLink $viewLink</div>
</div>
</div>
";
}
}

@ -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 '<h1 style="text-align : center; margin : 20px 0;">'.get_lang('YourResults').'</h1><br />';
@ -4770,6 +4775,15 @@ EOT;
);
}
$totalScoreText .= '</div>';
$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);
}
}

@ -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;

@ -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 = "
<div class='panel panel-default'>
<div class='panel-body'>
<h3 class='text-center'>".get_lang('NowDownloadYourCertificateClickHere')."</h3>
<div class='text-center'>$downloadCertificateLink $viewCertificateLink</div>
</div>
</div>
";
return $downloadCertificateLink;
}

Loading…
Cancel
Save