Reputation: 1745
I'm running Moodle, and have a teacher who receives a notification email anytime a student enrolls in a course (via PayPal enrollment).
The email contents come from lang/en/enrol.php:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}";
What I'm trying to do is include the student's email address in this, for the teacher to reference.
Here's what I've tried:
$string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}". Student\'s email address: {$a->email}';
To make this $a->email variable available, I went into the function that gets the email contents: enrol/flatfile/lib.php::process_records()
Inside process_records(), I added the following:
$a->email = $user->email;
I put this directly after these lines:
$a = new stdClass();
$a->course = format_string($course->fullname, true, array('context' => $context));
$a->user = fullname($user);
and before this line, which gets the email contents:
$eventdata->fullmessage = get_string('enrolmentnewuser', 'enrol', $a);
I would think that the $a object would now contain my new 'email' property, which would be accessible in the 'enrolmentnewuser' string.
I've cleared the cache after my updates.
Unfortunately, this is the email the teacher is now receiving:
Student has enrolled in course "Test Course". Student's email address: {$a->email}
It looks like the $a->email is not swapping the actual property into the message. For the life of me, I haven't been able to figure out why it's not working. It's been difficult to debug, as I have to keep enrolling and un-enrolling in the test course which is frustrating.
Does anyone have any insight into why this is printing the $a->email property name literally, instead of the actual property?
Upvotes: 2
Views: 402
Reputation: 76
In your case, you need to add the below line to enrol/paypal/ipn.php file also.
$a->email = $user->email;
put this directly after these lines:
$a->course = format_string($course->fullname, true, array('context' => $coursecontext));
$a->user = fullname($user);
Upvotes: 3