Skip to content

Commit

Permalink
Merge pull request #40 from learnweb/update/m404
Browse files Browse the repository at this point in the history
Update for Moodle 4.4
  • Loading branch information
NinaHerrmann authored Apr 29, 2024
2 parents c79c988 + 0c80af8 commit 1e39233
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 113 deletions.
86 changes: 23 additions & 63 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
strategy:
matrix:
php: ['8.2']
moodle-branch: ['MOODLE_403_STABLE']
moodle-branch: ['MOODLE_404_STABLE']
database: ['pgsql']

steps:
- name: Start PostgreSQL
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -36,29 +36,9 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand All @@ -75,10 +55,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
if: ${{ always() }}
run: moodle-plugin-ci phpmd
Expand Down Expand Up @@ -116,30 +92,20 @@ jobs:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
database: ['mariadb', 'pgsql']
exclude:
- php: '8.0'
moodle-branch: 'MOODLE_404_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

steps:
- name: Start MariaDB
Expand All @@ -151,7 +117,7 @@ jobs:
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -162,24 +128,6 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
Expand All @@ -201,4 +149,16 @@ jobs:

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
run: moodle-plugin-ci behat --profile chrome --auto-rerun 0

# This step allows to upload Behat faildump (screenshots) as workflow artifact,
# so it can be downloaded and inspected. You don't need this step if you
# are not running Behat test. Artifact will be retained for 7 days.
- name: Upload Behat Faildump
if: ${{ failure() && steps.behat.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: Behat Faildump (${{ join(matrix.*, ', ') }})
path: ${{ github.workspace }}/moodledata/behat_dump
retention-days: 7
if-no-files-found: ignore
4 changes: 2 additions & 2 deletions block_qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function get_content() {
$this->content->text .= $renderer->display_download_section($COURSE->id, $this->instance->id);
}

$this->page->requires->js_call_amd('block_qrcode/fullscreenqrcode', 'init', array($qrcode));
$this->page->requires->js_call_amd('block_qrcode/fullscreenqrcode', 'init', [$qrcode]);

return $this->content;
}
Expand All @@ -78,7 +78,7 @@ public function get_content() {
* @return array of applicable formats
*/
public function applicable_formats() {
return array('course-view' => true, 'mod' => false, 'my' => false);
return ['course-view' => true, 'mod' => false, 'my' => false];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions classes/block_qrcode_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public function definition() {
'select',
'format',
get_string('formats', 'block_qrcode'),
array(1 => 'svg', 2 => 'png'),
array('id' => 'slc_format'));
[1 => 'svg', 2 => 'png'],
['id' => 'slc_format']);
$selectf->setSelected($this->_customdata['format']);

// Select image size.
$selects = $mform->addElement(
'select',
'size',
get_string('sizes', 'block_qrcode'),
array(150 => '150px', 300 => '300px'),
array('id' => 'slc_size', 'disabled' => true));
[150 => '150px', 300 => '300px'],
['id' => 'slc_size', 'disabled' => true]);
$selects->setSelected($this->_customdata['size']);
$mform->disabledIf('size', 'format', 'eq', 1);

Expand Down
6 changes: 3 additions & 3 deletions classes/output_image.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct($format, $size, $courseid, $instanceid) {
$file = $CFG->localcachedir . '/block_qrcode/course-' .
(int)$courseid . '-' . $this->size; // Set file path.

$instance = $DB->get_record('block_instances', array('id' => $instanceid), '*', MUST_EXIST);
$instance = $DB->get_record('block_instances', ['id' => $instanceid], '*', MUST_EXIST);
$block = block_instance('qrcode', $instance);

if (is_null($block->config)) {
Expand Down Expand Up @@ -290,7 +290,7 @@ public function get_logo() {
'block_qrcode', 'customlogopng', 0, 'sortorder', false);

if ($this->format == 1) {
if (count($filessvg) == 1 AND get_config('block_qrcode', 'allow_customlogo') == 1) {
if (count($filessvg) == 1 && get_config('block_qrcode', 'allow_customlogo') == 1) {
$filesvg = reset($filessvg);
return $filesvg;
} else {
Expand All @@ -311,7 +311,7 @@ public function get_logo() {
}
}
} else {
if (count($filespng) == 1 AND get_config('block_qrcode', 'allow_customlogo') == 1) {
if (count($filespng) == 1 && get_config('block_qrcode', 'allow_customlogo') == 1) {
$filepng = reset($filespng);
return $filepng;
} else {
Expand Down
26 changes: 13 additions & 13 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
*/
defined('MOODLE_INTERNAL') || die();

$capabilities = array(
'block/qrcode:addinstance' => array(
$capabilities = [
'block/qrcode:addinstance' => [
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/site:manageblocks',
],

'block/qrcode:download' => array(
'block/qrcode:download' => [
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'archetypes' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
);
'manager' => CAP_ALLOW,
],
],
];
34 changes: 17 additions & 17 deletions lang/en/block_qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['allow_customlogo'] = 'Allow Customlogo';
$string['allow_customlogo_help'] = 'If the checkbox is checked, it allows teachers to upload a custom logo to be shown in the QR code';
$string['button'] = 'Download';
$string['cachedef_qrcodes'] = 'Cache for the QR codes';
$string['customfilepng'] = 'Custom File .png';
$string['customfilesvg'] = 'Custom File .svg';
$string['editblock'] = 'Edit QR code block';
$string['filename'] = 'course';
$string['formats'] = 'Format';
$string['img_tag_alt'] = 'QR code';
$string['instc_uselogo'] = 'Use logo';
$string['logofile_png'] = 'Choose .png logo';
$string['logofile_svg'] = 'Choose .svg logo';
$string['pluginname'] = 'QR code';
$string['privacy:metadata'] = 'The qrcode block only displays information about a course, but does not effect or store any personal data.';
$string['qrcode:addinstance'] = 'Add a new QR code block';
$string['qrcode:download'] = 'Show Download button';
$string['filename'] = 'course';
$string['cachedef_qrcodes'] = 'Cache for the QR codes';
$string['img_tag_alt'] = 'QR code';
$string['button'] = 'Download';
$string['formats'] = 'Format';
$string['sizes'] = 'Size';
$string['settings'] = 'QR code settings';
$string['sizes'] = 'Size';
$string['submit'] = 'Save changes';
$string['uploadpng'] = 'Upload Customlogo as .png also';
$string['use_logo'] = 'Use logo';
$string['use_logo_help'] = 'If the checkbox is checked, a logo is shown in the QR code. By default the moodle logo is shown but you can upload a custom logo.';
$string['logofile_png'] = 'Choose .png logo';
$string['logofile_svg'] = 'Choose .svg logo';
$string['submit'] = 'Save changes';
$string['editblock'] = 'Edit QR code block';
$string['usedefault'] = 'Use default settings';
$string['instc_uselogo'] = 'Use logo';
$string['privacy:metadata'] = 'The qrcode block only displays information about a course, but does not effect or store any personal data.';
$string['customfilesvg'] = 'Custom File .svg';
$string['customfilepng'] = 'Custom File .png';
$string['uploadpng'] = 'Upload Customlogo as .png also';
$string['allow_customlogo'] = 'Allow Customlogo';
$string['allow_customlogo_help'] = 'If the checkbox is checked, it allows teachers to upload a custom logo to be shown in the QR code';
12 changes: 6 additions & 6 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class block_qrcode_renderer extends plugin_renderer_base {
*/
public function display_image($courseid, $instanceid) {
$link = new moodle_url('/blocks/qrcode/download.php',
array('courseid' => $courseid,
['courseid' => $courseid,
'download' => false,
'format' => 1,
'size' => 150,
'instance' => $instanceid));
'instance' => $instanceid]);

return html_writer::img($link, get_string('img_tag_alt', 'block_qrcode'), array('id' => 'img_qrcode', 'width' => '90%'));
return html_writer::img($link, get_string('img_tag_alt', 'block_qrcode'), ['id' => 'img_qrcode', 'width' => '90%']);
}

/**
Expand All @@ -56,10 +56,10 @@ public function display_image($courseid, $instanceid) {
*/
public function display_download_section($courseid, $instanceid) {
$download = new moodle_url('/blocks/qrcode/download.php',
array('courseid' => $courseid,
['courseid' => $courseid,
'download' => true,
'instance' => $instanceid));
$mform = new block_qrcode\block_qrcode_form($download, array('format' => 1, 'size' => 150), 'post',
'instance' => $instanceid]);
$mform = new block_qrcode\block_qrcode_form($download, ['format' => 1, 'size' => 150], 'post',
'', ['data-double-submit-protection' => 'off']);
return $mform->render();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class block_qrcode_generator extends testing_block_generator {
*/
public function create_course() {
$generator = advanced_testcase::getDataGenerator();
$data = array();
$data = [];

// Create a course.
$course = $generator->create_course();
Expand Down
10 changes: 6 additions & 4 deletions tests/output_image_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @copyright 2017 T Gunkel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class output_image_test extends \advanced_testcase {
final class output_image_test extends \advanced_testcase {
/**
* course object
* @var object
Expand All @@ -48,7 +48,7 @@ class output_image_test extends \advanced_testcase {
*
* Create a course and a block instance.
*/
protected function setUp() : void {
protected function setUp(): void {
$generator = $this->getDataGenerator()->get_plugin_generator('block_qrcode');
$this->course = $generator->create_course()['course'];
$this->block = $generator->create_instance();
Expand All @@ -59,8 +59,9 @@ protected function setUp() : void {

/**
* Tests, if the image is created.
* @covers \block_qrcode\output_image
*/
public function test_create_image() {
public function test_create_image(): void {
global $CFG;

set_config('use_logo', 0, 'block_qrcode');
Expand All @@ -80,8 +81,9 @@ public function test_create_image() {
/**
* Tests, if the QR code is created with the moodle logo if no custom logo was uploaded
* when no logo is uploaded.
* @covers \block_qrcode\output_image
*/
public function test_no_logo() {
public function test_no_logo(): void {
global $CFG;

$this->assertEquals('', get_config('block_qrcode', 'logofile_svg'));
Expand Down

0 comments on commit 1e39233

Please sign in to comment.