Prechádzať zdrojové kódy

generate custom certificate delete and create new one BT#14042

jmontoyaa 7 rokov pred
rodič
commit
8e89d542a8

+ 7 - 7
main/inc/lib/certificate.lib.php

@@ -210,12 +210,13 @@ class Certificate extends Model
         }
 
         $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false;
-
+        $categoryId = 0;
         if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
-            $my_category = Category::load($this->certificate_data['cat_id']);
+            $categoryId = $this->certificate_data['cat_id'];
+            $my_category = Category::load($categoryId);
         }
 
-        if (isset($my_category[0]) &&
+        if (isset($my_category[0]) && !empty($categoryId) &&
             $my_category[0]->is_certificate_available($this->user_id)
         ) {
             $courseInfo = api_get_course_info($my_category[0]->get_course_code());
@@ -332,7 +333,7 @@ class Certificate extends Model
             $my_new_content_html = str_replace(
                 '((certificate_barcode))',
                 Display::img(
-                    +$this->certification_web_user_path.$file_info['filename'].'_qr.png',
+                    $this->certification_web_user_path.$file_info['filename'].'_qr.png',
                     'QR'
                 ),
                 $content
@@ -457,9 +458,9 @@ class Certificate extends Model
         $user_id,
         $path_certificate
     ) {
-        $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
-        $now = api_get_utc_datetime();
         if (!UserManager::is_user_certified($cat_id, $user_id)) {
+            $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
+            $now = api_get_utc_datetime();
             $sql = 'UPDATE '.$table.' SET 
                         path_certificate="'.Database::escape_string($path_certificate).'",
                         created_at = "'.$now.'"
@@ -656,7 +657,6 @@ class Certificate extends Model
             0,
             $this->user_id
         );
-
         if (empty($myCertificate)) {
             GradebookUtils::registerUserInfoAboutCertificate(
                 0,

+ 10 - 1
main/mySpace/myStudents.php

@@ -221,7 +221,16 @@ switch ($action) {
         }
         break;
     case 'generate_certificate':
-        // ofaj
+        // Delete old certificate
+        $myCertificate = GradebookUtils::get_certificate_by_user_id(
+            0,
+            $student_id
+        );
+        if ($myCertificate) {
+            $certificate = new Certificate($myCertificate['id'], $student_id);
+            $certificate->delete(true);
+        }
+        // Create new one
         $certificate = new Certificate(0, $student_id);
         $certificate->generatePdfFromCustomCertificate();
         exit;