Skip to content
Open
12 changes: 10 additions & 2 deletions classes/broadcast_recipient_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class block_quickmail_broadcast_recipient_filter {
'middlename' => 1,
'alternatename' => 1
];
public int $result_user_count;
public array $display_users;
public array $result_users;
public mixed $filter_result_params;
public mixed $filter_result_sql;
public mixed $draft_message;
public array $extra_params;
public array $filter_params;

/**
* Construct a wrapper instance for moodle's user_filtering class
Expand All @@ -93,8 +101,8 @@ public function __construct($filterparams, $extraparams, $draftmessage = null) {

// In user/filters/lib.php this variable $SESSION->user_filtering
// sometimes is set to '' which causes an error. Instead of changing core from
// if (!isset($SESSION->user_filtering) to the what's below I'll do that
// check here right before the call.
// if (!isset($SESSION->user_filtering) to the what's below I'll do that
// check here right before the call.
if (!isset($SESSION->user_filtering) || $SESSION->user_filtering == '') {
$SESSION->user_filtering = array();
}
Expand Down
3 changes: 3 additions & 0 deletions classes/components/broadcast_message_component.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

class broadcast_message_component extends component implements \renderable {
public $broadcastform;
public string $heading;
public mixed $broadcast_form;

public function __construct($params = []) {
parent::__construct($params);
$this->broadcast_form = $this->get_param('broadcast_form');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class broadcast_recipient_filter_results_component extends component implements
public $displayusers;
public $sortby;
public $sortdir;
public mixed $sort_dir;
public mixed $sort_by;
public mixed $page;
public $draft_id;
public $display_users;
public $result_user_count;
public mixed $broadcast_recipient_filter;

public function __construct($params = []) {
parent::__construct($params);
Expand Down
2 changes: 2 additions & 0 deletions classes/components/notification_index_component.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class notification_index_component extends component implements \renderable {
public $courseid;
public $sortby;
public $sortdir;
public mixed $sort_dir;
public mixed $sort_by;

public function __construct($params = []) {
parent::__construct($params);
Expand Down
1 change: 1 addition & 0 deletions classes/filemanager/attachment_appender.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class attachment_appender {
public $body;
public $course_context;
public $message_attachments;
public string $links;

public function __construct(message $message, $body) {
$this->message = $message;
Expand Down
4 changes: 4 additions & 0 deletions classes/forms/broadcast_message_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class broadcast_message_form extends \moodleform {
public $userdefaultsignatureid;
public $courseconfigarray;
public $draftmessage;
public mixed $draft_message;
public mixed $course_config_array;
public mixed $user_default_signature_id;
private mixed $user_signature_array;

/**
* Instantiates and returns a compose message form
Expand Down
3 changes: 3 additions & 0 deletions classes/migrator/migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class migrator {
public static $draftrecipienttable = 'block_quickmail_draft_recips';
public static $messagerecipienttable = 'block_quickmail_msg_recips';
public static $additionalemailtable = 'block_quickmail_msg_ad_email';
public int $migrated_count;
public int $chunk_size;
public $site_id;

public function __construct() {
global $DB;
Expand Down
3 changes: 2 additions & 1 deletion classes/notifier/models/notification_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ abstract class notification_model implements notification_model_interface {
public $notificationtypeinterface;
public $notification;
public $condition;
public notification_type_interface $notification_type_interface;

public function __construct(notification_type_interface $notificationtypeinterface) {
$this->notification_type_interface = $notificationtypeinterface;
$this->notificationtypeinterface = $notificationtypeinterface;
$this->notification = $notificationtypeinterface->get_notification();
$this->condition = notification_condition::from_condition_string($this->notification->get('conditions'));
}
Expand Down
5 changes: 3 additions & 2 deletions classes/notifier/notification_condition_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class notification_condition_summary {

public $langstringkey;
public $params;
public mixed $lang_string_key;

public function __construct($langstringkey, $params = []) {
$this->lang_string_key = $langstringkey;
$this->langstringkey = $langstringkey;
$this->params = $params;
}

Expand Down Expand Up @@ -82,7 +83,7 @@ public function format() {
$langarray[$key] = $this->format_condition_value($key, $params);
}

return block_quickmail_string::get($this->lang_string_key, (object) $langarray);
return block_quickmail_string::get($this->langstringkey, (object) $langarray);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/persistents/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function populate_recip_course_msg()
global $DB;

$messageid = $this->get('id');
$cuser = $this->get('user_id');
$cuser = $DB->get_record('user', ['id' => $this->get('user_id')]);
$course = $DB->get_record('course', ['id' => $this->get('course_id')]);
$coursemsg = new message($messageid);

Expand Down Expand Up @@ -270,7 +270,7 @@ public function get_message_recipients($status = 'all', $asuseridarray = false)
}

$recipientids = array_reduce($checkedrecipients, function ($carry, $recipient) {
$carry[] = $checkedrecipients->get('user_id');
$carry[] = $recipient->get('user_id');

return $carry;
}, []);
Expand Down
4 changes: 2 additions & 2 deletions classes/repos/queued_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public static function sync_course_recip_msgs() {
$syncthese = $DB->get_records('block_quickmail_msg_course', $params);

$now = time();
foreach ($syncthese as $cmsg) {

foreach ($syncthese as $cmsg) {
$zeemsg = new message($cmsg->message_id);
if ($zeemsg->get('to_send_at') <= $now) {

Expand Down
5 changes: 5 additions & 0 deletions classes/services/grade_calculator/calculation_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class calculation_exception extends \Exception {
public $message;
public $courseid;
public $userid;
/**
* @var mixed|null
*/
public mixed $user_id;
public mixed $course_id;

