WIP: Gradebook: certificate qr code, change aferrandini/phpqrcode to

endroid/qr-code into composer.json - ref. #3061
pull/3434/head
carlos alvarado 5 years ago
parent 4bd6911c88
commit 98deaccf95
  1. 4
      composer.json
  2. 39
      main/inc/lib/certificate.lib.php

@ -33,7 +33,6 @@
] ]
}, },
"require": { "require": {
"aferrandini/phpqrcode": "1.0.1",
"apereo/phpcas": "^1.3", "apereo/phpcas": "^1.3",
"brumann/polyfill-unserialize": "^1.0", "brumann/polyfill-unserialize": "^1.0",
"chamilo/chash": "0.1.1", "chamilo/chash": "0.1.1",
@ -118,7 +117,8 @@
"zendframework/zend-feed": "~2.6|^3.0", "zendframework/zend-feed": "~2.6|^3.0",
"zendframework/zend-http": "~2.6|^3.0", "zendframework/zend-http": "~2.6|^3.0",
"zendframework/zend-soap": "~2.6|^3.0", "zendframework/zend-soap": "~2.6|^3.0",
"angelfqc/vimeo-api": "2.0.6" "angelfqc/vimeo-api": "2.0.6",
"endroid/qr-code": "3.0.0"
}, },
"require-dev": { "require-dev": {
"behat/behat": "3.5.0", "behat/behat": "3.5.0",

@ -1,6 +1,9 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* 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 * Certificate Class
* Generate certificates based in the gradebook tool. * Generate certificates based in the gradebook tool.
@ -513,11 +516,43 @@ class Certificate extends Model
// Make sure HTML certificate is generated // Make sure HTML certificate is generated
if (!empty($text) && !empty($path)) { if (!empty($text) && !empty($path)) {
//L low, M - Medium, L large error correction //L low, M - Medium, L large error correction
return PHPQRCode\QRcode::png($text, $path, 'M', 2, 2); // return PHPQRCode\QRcode::png($text, $path, 'M', 2, 2);;
return $this->makeQrBasedOnEndroid($text,$path);
} }
return false; 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->writeFile($path);
} catch (Error $e) {
}
return true;
}
/** /**
* Transforms certificate tags into text values. This function is very static * Transforms certificate tags into text values. This function is very static

Loading…
Cancel
Save