Selaa lähdekoodia

Merge pull request #2573 from nosolored/1.11.x_customcertificate

Add config option to hide contents in custom certificate plugin
Yannick Warnier 6 vuotta sitten
vanhempi
commit
122ab7db3d

+ 1 - 0
plugin/customcertificate/lang/english.php

@@ -22,6 +22,7 @@ $strings['ContentsToShow'] = "Contents to show";
 $strings['ContentsCourseDescription'] = 'Use section "Course description"> "Contents"';
 $strings['ContentsIndexLearnpath'] = "Use learnpath index";
 $strings['ContentsCustom'] = "Use custom content";
+$strings['ContentsHide'] = "No show contents";
 $strings['Dates'] = "Dates";
 $strings['CourseDeliveryDates'] = "Course delivery dates";
 $strings['Custom'] = "Custom";

+ 1 - 0
plugin/customcertificate/lang/spanish.php

@@ -22,6 +22,7 @@ $strings['ContentsToShow'] = "Contenidos a mostrar";
 $strings['ContentsCourseDescription'] = 'Usar apartado "Descripcion del curso" > "Contenidos"';
 $strings['ContentsIndexLearnpath'] = "Usar indice de lecciones";
 $strings['ContentsCustom'] = "Usar contenido personalizado";
+$strings['ContentsHide'] = "No mostrar contenidos";
 $strings['Dates'] = "Fechas";
 $strings['CourseDeliveryDates'] = "Fechas de impartición del curso";
 $strings['Custom'] = "Personalizado";

+ 13 - 3
plugin/customcertificate/src/index.php

@@ -321,6 +321,16 @@ $element = &$form->createElement(
 );
 $group[] = $element;
 
