Fix certificate generation BT#13574

ofaj
jmontoyaa 8 years ago committed by Nicolas Ducoulombier
parent 56628d8a03
commit 71de1d3d98
  1. 75
      main/inc/lib/certificate.lib.php

@ -84,6 +84,54 @@ class Certificate extends Model
$pathinfo = pathinfo($this->certificate_data['path_certificate']);
$this->html_file = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
$this->qr_file = $this->certification_user_path.$pathinfo['filename'].'_qr.png';
} else {
// General certificate
$name = md5($this->user_id).'.html';
$my_path_certificate = $this->certification_user_path.$name;
$path_certificate = '/'.$name;
// Getting QR filename
$file_info = pathinfo($path_certificate);
$qr_code_filename = $this->certification_user_path.$file_info['filename'].'_qr.png';
$content = $this->generateCustomCertificate();
$my_new_content_html = str_replace(
'((certificate_barcode))',
Display::img(
$this->certification_web_user_path.$file_info['filename'].'_qr.png',
'QR'
),
$content
);
$my_new_content_html = mb_convert_encoding(
$my_new_content_html,
'UTF-8',
api_get_system_encoding()
);
$this->html_file = $my_path_certificate;
$result = @file_put_contents($my_path_certificate, $my_new_content_html);
if ($result) {
// Updating the path
self::updateUserCertificateInfo(
0,
$this->user_id,
$path_certificate
);
$this->certificate_data['path_certificate'] = $path_certificate;
if ($this->isHtmlFileGenerated()) {
if (!empty($file_info)) {
//$text = $this->parse_certificate_variables($new_content_html['variables']);
//$this->generate_qr($text, $qr_code_filename);
}
}
}
return $result;
}
}
@ -355,12 +403,11 @@ class Certificate extends Model
}
/**
* update user info about certificate
* @param int $cat_id category id
* @param int $user_id user id
* @param string $path_certificate the path name of the certificate
* @return void
*/
* Update user info about certificate
* @param int $cat_id category id
* @param int $user_id user id
* @param string $path_certificate the path name of the certificate
*/
public function updateUserCertificateInfo(
$cat_id,
$user_id,
@ -586,12 +633,19 @@ class Certificate extends Model
$allCoursesApproved = [];
foreach ($session['courses'] as $course) {
$courseInfo = api_get_course_info_by_id($course['real_id']);
$gradebookCategories = Category::load(null, null, $courseInfo['code'], null, false, $session['session_id']);
$gradebookCategories = Category::load(
null,
null,
$courseInfo['code'],
null,
false,
$session['session_id']
);
if (isset($gradebookCategories[0])) {
/** @var Category $category */
$category = $gradebookCategories[0];
// $categoryId = $category->get_id();
// $categoryId = $category->get_id();
// @todo how we check if user pass a gradebook?
//$certificateInfo = GradebookUtils::get_certificate_by_user_id($categoryId, $this->user_id);
@ -618,13 +672,14 @@ class Certificate extends Model
$skill = new Skill();
$skills = $skill->getStudentSkills($this->user_id);
$time = api_time_to_hms(Tracking::get_time_spent_on_the_platform($this->user_id));
$time = Tracking::get_time_spent_on_the_platform($this->user_id);
$timeFormatted = api_time_to_hms($time);
$tplContent = new Template(null, false, false, false, false, false);
// variables for the default template
$tplContent->assign('complete_name', $userInfo['complete_name']);
$tplContent->assign('time_in_platform', $time);
$tplContent->assign('time_in_platform', $timeFormatted);
$tplContent->assign('certificate_generated_date', api_get_local_time($myCertificate['created_at']));
$tplContent->assign('terms_validation_date', api_get_local_time($termsValidationDate));

Loading…
Cancel
Save