@@ -73,9 +73,8 @@ public function __construct($certificate_id = 0, $userId = 0)
7373 }
7474 }
7575
76- //Setting the qr and html variables
77- if (
78- isset ($ certificate_id ) &&
76+ // Setting the qr and html variables
77+ if (isset ($ certificate_id ) &&
7978 !empty ($ this ->certification_user_path ) &&
8079 isset ($ this ->certificate_data ['path_certificate ' ])
8180 ) {
@@ -92,7 +91,7 @@ public function check_certificate_path()
9291 {
9392 $ this ->certification_user_path = null ;
9493
95- //Setting certification path
94+ // Setting certification path
9695 $ path_info = UserManager::getUserPathById ($ this ->user_id , 'system ' );
9796 $ web_path_info = UserManager::getUserPathById ($ this ->user_id , 'web ' );
9897
@@ -212,7 +211,10 @@ public function generate($params = array())
212211
213212 $ my_new_content_html = str_replace (
214213 '((certificate_barcode)) ' ,
215- Display::img ($ this ->certification_web_user_path .$ file_info ['filename ' ].'_qr.png ' , 'QR ' ),
214+ Display::img (
215+ $ this ->certification_web_user_path .$ file_info ['filename ' ].'_qr.png ' ,
216+ 'QR '
217+ ),
216218 $ new_content_html ['content ' ]
217219 );
218220
@@ -262,10 +264,10 @@ public function update_user_info_about_certificate(
262264 $ user_id ,
263265 $ path_certificate
264266 ) {
265- $ table_certificate = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CERTIFICATE );
267+ $ table = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CERTIFICATE );
266268 $ now = api_get_utc_datetime ();
267269 if (!UserManager::is_user_certified ($ cat_id , $ user_id )) {
268- $ sql = 'UPDATE ' .$ table_certificate .' SET
270+ $ sql = 'UPDATE ' .$ table .' SET
269271 path_certificate=" ' .Database::escape_string ($ path_certificate ).'",
270272 created_at = " ' .$ now .'"
271273 WHERE cat_id=" ' .intval ($ cat_id ).'" AND user_id=" ' .intval ($ user_id ).'" ' ;
@@ -295,9 +297,10 @@ public function html_file_is_generated()
295297
296298 /**
297299 * Generates a QR code for the certificate. The QR code embeds the text given
298- * @param string $text Text to be added in the QR code
299- * @param string $path file path of the image
300- * */
300+ * @param string $text Text to be added in the QR code
301+ * @param string $path file path of the image
302+ * @return bool
303+ **/
301304 public function generate_qr ($ text , $ path )
302305 {
303306 //Make sure HTML certificate is generated
@@ -427,6 +430,23 @@ public function show()
427430 $ user_certificate = $ this ->certification_user_path .basename ($ this ->certificate_data ['path_certificate ' ]);
428431 if (file_exists ($ user_certificate )) {
429432 $ certificateContent = (string ) file_get_contents ($ user_certificate );
433+
434+ if ($ this ->user_id == api_get_user_id () && !empty ($ this ->certificate_data )) {
435+ $ certificateId = $ this ->certificate_data ['id ' ];
436+ $ extraFieldValue = new ExtraFieldValue ('user_certificate ' );
437+ $ value = $ extraFieldValue ->get_values_by_handler_and_field_variable (
438+ $ certificateId ,
439+ 'downloaded_at '
440+ );
441+ if (empty ($ value )) {
442+ $ params = [
443+ 'item_id ' => $ this ->certificate_data ['id ' ],
444+ 'extra_downloaded_at ' => api_get_utc_datetime (),
445+ ];
446+ $ extraFieldValue ->saveFieldValues ($ params );
447+ }
448+ }
449+
430450 echo $ certificateContent ;
431451 exit ;
432452 }
0 commit comments