Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"moodle-plugin-ci": "4.5.9",
"main-moodle": "MOODLE_500_STABLE",
"main-php": "8.4",
"main-db": "pgsql",
"moodle-testmatrix": {
"MOODLE_500_STABLE": {
"php": ["8.2", "8.3", "8.4"],
"db": ["pgsql", "mariadb", "mysqli"]
}
}
}
4 changes: 2 additions & 2 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function display_image($courseid, $instanceid) {
'courseid' => $courseid,
'download' => false,
'format' => 1,
'size' => 150,
'size' => 300,
'instance' => $instanceid]);

return \html_writer::img(
Expand All @@ -66,7 +66,7 @@ public function display_download_section($courseid, $instanceid) {
'instance' => $instanceid]);
$mform = new \block_qrcode\block_qrcode_form(
$download,
['format' => 1, 'size' => 150],
['format' => 1, 'size' => 300],
'post',
'',
['data-double-submit-protection' => 'off']
Expand Down
21 changes: 8 additions & 13 deletions classes/output_image.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
namespace block_qrcode;

use core\url;

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\Encoding\Encoding;
Expand Down Expand Up @@ -172,15 +171,11 @@ public function create_image() {
}

// Creates the QR code.
$qrcode = new QrCode($this->course_link_url()->out(false));
$qrcode->setSize($this->size);

// Set advanced options.
$qrcode->setMargin(10);
$qrcode->setEncoding(new Encoding('UTF-8'));
$qrcode->setErrorCorrectionLevel(new ErrorCorrectionLevel\ErrorCorrectionLevelHigh());
$qrcode->setForegroundColor(new Color(0, 0, 0));
$qrcode->setBackgroundColor(new Color(255, 255, 255));
$qrcode = new QrCode(
data: $this->course_link_url()->out(false),
size: $this->size,
errorCorrectionLevel: ErrorCorrectionLevel::High,
);

// Png format.
$logo = null;
Expand All @@ -194,7 +189,7 @@ public function create_image() {
}
$logo = new Logo(
$logopath,
intval($this->size * 0.4),
intval($this->size * 0.25),
null,
false
);
Expand All @@ -206,8 +201,8 @@ public function create_image() {
: $CFG->dirroot . '/blocks/qrcode/pix/moodlelogo.svg';
$logo = new Logo(
$logopath,
intval($this->size * 0.4),
intval($this->size * 0.4 / $this->get_logo_aspect_ratio($logopath)),
intval($this->size * 0.25),
intval($this->size * 0.25 / $this->get_logo_aspect_ratio($logopath)),
false
);
}
Expand Down
2 changes: 1 addition & 1 deletion download.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$download = required_param('download', PARAM_BOOL);
$format = required_param('format', PARAM_TEXT);
$instanceid = required_param('instance', PARAM_INT);
$size = optional_param('size', 150, PARAM_INT);
$size = optional_param('size', 300, PARAM_INT);

if ($download) {
require_capability('block/qrcode:download', context_course::instance($courseid));
Expand Down
7 changes: 3 additions & 4 deletions tests/behat/download_qrcode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ Feature: Download QR code as .png file
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | Crs1 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "QR code" block
And I log out
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| qrcode | Course | Crs1 | course-view-* | site-post |

@javascript
Scenario: Teacher sees the QR code and clicks on the Download button
Expand Down
7 changes: 3 additions & 4 deletions tests/behat/show_qrcode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ Feature: Display the QR code block
| user | course | role |
| teacher1 | Crs1 | editingteacher |
| student1 | Crs1 | student |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "QR code" block
And I log out
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| qrcode | Course | Crs1 | course-view-* | site-post |

@javascript
Scenario: Only enrolled students are able to see the QR code and they don't see the download button
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"endroid/qr-code": "4.6.1"
"endroid/qr-code": "^6.0.0"
}
}
64 changes: 32 additions & 32 deletions thirdparty/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions thirdparty/vendor/bacon/bacon-qr-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ BaconQrCode comes with multiple back ends for rendering images. Currently includ
- `ImagickImageBackEnd`: renders raster images using the Imagick library
- `SvgImageBackEnd`: renders SVG files using XMLWriter
- `EpsImageBackEnd`: renders EPS files

### GDLib Renderer
GD library has so many limitations, that GD support is not added as backend, but as separated renderer.
Use `GDLibRenderer` instead of `ImageRenderer`. These are the limitations:

- Does not support gradient.
- Does not support any curves, so you QR code is always squared.

Example usage:

```php
use BaconQrCode\Renderer\GDLibRenderer;
use BaconQrCode\Writer;

$renderer = new GDLibRenderer(400);
$writer = new Writer($renderer);
$writer->writeFile('Hello World!', 'qrcode.png');
```
20 changes: 13 additions & 7 deletions thirdparty/vendor/bacon/bacon-qr-code/composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "bacon/bacon-qr-code",
"description": "BaconQrCode is a QR code generator for PHP.",
"license" : "BSD-2-Clause",
"license": "BSD-2-Clause",
"homepage": "https://github.com/Bacon/BaconQrCode",
"require": {
"php": "^7.1 || ^8.0",
"php": "^8.1",
"ext-iconv": "*",
"dasprid/enum": "^1.0.3"
},
Expand All @@ -24,15 +24,21 @@
"BaconQrCode\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"BaconQrCodeTest\\": "test/"
}
},
"require-dev": {
"phpunit/phpunit": "^7 | ^8 | ^9",
"spatie/phpunit-snapshot-assertions": "^4.2.9",
"squizlabs/php_codesniffer": "^3.4",
"phly/keep-a-changelog": "^2.1"
"phpunit/phpunit": "^10.5.11 || 11.0.4",
"spatie/phpunit-snapshot-assertions": "^5.1.5",
"squizlabs/php_codesniffer": "^3.9",
"phly/keep-a-changelog": "^2.12"
},
"config": {
"allow-plugins": {
"ocramius/package-versions": true
"ocramius/package-versions": true,
"php-http/discovery": true
}
},
"archive": {
Expand Down
13 changes: 0 additions & 13 deletions thirdparty/vendor/bacon/bacon-qr-code/phpunit.xml.dist

This file was deleted.

16 changes: 4 additions & 12 deletions thirdparty/vendor/bacon/bacon-qr-code/src/Common/BitArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ final class BitArray
*
* @var SplFixedArray<int>
*/
private $bits;

/**
* Size of the bit array in bits.
*
* @var int
*/
private $size;
private SplFixedArray $bits;

/**
* Creates a new bit array with a given size.
*/
public function __construct(int $size = 0)
public function __construct(private int $size = 0)
{
$this->size = $size;
$this->bits = SplFixedArray::fromArray(array_fill(0, ($this->size + 31) >> 3, 0));
}

Expand Down Expand Up @@ -107,7 +99,7 @@ public function getNextSet(int $from) : int
}

$result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits);
return $result > $this->size ? $this->size : $result;
return min($result, $this->size);
}

/**
Expand All @@ -133,7 +125,7 @@ public function getNextUnset(int $from) : int
}

$result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits);
return $result > $this->size ? $this->size : $result;
return min($result, $this->size);
}

/**
Expand Down
Loading