Skip to content
Open
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
11 changes: 8 additions & 3 deletions classes/notifier/models/reminder/course_grade_range_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class course_grade_range_model extends reminder_notification_model implements re
* @return array
*/
public function get_user_ids_to_notify() {
global $CFG;

// Make sure a grade_greater_than boundary is set.
if (!$greaterthan = $this->condition->get_value('grade_greater_than')) {
$greaterthan = 0;
Expand All @@ -58,16 +60,19 @@ public function get_user_ids_to_notify() {
// Where users are in a specific course.
global $DB;

$queryresults = $DB->get_records_sql('SELECT u.id
$gradebookroles = explode(',', $CFG->gradebookroles);
list($insql, $params) = $DB->get_in_or_equal($gradebookroles);
$params[] = $this->get_course_id();
$queryresults = $DB->get_records_sql("SELECT u.id
FROM {user} u
INNER JOIN {user_enrolments} ue ON ue.userid = u.id
INNER JOIN {enrol} e ON e.id = ue.enrolid
INNER JOIN {course} c ON c.id = e.courseid
INNER JOIN {role_assignments} ra ON ra.userid = u.id
INNER JOIN {context} ctx ON ctx.id = ra.contextid AND ctx.instanceid = c.id
WHERE ra.roleid IN (SELECT value FROM {config} WHERE name = "gradebookroles")
WHERE ra.roleid " . $insql . "
AND c.id = ?
GROUP BY u.id', [$this->get_course_id()]);
GROUP BY u.id", $params);

$courseuserids = array_keys($queryresults);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,23 @@ public function get_user_ids_to_notify() {
// Where users are in a specific course.
// And where have not accessed the course since a conditionally set increment of time before now.

global $DB;
global $DB, $CFG;

$results = $DB->get_records_sql('SELECT u.id
FROM {user} u
$gradebookroles = explode(',', $CFG->gradebookroles);
list($insql, $params) = $DB->get_in_or_equal($gradebookroles);
$params[] = $this->condition->get_offset_timestamp_from_now('before');
$params[] = $this->get_course_id();
$results = $DB->get_records_sql("SELECT u.id
FROM {user} u
INNER JOIN {user_enrolments} ue ON ue.userid = u.id
INNER JOIN {enrol} e ON e.id = ue.enrolid
INNER JOIN {course} c ON c.id = e.courseid
INNER JOIN {role_assignments} ra ON ra.userid = u.id
INNER JOIN {context} ctx ON ctx.id = ra.contextid AND ctx.instanceid = c.id
WHERE u.id NOT IN (SELECT la.userid FROM {user_lastaccess} la WHERE la.courseid = c.id AND la.timeaccess > ?)
AND ra.roleid IN (SELECT value FROM {config} WHERE name = "gradebookroles")
AND c.id = ?
GROUP BY u.id', [$this->condition->get_offset_timestamp_from_now('before'), $this->get_course_id()]);
WHERE ra.roleid " . $insql . "
AND u.id NOT IN (SELECT la.userid FROM {user_lastaccess} la WHERE la.courseid = c.id AND la.timeaccess > ?)
AND c.id = ?
GROUP BY u.id", $params);

return array_keys($results);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/messenger_compose_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use block_quickmail\persistents\signature;
use block_quickmail\exceptions\validation_exception;

class block_quickmail_messenger_compose_testcase extends advanced_testcase {
class messenger_compose_test extends advanced_testcase {

use has_general_helpers,
sets_up_courses,
Expand All @@ -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
5 changes: 4 additions & 1 deletion tests/unit/messenger_drafting_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use block_quickmail\persistents\signature;
use block_quickmail\exceptions\validation_exception;

class block_quickmail_messenger_drafting_testcase extends advanced_testcase {
class messenger_drafting_test extends advanced_testcase {

use has_general_helpers,
sets_up_courses,
Expand Down 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
3 changes: 2 additions & 1 deletion tests/unit/send_all_ready_messages_task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use block_quickmail\messenger\messenger;
use block_quickmail\tasks\send_all_ready_messages_task;

class block_quickmail_send_all_ready_messages_task_testcase extends advanced_testcase {
class send_all_ready_messages_task_test extends advanced_testcase {

use has_general_helpers,
sets_up_courses,
Expand Down Expand Up @@ -99,6 +99,7 @@ private function create_messages($course, $userteacher, $userstudents) {
]);

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

$messages[] = $message;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/send_message_adhoc_task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use block_quickmail\tasks\send_message_adhoc_task;
use core\task\manager as task_manager;

class block_quickmail_send_message_adhoc_task_testcase extends advanced_testcase {
class send_message_adhoc_task_test extends advanced_testcase {

use has_general_helpers,
sets_up_courses,
Expand Down Expand Up @@ -70,6 +70,7 @@ public function test_send_message_adhoc_task_sends() {
]);

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

\phpunit_util::run_all_adhoc_tasks();
Expand Down
13 changes: 1 addition & 12 deletions tests/unit/traits/has_general_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,7 @@ public function get_course_config_params(array $overrideparams = []) {
}

public function update_system_config_value($configname, $newvalue) {
global $DB;

if ($record = $DB->get_record('config', ['name' => $configname])) {
$record->value = $newvalue;

$DB->update_record('config', $record);
} else {
$DB->insert_record('config', (object)[
'name' => $configname,
'value' => $newvalue,
]);
}
set_config($configname, $newvalue);
}

public function override_params($values, $overrides) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/traits/submits_compose_message_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function get_recipients_array($recipients) {
// Not sure how this ever worked with undescores.
// Recipient IDs will never have been captured.
$containername = $inclusiontype . 'entityids';
$containername[] = $recipienttype . '_' . $id;
$$containername[] = $recipienttype . '_' . $id;
}
}
}
Expand Down