Skip to content

Commit

Permalink
Merge branch 'MDL-43908-MOODLE_26_STABLE' of https://github.com/lucis…
Browse files Browse the repository at this point in the history
…git/moodle into MOODLE_26_STABLE
  • Loading branch information
Sam Hemelryk committed Jul 29, 2014
2 parents 5175bb4 + 072e93e commit 23bf420
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions mod/assign/locallib.php
Expand Up @@ -1580,17 +1580,18 @@ public static function cron() {

// Collect all submissions from the past 24 hours that require mailing.
// Submissions are excluded if the assignment is hidden in the gradebook.
$sql = 'SELECT g.id as gradeid, a.course, a.name, a.blindmarking, a.revealidentities,
g.*, g.timemodified as lastmodified
$sql = "SELECT g.id as gradeid, a.course, a.name, a.blindmarking, a.revealidentities,
g.*, g.timemodified as lastmodified, cm.id as cmid
FROM {assign} a
JOIN {assign_grades} g ON g.assignment = a.id
LEFT JOIN {assign_user_flags} uf ON uf.assignment = a.id AND uf.userid = g.userid
JOIN {course_modules} cm ON cm.course = a.course
JOIN {modules} md ON md.id = cm.module
JOIN {course_modules} cm ON cm.course = a.course AND cm.instance = a.id
JOIN {modules} md ON md.id = cm.module AND md.name = 'assign'
JOIN {grade_items} gri ON gri.iteminstance = a.id AND gri.courseid = a.course AND gri.itemmodule = md.name
WHERE g.timemodified >= :yesterday AND
g.timemodified <= :today AND
uf.mailed = 0 AND gri.hidden = 0';
uf.mailed = 0 AND gri.hidden = 0
ORDER BY a.course, cm.id";

$params = array('yesterday' => $yesterday, 'today' => $timenow);
$submissions = $DB->get_records_sql($sql, $params);
Expand Down Expand Up @@ -1623,9 +1624,6 @@ public static function cron() {
unset($courseidsql);
unset($params);

// Simple array we'll use for caching modules.
$modcache = array();

// Message students about new feedback.
foreach ($submissions as $submission) {

Expand Down Expand Up @@ -1667,21 +1665,13 @@ public static function cron() {
continue;
}

if (!array_key_exists($submission->assignment, $modcache)) {
$mod = get_coursemodule_from_instance('assign', $submission->assignment, $course->id);
if (empty($mod)) {
mtrace('Could not find course module for assignment id ' . $submission->assignment);
continue;
}
$modcache[$submission->assignment] = $mod;
} else {
$mod = $modcache[$submission->assignment];
}
$modinfo = get_fast_modinfo($course, $user->id);
$cm = $modinfo->get_cm($submission->cmid);
// Context lookups are already cached.
$contextmodule = context_module::instance($mod->id);
$contextmodule = context_module::instance($cm->id);

if (!$mod->visible) {
// Hold mail notification for hidden assignments until later.
if (!$cm->uservisible) {
// Hold mail notification for assignments the user cannot access until later.
continue;
}

Expand All @@ -1701,7 +1691,7 @@ public static function cron() {
$messagetype,
$eventtype,
$updatetime,
$mod,
$cm,
$contextmodule,
$course,
$modulename,
Expand Down Expand Up @@ -1729,7 +1719,6 @@ public static function cron() {

// Free up memory just to be sure.
unset($courses);
unset($modcache);
}

// Update calendar events to provide a description.
Expand Down Expand Up @@ -5766,7 +5755,16 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
}
}
$mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'assign'));
$mform->setDefault('sendstudentnotifications', 1);
// Get assignment visibility information for student.
$modinfo = get_fast_modinfo($settings->course, $userid);
$cm = $modinfo->get_cm($this->get_course_module()->id);
// Don't allow notification to be sent if student can't access assignment.
if (!$cm->uservisible) {
$mform->setDefault('sendstudentnotifications', 0);
$mform->freeze('sendstudentnotifications');
} else {
$mform->setDefault('sendstudentnotifications', 1);
}

$mform->addElement('hidden', 'action', 'submitgrade');
$mform->setType('action', PARAM_ALPHA);
Expand Down

0 comments on commit 23bf420

Please sign in to comment.