Gradebook: Change endroid/qr-code to 2.5.*, Version php >= 5.6 - ref.

#3061
pull/3434/head
carlos alvarado 5 years ago
parent 98deaccf95
commit c709cb91ba
  1. 2
      composer.json
  2. 49
      main/inc/lib/certificate.lib.php

@ -118,7 +118,7 @@
"zendframework/zend-http": "~2.6|^3.0",
"zendframework/zend-soap": "~2.6|^3.0",
"angelfqc/vimeo-api": "2.0.6",
"endroid/qr-code": "3.0.0"
"endroid/qr-code": "2.5.*"
},
"require-dev": {
"behat/behat": "3.5.0",

@ -1,9 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Response\QrCodeResponse;
/**
* Certificate Class
* Generate certificates based in the gradebook tool.
@ -513,45 +511,20 @@ class Certificate extends Model
*/
public function generateQRImage($text, $path)
{
// Make sure HTML certificate is generated
if (!empty($text) && !empty($path)) {
//L low, M - Medium, L large error correction
// return PHPQRCode\QRcode::png($text, $path, 'M', 2, 2);;
return $this->makeQrBasedOnEndroid($text,$path);
}
return false;
}
/**
* Generates a QR code for the certificate. The QR code embeds the text given.
*
* @param string $text Text to be added in the QR code
* @param string $path file path of the image
*
* @return bool
*/
// this name will be change
public function makeQrBasedOnEndroid($text, $path)
{
$qrCode = new QrCode($text);
$qrCode->setSize(145);
$qrCode->setMargin(10);
$qrCode->setWriterByName('png');
//$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setValidateResult(false);
// To prevent this error:
//Fatal error: Uncaught TypeError: Return value of Endroid\QrCode\Writer\AbstractWriter::writeFile() must be of the type string, none returned in C:\Work\chamilo\vendor\endroid\qr-code\src\Writer\AbstractWriter.php on line 27
try {
$qrCode = new QrCode($text);
//$qrCode->setEncoding('UTF-8');
$qrCode->setSize(106);
$qrCode->setMargin(4);
$qrCode->setWriterByName('png');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setValidateResult(false);
$qrCode->writeFile($path);
} catch (Error $e) {
return true;
}
return true;
return false;
}
/**

Loading…
Cancel
Save