Skip to content
Browse files

Performance for welcome message sending to students.

Order by students.
Dear student, welcome to these courses:
Coursename1
Coursename2
Coursename3

This sends an email for each student.
  • Loading branch information...
1 parent 2044f30 commit 905c4d38adc8d50379259f1130025bd05a9fd9d5 ethem committed Jul 6, 2006
Showing with 21 additions and 16 deletions.
  1. +21 −16 enrol/authorize/enrol.php
View
37 enrol/authorize/enrol.php
@@ -683,7 +683,7 @@ function check_openssl_loaded() {
*/
function cron()
{
- global $CFG;
+ global $CFG, $SITE;
require_once($CFG->dirroot.'/enrol/authorize/authorizenetlib.php');
$oneday = 86400;
@@ -783,30 +783,35 @@ function cron()
if (!empty($CFG->enrol_mailadmins)) {
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON LOG", $this->log);
}
+
+ // Send emails to students about which courses have enrolled.
if (empty($sendem)) {
return;
}
-
- $lastcourse = 0;
$select = "SELECT E.id, E.courseid, E.userid, C.fullname " .
"FROM {$CFG->prefix}enrol_authorize E " .
"INNER JOIN {$CFG->prefix}course C ON C.id = E.courseid " .
"WHERE E.id IN(" . implode(',', $sendem) . ") " .
- "ORDER BY E.courseid";
- $orders = get_records_sql($select);
- foreach ($orders as $order)
- {
- if ($lastcourse != $order->courseid) {
- $lastcourse = $order->courseid;
- $teacher = get_teacher($lastcourse);
+ "ORDER BY E.userid";
+ $emailinfo = get_records_sql($select);
+ $emailcount = count($emailinfo);
+ for($i = 0; $i < $emailcount; ) {
+ $usercourses = array();
+ $lastuserid = $emailinfo[$i]->userid;
+ for ($j=$i; $j < $emailcount and $emailinfo[$j]->userid == $lastuserid; $j++) {
+ $usercourses[] = $emailinfo[$j]->fullname;
}
- $user = get_record('user', 'id', $order->userid);
$a = new stdClass;
- $a->coursename = $order->fullname;
- $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
- email_to_user($user, $teacher,
- get_string("enrolmentnew", '', $order->fullname),
- get_string('welcometocoursetext', '', $a));
+ $a->courses = implode("\n", $usercourses);
+ $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
+ $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
+ $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
+ $user = get_record('user', 'id', $lastuserid);
+ email_to_user($user,
+ $adminuser,
+ get_string("enrolmentnew", '', $SITE->shortname),
+ $emailmessage);
+ $i = $j;
}
}

0 comments on commit 905c4d3

Please sign in to comment.
Something went wrong with that request. Please try again.