Skip to content

Commit

Permalink
Fix code checker errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Jul 26, 2023
1 parent c01774b commit 2ef7243
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 151 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
matrix:
include:
- php: 8.0
moodle-branch: main
moodle-branch: master
database: pgsql
- php: 8.1
moodle-branch: main
moodle-branch: master
database: mariadb
- php: 8.1
moodle-branch: MOODLE_401_STABLE
Expand Down
2 changes: 1 addition & 1 deletion bouncetest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
$bounceprocessor->testrun();
}

echo $OUTPUT->footer();
echo $OUTPUT->footer();
6 changes: 3 additions & 3 deletions confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

if ($secret && $userid) {
if (!$user = get_complete_user_data('id', $userid)) {
print_error("Cannot find user!");
throw new \moodle_exception("Cannot find user!");
}
if ($user->confirmed) {
redirect(new moodle_url('/mod/newsletter/view.php', array('id' => $cm->id)),
Expand All @@ -70,9 +70,9 @@
$welcomemessage, 15);
// TODO: user/editadvanced.php?id=2.
} else {
print_error('The link you followed is invalid.');
throw new \moodle_exception('The link you followed is invalid.');
}
}
} else {
print_error('The link you followed is invalid.');
throw new \moodle_exception('The link you followed is invalid.');
}
2 changes: 1 addition & 1 deletion db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
'callback' => 'mod_newsletter_observer::user_deleted'),
array('eventname' => '\core\event\user_enrolment_deleted',
'callback' => 'mod_newsletter_observer::user_enrolment_deleted')
);
);
33 changes: 0 additions & 33 deletions db/uninstall.php

This file was deleted.

4 changes: 1 addition & 3 deletions guest_signup_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function definition() {
$mform->addElement('hidden', NEWSLETTER_PARAM_ACTION, $data[NEWSLETTER_PARAM_ACTION]);
$mform->setType(NEWSLETTER_PARAM_ACTION, PARAM_ALPHANUM);

// $mform->addElement('html', '<h3>' . get_string('guestsubscribe', 'mod_newsletter') . '</h3>');

$mform->addElement('text', 'firstname', get_string('firstname'), array('size' => '64'));
$mform->setType('firstname', PARAM_TEXT);
$mform->addRule('firstname', null, 'required', null, 'client');
Expand Down Expand Up @@ -88,7 +86,7 @@ public function validation($usernew, $files) {
$usernew = (object) $usernew;

$user = $DB->get_record('user', array('id' => $usernew->id));
if (!$user or $user->email !== $usernew->email) {
if (!$user || $user->email !== $usernew->email) {
if (!validate_email($usernew->email)) {
$err['email'] = get_string('invalidemail');
} else if ($DB->record_exists('user',
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$id = required_param('id', PARAM_INT);

if (!$course = $DB->get_record("course", array("id" => $id))) {
print_error('invalidcourseid');
throw new \moodle_exception('invalidcourseid');
}
require_login($course);

Expand Down
2 changes: 1 addition & 1 deletion lang/en/newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
You have requested to be subscribed to
\'{$a->newslettername}\' newsletter at \'{$a->sitename}\'
using this email address.
using this email address.
Please confirm your subscription by clicking on the following link:
Expand Down
38 changes: 19 additions & 19 deletions mod_form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
use mod_newsletter\userfilter;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -24,12 +23,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_newsletter\userfilter;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->libdir . '/formslib.php');


/**
* Module instance settings form
*/
Expand All @@ -40,19 +40,7 @@ class mod_newsletter_mod_form extends moodleform_mod {
*/
public function definition() {
global $CFG;

$mform = &$this->_form;
$data = &$this->_customdata;

$newsletter = $data['newsletter'];
$issue = $data['issue'];
$context = $data['context'];

$userfilter = $issue ? $issue->userfilter ?? null : null;
$newsletterid = $issue ? $issue->newsletterid : 0;

$mform = $this->_form;

$mform->addElement('header', 'general', get_string('general', 'form'));

$mform->addElement('text', 'name', get_string('newslettername', 'mod_newsletter'),
Expand Down Expand Up @@ -89,7 +77,7 @@ public function definition() {
$mform->addElement('header', 'header_profilefield',
get_string('header_profilefield', 'mod_newsletter'));
$mform->addElement('select', 'profilefield',
get_string('header_profilefield', 'mod_newsletter'), $this->cpf_list());
get_string('header_profilefield', 'mod_newsletter'), $this->cpf_list());
$mform->addHelpButton('profilefield', 'help_profilefield', 'mod_newsletter');

$this->standard_coursemodule_elements();
Expand All @@ -101,21 +89,25 @@ public function definition() {
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_newsletter',
NEWSLETTER_FILE_AREA_STYLESHEET, $newsletterid,
array('subdirs' => NEWSLETTER_FILE_OPTIONS_SUBDIRS, 'maxbytes' => 0,
'maxfiles' => -1));
'maxfiles' => -1));
$entry = new stdClass();
$entry->stylesheets = $draftitemid;

parent::set_data($entry);
}

public function cpf_list() {
/**
* Get custom profile fields as array.
* @return array
*/
public function cpf_list(): array {
global $DB;

$userprofilefieldsarray = [];
$customuserprofilefields = $DB->get_records('user_info_field', ['datatype' => 'checkbox'], '', 'id, name, shortname');

if (!empty($customuserprofilefields)) {

// Create an array of key => value pairs for the dropdown.
foreach ($customuserprofilefields as $cpf) {
$userprofilefieldsarray[$cpf->id] = $cpf->name;
Expand All @@ -128,6 +120,10 @@ public function cpf_list() {
return $userprofilefieldsarray;
}

/**
* Return subscription modes.
* @return array
*/
public function make_subscription_option_list() {
$options = array();
$options[NEWSLETTER_SUBSCRIPTION_MODE_OPT_IN] = get_string('sub_mode_opt_in',
Expand All @@ -139,6 +135,10 @@ public function make_subscription_option_list() {
return $options;
}

/**
* Returns cohort name and id as key.
* @return array
*/
public function make_cohort_option_list() {
$cohorts = cohort_get_cohorts($this->context->id);
$options = array();
Expand Down
Loading

0 comments on commit 2ef7243

Please sign in to comment.