Skip to content

Commit

Permalink
Codestyle: Adjust to new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Apr 23, 2024
1 parent 55474e6 commit fc45e23
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 50 deletions.
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 fc45e23

Please sign in to comment.