@@ -73,9 +73,8 @@ public function __construct($certificate_id = 0, $userId = 0)
73
73
}
74
74
}
75
75
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 ) &&
79
78
!empty ($ this ->certification_user_path ) &&
80
79
isset ($ this ->certificate_data ['path_certificate ' ])
81
80
) {
@@ -92,7 +91,7 @@ public function check_certificate_path()
92
91
{
93
92
$ this ->certification_user_path = null ;
94
93
95
- //Setting certification path
94
+ // Setting certification path
96
95
$ path_info = UserManager::getUserPathById ($ this ->user_id , 'system ' );
97
96
$ web_path_info = UserManager::getUserPathById ($ this ->user_id , 'web ' );
98
97
@@ -212,7 +211,10 @@ public function generate($params = array())
212
211
213
212
$ my_new_content_html = str_replace (
214
213
'((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
+ ),
216
218
$ new_content_html ['content ' ]
217
219
);
218
220
@@ -262,10 +264,10 @@ public function update_user_info_about_certificate(
262
264
$ user_id ,
263
265
$ path_certificate
264
266
) {
265
- $ table_certificate = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CERTIFICATE );
267
+ $ table = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CERTIFICATE );
266
268
$ now = api_get_utc_datetime ();
267
269
if (!UserManager::is_user_certified ($ cat_id , $ user_id )) {
268
- $ sql = 'UPDATE ' .$ table_certificate .' SET
270
+ $ sql = 'UPDATE ' .$ table .' SET
269
271
path_certificate=" ' .Database::escape_string ($ path_certificate ).'",
270
272
created_at = " ' .$ now .'"
271
273
WHERE cat_id=" ' .intval ($ cat_id ).'" AND user_id=" ' .intval ($ user_id ).'" ' ;
@@ -295,9 +297,10 @@ public function html_file_is_generated()
295
297
296
298
/**
297
299
* 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
+ **/
301
304
public function generate_qr ($ text , $ path )
302
305
{
303
306
//Make sure HTML certificate is generated
@@ -427,6 +430,23 @@ public function show()
427
430
$ user_certificate = $ this ->certification_user_path .basename ($ this ->certificate_data ['path_certificate ' ]);
428
431
if (file_exists ($ user_certificate )) {
429
432
$ 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
+
430
450
echo $ certificateContent ;
431
451
exit ;
432
452
}
0 commit comments