MDL-65257 message_email: add images to digest

This commit is contained in:
Mark Nelson 2019-04-29 15:01:30 +08:00
parent 14cdf51189
commit aa0792484e
4 changed files with 41 additions and 0 deletions

View File

@ -83,6 +83,8 @@ class email_digest implements \renderable, \templatable {
* @return \stdClass The data ready for use in a mustache template
*/
public function export_for_template(\renderer_base $renderer) {
global $PAGE;
// Prepare the data we are going to send to the template.
$data = new \stdClass();
$data->conversations = [];
@ -97,8 +99,19 @@ class email_digest implements \renderable, \templatable {
$viewallmessageslink = new \moodle_url('/message/index.php', ['convid' => $conversation->id]);
$group = new \stdClass();
$group->id = $conversation->groupid;
$group->picture = $conversation->picture;
$group->hidepicture = $conversation->hidepicture;
$group->courseid = $conversation->courseid;
$grouppictureurl = $renderer->image_url('g/g1')->out(false); // Default image.
if ($url = get_group_picture_url($group, $group->courseid, false, true)) {
$grouppictureurl = $url->out(false);
}
$conversationformatted = new \stdClass();
$conversationformatted->groupname = $conversation->name;
$conversationformatted->grouppictureurl = $grouppictureurl;
$conversationformatted->coursename = $conversation->coursename;
$conversationformatted->numberofunreadmessages = count($messages);
$conversationformatted->messages = [];
@ -110,8 +123,17 @@ class email_digest implements \renderable, \templatable {
foreach ($messages as $message) {
$user = new \stdClass();
username_load_fields_from_object($user, $message);
$user->picture = $message->picture;
$user->imagealt = $message->imagealt;
$user->email = $message->email;
$user->id = $message->useridfrom;
$userpicture = new \user_picture($user);
$userpicture->includetoken = true;
$userpictureurl = $userpicture->get_url($PAGE)->out(false);
$messageformatted = new \stdClass();
$messageformatted->userpictureurl = $userpictureurl;
$messageformatted->userfullname = fullname($user);
$messageformatted->message = message_format_message_text($message);

View File

@ -73,6 +73,8 @@ class send_email_task extends scheduled_task {
// Keep track of which emails failed to send.
$users = $this->get_unique_users();
foreach ($users as $user) {
cron_setup_user($user);
$hascontent = false;
$renderable = new \message_email\output\email_digest($user);
$conversations = $this->get_conversations_for_user($user->id);
@ -97,6 +99,7 @@ class send_email_task extends scheduled_task {
}
}
}
cron_setup_user();
$users->close();
}

View File

@ -30,16 +30,19 @@
"conversations": [
{
"groupname": "Blue Students",
"grouppictureurl": "http://example.com/image.jpg",
"coursename": "Math 101",
"numberofunreadmessages": "2",
"messages": [
{
"userfullname": "Chris Cross",
"userpictureurl": "http://example.com/image.jpg",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla neque nunc, bibendum ac vestibulum sit amet, scelerisque luctus sem. Maecenas ultricies hendrerit augue, ac venenatis odio volutpat nec",
"timesent": "10:12"
},
{
"userfullname": "Irene Ipsum",
"userpictureurl": "http://example.com/image.jpg",
"message": "Etiam a tristique risus. Pellentesque id tellus eget elit dictum varius id sed sapien",
"timesent": "10:14"
}
@ -92,6 +95,9 @@
<table class="table">
<thead>
<tr>
<th>
<img src="{{{ grouppictureurl }}}" class="round" width="40px" height="40px"/>
</th>
<th>
<strong>{{ groupname }}</strong><br>
{{ coursename }}
@ -104,6 +110,9 @@
<tbody>
{{#messages}}
<tr>
<td>
<img src="{{{ userpictureurl }}}" class="round" width="30px" height="30px">
</td>
<td>
<strong>{{{ userfullname }}}</strong>
<p>{{{ message }}}</p>

View File

@ -30,16 +30,19 @@
"conversations": [
{
"groupname": "Blue Students",
"grouppictureurl": "http://example.com/image.jpg",
"coursename": "Math 101",
"numberofunreadmessages": "2",
"messages": [
{
"userfullname": "Chris Cross",
"userpictureurl": "http://example.com/image.jpg",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla neque nunc, bibendum ac vestibulum sit amet, scelerisque luctus sem. Maecenas ultricies hendrerit augue, ac venenatis odio volutpat nec",
"timesent": "10:12"
},
{
"userfullname": "Irene Ipsum",
"userpictureurl": "http://example.com/image.jpg",
"message": "Etiam a tristique risus. Pellentesque id tellus eget elit dictum varius id sed sapien",
"timesent": "10:14"
}
@ -50,6 +53,8 @@
}
}}
{{#conversations}}
{{{grouppictureurl}}}
{{groupname}}
{{coursename}}
@ -57,6 +62,8 @@
{{numberofunreadmessages}} {{#str}}emaildigestunreadmessages, message_email{{/str}}
{{#messages}}
{{{ userpictureurl }}}
{{userfullname}}
{{message}}