Skip to content

Commit

Permalink
Performance for welcome message sending to students.
Browse files Browse the repository at this point in the history
Order by students.
Dear student, welcome to these courses:
Coursename1
Coursename2
Coursename3

This sends an email for each student.
  • Loading branch information
ethem committed Jul 6, 2006
1 parent 2044f30 commit 905c4d3
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions enrol/authorize/enrol.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 905c4d3

Please sign in to comment.