+$element = &$form->createElement(
+    'radio',
+    'contents_type',
+    '',
+    get_lang('ContentsHide'),
+    3,
+    ['id' => 'contents_type_3', 'onclick' => 'javascript: contentsTypeSwitchRadioButton();']
+);
+$group[] = $element;
+
 $element = &$form->createElement(
     'radio',
     'contents_type',
@@ -373,7 +383,7 @@ $option1 = &$form->createElement(
     '',
     get_lang('UseDateSessionAccess'),
     0,
-    ['id' => 'contents_type_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();']
+    ['id' => 'date_change_0', 'onclick' => 'javascript: dateCertificateSwitchRadioButton0();']
 );
 $group[] = $option1;
 
@@ -383,7 +393,7 @@ $option2 = &$form->createElement(
     '',
     get_lang('None'),
     2,
-    ['id' => 'contents_type_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();']
+    ['id' => 'date_change_2', 'onclick' => 'javascript: dateCertificateSwitchRadioButton2();']
 );
 $group[] = $option2;
 
@@ -393,7 +403,7 @@ $option3 = &$form->createElement(
     '',
     get_lang('Custom'),
     1,
-    ['id' => 'contents_type_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();']
+    ['id' => 'date_change_1', 'onclick' => 'javascript: dateCertificateSwitchRadioButton1();']
 );
 $group[] = $option3;
 

+ 103 - 101
plugin/customcertificate/src/print_certificate.php

@@ -320,134 +320,136 @@ foreach ($userList as $userInfo) {
     $htmlText .= '</div>';
 
     // Rear certificate
-    $htmlText .= '<div class="caraB" style="page-break-before:always; margin:0px; padding:0px;">';
-    if ($infoCertificate['contents_type'] == 0) {
-        $courseDescription = new CourseDescription();
-        $contentDescription = $courseDescription->get_data_by_description_type(3, $courseId, 0);
-        $domd = new DOMDocument();
-        libxml_use_internal_errors(true);
-        if (isset($contentDescription['description_content'])) {
-            $domd->loadHTML($contentDescription['description_content']);
-        }
-        libxml_use_internal_errors(false);
-        $domx = new DOMXPath($domd);
-        $items = $domx->query("//li[@style]");
-        foreach ($items as $item) {
-            $item->removeAttribute("style");
-        }
-
-        $items = $domx->query("//span[@style]");
-        foreach ($items as $item) {
-            $item->removeAttribute("style");
-        }
-
-        $output = $domd->saveHTML();
-        $htmlText .= getIndexFiltered($output);
-    }
-
-    if ($infoCertificate['contents_type'] == 1) {
-        $items = [];
-        $categoriesTempList = learnpath::getCategories($courseId);
-        $categoryTest = new CLpCategory();
-        $categoryTest->setId(0);
-        $categoryTest->setName($plugin->get_lang('WithOutCategory'));
-        $categoryTest->setPosition(0);
-        $categories = [$categoryTest];
-
-        if (!empty($categoriesTempList)) {
-            $categories = array_merge($categories, $categoriesTempList);
-        }
-
-        foreach ($categories as $item) {
-            $categoryId = $item->getId();
-
-            if (!learnpath::categoryIsVisibleForStudent($item, api_get_user_entity($studentId))) {
-                continue;
+    if ($infoCertificate['contents_type'] != 3) {
+        $htmlText .= '<div class="caraB" style="page-break-before:always; margin:0px; padding:0px;">';
+        if ($infoCertificate['contents_type'] == 0) {
+            $courseDescription = new CourseDescription();
+            $contentDescription = $courseDescription->get_data_by_description_type(3, $courseId, 0);
+            $domd = new DOMDocument();
+            libxml_use_internal_errors(true);
+            if (isset($contentDescription['description_content'])) {
+                $domd->loadHTML($contentDescription['description_content']);
             }
-
-            $sql = "SELECT 1
-                    FROM $tblProperty
-                    WHERE tool = 'learnpath_category'
-                    AND ref = $categoryId
-                    AND visibility = 0
-                    AND (session_id = $sessionId OR session_id IS NULL)";
-            $res = Database::query($sql);
-            if (Database::num_rows($res) > 0) {
-                continue;
+            libxml_use_internal_errors(false);
+            $domx = new DOMXPath($domd);
+            $items = $domx->query("//li[@style]");
+            foreach ($items as $item) {
+                $item->removeAttribute("style");
             }
 
-            $list = new LearnpathList(
-                $studentId,
-                $courseCode,
-                $sessionId,
-                null,
-                false,
-                $categoryId
-            );
+            $items = $domx->query("//span[@style]");
+            foreach ($items as $item) {
+                $item->removeAttribute("style");
+            }
 
-            $flat_list = $list->get_flat_list();
+            $output = $domd->saveHTML();
+            $htmlText .= getIndexFiltered($output);
+        }
 
-            if (empty($flat_list)) {
-                continue;
+        if ($infoCertificate['contents_type'] == 1) {
+            $items = [];
+            $categoriesTempList = learnpath::getCategories($courseId);
+            $categoryTest = new CLpCategory();
+            $categoryTest->setId(0);
+            $categoryTest->setName($plugin->get_lang('WithOutCategory'));
+            $categoryTest->setPosition(0);
+            $categories = [$categoryTest];
+
+            if (!empty($categoriesTempList)) {
+                $categories = array_merge($categories, $categoriesTempList);
             }
 
-            if (count($categories) > 1 && count($flat_list) > 0) {
-                if ($item->getName() != $plugin->get_lang('WithOutCategory')) {
-                    $items[] = '<h4 style="margin:0">'.$item->getName().'</h4>';
+            foreach ($categories as $item) {
+                $categoryId = $item->getId();
+
+                if (!learnpath::categoryIsVisibleForStudent($item, api_get_user_entity($studentId))) {
+                    continue;
                 }
-            }
 
-            foreach ($flat_list as $learnpath) {
-                $lpId = $learnpath['lp_old_id'];
                 $sql = "SELECT 1
                         FROM $tblProperty
-                        WHERE tool = 'learnpath'
-                        AND ref = $lpId AND visibility = 0
+                        WHERE tool = 'learnpath_category'
+                        AND ref = $categoryId
+                        AND visibility = 0
                         AND (session_id = $sessionId OR session_id IS NULL)";
                 $res = Database::query($sql);
                 if (Database::num_rows($res) > 0) {
                     continue;
                 }
-                $lpName = $learnpath['lp_name'];
-                $items[] = $lpName.'<br>';
+
+                $list = new LearnpathList(
+                    $studentId,
+                    $courseCode,
+                    $sessionId,
+                    null,
+                    false,
+                    $categoryId
+                );
+
+                $flat_list = $list->get_flat_list();
+
+                if (empty($flat_list)) {
+                    continue;
+                }
+
+                if (count($categories) > 1 && count($flat_list) > 0) {
+                    if ($item->getName() != $plugin->get_lang('WithOutCategory')) {
+                        $items[] = '<h4 style="margin:0">'.$item->getName().'</h4>';
+                    }
+                }
+
+                foreach ($flat_list as $learnpath) {
+                    $lpId = $learnpath['lp_old_id'];
+                    $sql = "SELECT 1
+                            FROM $tblProperty
+                            WHERE tool = 'learnpath'
+                            AND ref = $lpId AND visibility = 0
+                            AND (session_id = $sessionId OR session_id IS NULL)";
+                    $res = Database::query($sql);
+                    if (Database::num_rows($res) > 0) {
+                        continue;
+                    }
+                    $lpName = $learnpath['lp_name'];
+                    $items[] = $lpName.'<br>';
+                }
+                $items[] = '<br>';
             }
-            $items[] = '<br>';
+
+            if (count($items) > 0) {
+                $htmlText .= '<table width="100%" class="contents-learnpath">';
+                $htmlText .= '<tr>';
+                $htmlText .= '<td>';
+                $i = 0;
+                foreach ($items as $value) {
+                    if ($i == 50) {
+                        $htmlText .= '</td><td>';
+                    }
+                    $htmlText .= $value;
+                    $i++;
+                }
+                $htmlText .= '</td>';
+                $htmlText .= '</tr>';
+                $htmlText .= '</table>';
+            }
+            $htmlText .= '</td></table>';
         }
 
-        if (count($items) > 0) {
+        if ($infoCertificate['contents_type'] == 2) {
             $htmlText .= '<table width="100%" class="contents-learnpath">';
             $htmlText .= '<tr>';
             $htmlText .= '<td>';
-            $i = 0;
-            foreach ($items as $value) {
-                if ($i == 50) {
-                    $htmlText .= '</td><td>';
-                }
-                $htmlText .= $value;
-                $i++;
-            }
+            $myContentHtml = strip_tags(
+                $infoCertificate['contents'],
+                '<p><b><strong><table><tr><td><th><span><i><li><ol><ul>'.
+                '<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
+            );
+            $htmlText .= $myContentHtml;
             $htmlText .= '</td>';
             $htmlText .= '</tr>';
             $htmlText .= '</table>';
         }
-        $htmlText .= '</td></table>';
-    }
-
-    if ($infoCertificate['contents_type'] == 2) {
-        $htmlText .= '<table width="100%" class="contents-learnpath">';
-        $htmlText .= '<tr>';
-        $htmlText .= '<td>';
-        $myContentHtml = strip_tags(
-            $infoCertificate['contents'],
-            '<p><b><strong><table><tr><td><th><span><i><li><ol><ul>'.
-            '<dd><dt><dl><br><hr><img><a><div><h1><h2><h3><h4><h5><h6>'
-        );
-        $htmlText .= $myContentHtml;
-        $htmlText .= '</td>';
-        $htmlText .= '</tr>';
-        $htmlText .= '</table>';
+        $htmlText .= '</div>';
     }
-    $htmlText .= '</div>';
 }
 $htmlText .= '</body></html>';