public function __construct($message, $courseid, $userid = null) {
$this->message = $message;
Expand Down
3 changes: 3 additions & 0 deletions classes/services/grade_calculator/course_grade_calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class course_grade_calculator {
public $courseid;
public $coursecontext;
public $coursegradeitem;
public $course_grade_item;
public $course_context;
public int $course_id;

/**
* Constructs the course grade calculator
Expand Down
16 changes: 16 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,5 +1136,21 @@ function xmldb_block_quickmail_upgrade($oldversion) {
$dbman->create_table($table);
}
}

if ($oldversion < 2024101702) {

// Define index msgrec (not unique) to be added to block_quickmail_msg_course.
$table = new xmldb_table('block_quickmail_msg_course');
$index = new xmldb_index('msgrec', XMLDB_INDEX_NOTUNIQUE, ['sent_at']);

// Conditionally launch add index msgrec.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Quickmail savepoint reached.
upgrade_block_savepoint(true, 2024101702, 'quickmail');
}

return $result;
}
6 changes: 3 additions & 3 deletions tests/unit/course_recipient_send_factory_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function test_recipient_send_factory_sets_prepended_subject_correctly() {
// Reset all changes automatically after this test.
$this->resetAfterTest(true);

$this->update_system_config_value('block_quickmail_prepend_class', 'shortname');
set_config('block_quickmail_prepend_class', 'shortname');

// Set up a course with a teacher and students.
list($course, $userteacher, $userstudents) = $this->setup_course_with_teacher_and_students();
Expand Down Expand Up @@ -249,7 +249,7 @@ public function test_recipient_send_factory_sets_no_reply_params_correctly() {
// Reset all changes automatically after this test.
$this->resetAfterTest(true);

$this->update_system_config_value('noreplyaddress', 'no@reply.com');
set_config('noreplyaddress', 'no@reply.com');

// Set up a course with a teacher and students.
list($course, $userteacher, $userstudents) = $this->setup_course_with_teacher_and_students();
Expand All @@ -275,7 +275,7 @@ public function test_recipient_send_factory_sets_reply_params_correctly() {
// Reset all changes automatically after this test.
$this->resetAfterTest(true);

$this->update_system_config_value('noreplyaddress', 'no@reply.com');
set_config('noreplyaddress', 'no@reply.com');

// Set up a course with a teacher and students.
list($course, $userteacher, $userstudents) = $this->setup_course_with_teacher_and_students();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/edit_notification_form_validator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_validate_unsupported_message_type_is_invalid() {
// Reset all changes automatically after this test.
$this->resetAfterTest(true);

$this->update_system_config_value('block_quickmail_message_types_available', 'email');
set_config('block_quickmail_message_types_available', 'email');

$input = $this->get_notification_input(['message_type' => 'invalid']);

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/group_repo_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function test_get_course_user_selectable_groups() {
$this->assertArrayHasKey($yellowgroup->id, $groups);
$this->assertArrayHasKey($bluegroup->id, $groups);
$this->assertIsObject($firstgroup);
$this->assertObjectHasAttribute('id', $firstgroup);
$this->assertObjectHasAttribute('name', $firstgroup);
$this->assertObjectHasProperty('id', $firstgroup);
$this->assertObjectHasProperty('name', $firstgroup);

$student = $enrolledusers['student'][0];

Expand Down Expand Up @@ -99,8 +99,8 @@ public function test_get_course_user_groups() {
$this->assertArrayHasKey($yellowgroup->id, $groups);
$this->assertArrayNotHasKey($bluegroup->id, $groups);
$this->assertIsObject($firstgroup);
$this->assertObjectHasAttribute('id', $firstgroup);
$this->assertObjectHasAttribute('name', $firstgroup);
$this->assertObjectHasProperty('id', $firstgroup);
$this->assertObjectHasProperty('name', $firstgroup);

$student = $enrolledusers['student'][38];

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/message_form_validator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function test_validate_unsupported_message_type_is_invalid() {
// Set up a course with a teacher and students.
list($course, $userteacher, $userstudents) = $this->setup_course_with_teacher_and_students();

$this->update_system_config_value('block_quickmail_message_types_available', 'email');
set_config('block_quickmail_message_types_available', 'email');

// Get a compose form submission.
$composeformdata = $this->get_compose_message_form_submission($userstudents, 'message');
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/messenger_compose_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function test_messenger_sends_composed_email_now() {
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(4, $this->email_sink_email_count($sink));
Expand Down Expand Up @@ -89,6 +90,7 @@ public function test_messenger_sends_composed_email_including_mentors_now() {
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

// Should have been sent to 4 users + 1 mentor.
Expand Down Expand Up @@ -117,6 +119,7 @@ public function test_messenger_does_not_send_compose_message_with_invalid_params
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(0, $this->email_sink_email_count($sink));
Expand All @@ -140,6 +143,7 @@ public function test_messenger_sends_composed_message_now() {
$composeformdata = $this->get_compose_message_form_submission($recipients, 'message', []);

// Send a moodle message from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(4, $this->message_sink_message_count($sink));
Expand All @@ -165,6 +169,7 @@ public function test_skips_invalid_user_ids_when_sending() {
]);

// Send an email from the teacher to the students as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(1, $this->email_sink_email_count($sink));
Expand Down Expand Up @@ -193,6 +198,7 @@ public function test_messenger_does_not_send_scheduled_composed_email_now() {
]);

// Schedule an email from the teacher to the students (as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata);

\phpunit_util::run_all_adhoc_tasks();
Expand Down Expand Up @@ -221,6 +227,7 @@ public function test_messenger_sends_to_additional_emails() {
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(7, $this->email_sink_email_count($sink));
Expand Down Expand Up @@ -255,6 +262,7 @@ public function test_messenger_sends_a_receipt_if_asked() {
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertEquals(5, $this->email_sink_email_count($sink));
Expand Down Expand Up @@ -295,6 +303,7 @@ public function test_messenger_sends_with_signature_appended() {
]);

// Send an email from the teacher to the students now (not as queued adhoc tasks).
$this->setUser($userteacher);
messenger::compose($userteacher, $course, $composeformdata, null, false);

$this->assertTrue($this->email_in_sink_body_contains($sink, 1, 'This is one fine body.'));
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/messenger_drafting_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function test_messenger_saves_draft_email() {
]);

// Save this email message as a draft.
$this->setUser($userteacher);
$message = messenger::save_compose_draft($userteacher, $course, $composeformdata);

$messagerecipients = $message->get_message_recipients();
Expand Down Expand Up @@ -87,6 +88,7 @@ public function test_cannot_duplicate_a_draft_that_not_created_by_the_given_user
]);

// Save this email message as a draft.
$this->setUser($userteacher);
$draftmessage = messenger::save_compose_draft($userteacher, $course, $composeformdata);

$this->expectException(validation_exception::class);
Expand Down Expand Up @@ -114,6 +116,7 @@ public function test_duplicates_drafts() {
]);

// Save this email message as a draft.
$this->setUser($userteacher);
$draftmessage = messenger::save_compose_draft($userteacher, $course, $composeformdata);

// Now attempt to duplicate this draft.
Expand Down
Loading