From 76a6b96ccd057eb97f368535e40df7c23e14bc04 Mon Sep 17 00:00:00 2001 From: Nosolored Date: Tue, 22 May 2018 10:55:09 +0200 Subject: [PATCH] Applied fixes from FlintCI and Codacy --- main/gradebook/lib/fe/displaygradebook.php | 2 +- .../resources/css/certificate.css | 6 +- .../resources/js/certificate.js | 4 +- .../src/CustomCertificatePlugin.php | 6 +- plugin/customcertificate/src/index.php | 12 +- .../src/print_certificate.php | 144 ++++++++---------- 6 files changed, 82 insertions(+), 92 deletions(-) diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index 9f28bb6daf..1b5399a1aa 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -475,7 +475,7 @@ class DisplayGradebook $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).''; } - + if (empty($categories)) { $actionsRight .= ''. Display::return_icon('percentage.png', get_lang('EditAllWeights'), '', ICON_SIZE_MEDIUM).''; diff --git a/plugin/customcertificate/resources/css/certificate.css b/plugin/customcertificate/resources/css/certificate.css index cfeebe27dc..7e8a0f3103 100644 --- a/plugin/customcertificate/resources/css/certificate.css +++ b/plugin/customcertificate/resources/css/certificate.css @@ -1,7 +1,7 @@ body {background-repeat:no-repeat; margin:0; padding: 0;} td { font-family:arial, sans-serif; font-size:18px; } -.logo { height: 150px; vertical-align: middle; } -.content-table { height: 480px; padding: 10px 25px; vertical-align:middle;} +.logo {height: 150px; vertical-align: middle; } +.content-table {height: 480px; vertical-align:middle;} .content-student { text-align:center;} .course { padding-top: 10px; text-align:center; vertical-align: middle;} .modality { text-align:center; } @@ -13,5 +13,5 @@ td { font-family:arial, sans-serif; font-size:18px; } .caraA {box-decoration-break: slice; page: caraA} @page caraB { background:#FFFFFF; } .caraB {box-decoration-break: slice; page: caraB} -.contents-learnpath td {background: #FFFFFF; font-size: 12px; height: 160mm; padding: 10px; vertical-align: top;} +.contents-learnpath td {background: #FFFFFF; font-size: 12px; height: 160mm; vertical-align: top;} ol {margin: 0; padding:0;} diff --git a/plugin/customcertificate/resources/js/certificate.js b/plugin/customcertificate/resources/js/certificate.js index f2a422f129..0721fade19 100644 --- a/plugin/customcertificate/resources/js/certificate.js +++ b/plugin/customcertificate/resources/js/certificate.js @@ -27,7 +27,7 @@ function typeDateExpedictionSwitchRadioButton(){ var inputType = document.getElementsByName("type_date_expediction"); var type; for (var i=0;i 'checkbox', ], ]; - + protected function __construct() { parent::__construct( @@ -198,7 +198,7 @@ class CustomCertificatePlugin extends Plugin echo get_lang('MessageUpdate'); } } - + /** * Get certificate data. * @@ -233,7 +233,7 @@ class CustomCertificatePlugin extends Plugin ]; } } - + return []; } } diff --git a/plugin/customcertificate/src/index.php b/plugin/customcertificate/src/index.php index f65db161ed..f4815a9b33 100644 --- a/plugin/customcertificate/src/index.php +++ b/plugin/customcertificate/src/index.php @@ -1176,16 +1176,16 @@ function uploadImageCertificate( if (empty($certId)) { return false; } - + $delete = empty($file); - + if (empty($sourceFile)) { $sourceFile = $file; } $base = api_get_path(SYS_UPLOAD_PATH); $path = $base.'certificates/'.$certId.'/'; - + if ($default) { $path = $base.'certificates/default/'; } @@ -1194,17 +1194,17 @@ function uploadImageCertificate( if (!file_exists($path)) { mkdir($path, api_get_permissions_for_new_directories(), true); } - + // Exit if only deletion has been requested. Return an empty picture name. if ($delete) { return ''; } - + $allowedTypes = api_get_supported_image_extensions(); $file = str_replace('\\', '/', $file); $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file; $extension = strtolower(substr(strrchr($filename, '.'), 1)); - + if (!in_array($extension, $allowedTypes)) { return false; } diff --git a/plugin/customcertificate/src/print_certificate.php b/plugin/customcertificate/src/print_certificate.php index 47dc51ee33..8db8f9e40c 100644 --- a/plugin/customcertificate/src/print_certificate.php +++ b/plugin/customcertificate/src/print_certificate.php @@ -6,7 +6,7 @@ use Chamilo\CourseBundle\Entity\CLpCategory; if (intval($_GET['default']) == 1) { $cidReset = true; } - + $course_plugin = 'customcertificate'; require_once __DIR__.'/../config.php'; @@ -105,14 +105,14 @@ if (empty($infoCertificate)) { $workSpace = intval(297 - $infoCertificate['margin_left'] - $infoCertificate['margin_right']); $widthCell = intval($workSpace / 6); $htmlText = ''; -$htmlText .= ''; -$htmlText .= ''; +$htmlText .= ' + '; +$htmlText .= ' + '; $htmlText .= ''; foreach ($userList as $userInfo) { $studentId = $userInfo['user_id']; @@ -121,48 +121,47 @@ foreach ($userList as $userInfo) { $htmlText .= '
'; } else { $urlBackground = $path.$infoCertificate['background']; - $htmlText .= '
'; + $htmlText .= ' +
'; } if (!empty($infoCertificate['logo_left'])) { - $logoLeft = ''; + $logoLeft = ' + '; } else { $logoLeft = ''; } if (!empty($infoCertificate['logo_center'])) { - $logoCenter = ''; + $logoCenter = ' + '; } else { $logoCenter = ''; } if (!empty($infoCertificate['logo_right'])) { - $logoRight = ''; + $logoRight = ' + '; } else { $logoRight = ''; } $htmlText .= ''; + width="'.$workSpace.'mm" + style=" + margin-left:'.$infoCertificate['margin_left'].'mm; + margin-right:'.$infoCertificate['margin_right'].'mm; + " + border="0">'; $htmlText .= ''; $htmlText .= ''; $htmlText .= ''; @@ -268,57 +267,52 @@ foreach ($userList as $userInfo) { $htmlText .= ''; $htmlText .= ''; - $htmlText .= ' - - - '; $htmlText .= ''; $htmlText .= ''; - $htmlText .= ' - - - - '; $htmlText .= ''; $htmlText .= '
- '.((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : ''). + $htmlText .= ''. + ((!empty($infoCertificate['signature_text1'])) ? $infoCertificate['signature_text1'] : ''). ' - '.((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : ''). + '. + ((!empty($infoCertificate['signature_text2'])) ? $infoCertificate['signature_text2'] : ''). ' - '.((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : ''). + '. + ((!empty($infoCertificate['signature_text3'])) ? $infoCertificate['signature_text3'] : ''). ' - '.((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : ''). + '. + ((!empty($infoCertificate['signature_text4'])) ? $infoCertificate['signature_text4'] : ''). ' '.((!empty($infoCertificate['seal'])) ? $plugin->get_lang('Seal') : ''). '
- '.((!empty($infoCertificate['signature1'])) - ? '' - : ''). + $htmlText .= ''. + ((!empty($infoCertificate['signature1'])) + ? '' + : ''). ' - '.((!empty($infoCertificate['signature2'])) - ? '' - : ''). + '. + ((!empty($infoCertificate['signature2'])) + ? '' + : ''). ' - '.((!empty($infoCertificate['signature3'])) - ? '' - : ''). + '. + ((!empty($infoCertificate['signature3'])) + ? '' + : ''). ' - '.((!empty($infoCertificate['signature4'])) - ? '' - : ''). + '. + ((!empty($infoCertificate['signature4'])) + ? '' + : ''). ' - '.((!empty($infoCertificate['seal'])) - ? '' - : ''). + '. + ((!empty($infoCertificate['seal'])) + ? '' + : ''). '
'; @@ -329,12 +323,10 @@ foreach ($userList as $userInfo) { if ($infoCertificate['contents_type'] == 0) { $contentsDescription = CourseDescription::get_data_by_description_type(3, $courseId, 0); - $domd = new DOMDocument(); libxml_use_internal_errors(true); $domd->loadHTML($contentsDescription['description_content']); libxml_use_internal_errors(false); - $domx = new DOMXPath($domd); $items = $domx->query("//li[@style]"); foreach ($items as $item) { @@ -347,7 +339,6 @@ foreach ($userList as $userInfo) { } $output = $domd->saveHTML(); - $htmlText .= getIndexFiltered($output); } @@ -358,9 +349,8 @@ foreach ($userList as $userInfo) { $categoryTest->setId(0); $categoryTest->setName($plugin->get_lang('WithOutCategory')); $categoryTest->setPosition(0); - $categories = [ - $categoryTest - ]; + $categories = [$categoryTest]; + if (!empty($categoriesTempList)) { $categories = array_merge($categories, $categoriesTempList); }