Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65257

Improve the group messaging digest email by including images

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.7
    • 3.7
    • Messages
    • MOODLE_37_STABLE
    • MOODLE_37_STABLE
    • MDL-65257_master
    • Hide
      Prerequisites.
      1. Enable Site Admin > Plugins > Filters > Multi-Language Content, and also turn on Apply to: Content and headings.
      2. Set-up mailcatcher (https://mailcatcher.me/).
      3. Log in as an admin.
      4. Visit ‘Site administration’ > ‘Server’ > ‘Outgoing mail configuration’.
      5. Set the 'SMTP hosts' field to '127.0.0.1:1025' and save.
      6. Visit http://127.0.0.1:1080/ in your browser so you can view outgoing emails.
      7. Create a course with the name <span class="multilang" lang="en">hello there</span><span class="multilang" lang="es">hola ahí</span>.
      8. Enrol 2 users as students (A, B), ideally having some avatar/image in their profile and having English as language (user->preferences->preferred language).
      9. Create a group with the name <span class="multilang" lang="en">Group name</span><span class="multilang" lang="es">Nombre del grupo</span>, a group image and 'Group messaging' to 'Yes'.
      10. Assign all the users you enrolled into that group.
      Test 1
      1. Log in as A.
      2. Send 5 messages to the group.
      3. Log out
      4. Run the following:

        php admin/tool/task/cli/schedule_task.php --execute="\message_email\task\send_email_task"
        

      5. Confirm B gets an email.
      6. Confirm the email contains the group and user image.
      7. Confirm you only see the text "hello there" for the course name and "Group name" for the group name.
      Show
      Prerequisites. Enable Site Admin > Plugins > Filters > Multi-Language Content, and also turn on Apply to: Content and headings. Set-up mailcatcher ( https://mailcatcher.me/ ). Log in as an admin. Visit ‘Site administration’ > ‘Server’ > ‘Outgoing mail configuration’. Set the 'SMTP hosts' field to '127.0.0.1:1025' and save. Visit http://127.0.0.1:1080/ in your browser so you can view outgoing emails. Create a course with the name <span class="multilang" lang="en">hello there</span><span class="multilang" lang="es">hola ahí</span> . Enrol 2 users as students (A, B), ideally having some avatar/image in their profile and having English as language (user->preferences->preferred language). Create a group with the name <span class="multilang" lang="en">Group name</span><span class="multilang" lang="es">Nombre del grupo</span> , a group image and 'Group messaging' to 'Yes'. Assign all the users you enrolled into that group. Test 1 Log in as A. Send 5 messages to the group. Log out Run the following: php admin/tool/task/cli/schedule_task.php --execute="\message_email\task\send_email_task" Confirm B gets an email. Confirm the email contains the group and user image. Confirm you only see the text "hello there" for the course name and "Group name" for the group name.

      The original mock-up includes a user and group image (see attached image). I have been trying to utilise MDL-36754 with no luck. The reason -

      https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L3186 will prevent a token from working if it is created with a userid of 0 (which will happen in a scheduled task). I don't see how it is possible from a scheduled task to avoid this. Whenever you call moodle_url::make_pluginfile_url() and specify you want to create a token it calls https://github.com/moodle/moodle/blob/master/lib/weblib.php#L789 which then creates a token using $USER->id if it doesn't exist (see https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L3264).

      The user already exists, but there is no token, so when creating the URL for them (see snippets below) it automatically creates a token (with userid 0 since its from a scheduled task where $USER->id is 0 (there is no option to pass a user id)). Frankly, I am not sure what is happening in forum to prevent this, but it is late and I have been staring at code for a while. My guess is it sets up the tokens before it generates the URLs (which seems counter-intuitive looking at the API which leans towards creating the token on the fly). Perhaps what I am trying to achieve is not possible. I could hack the $USER->id but obviously that is not an acceptable option.

      $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);
      }
      

      $user = new \stdClass();
      $usernamefields = explode(',' ,\user_picture::fields());
      foreach ($usernamefields as $usernamefield) {
          $user->$usernamefield = $message->$usernamefield;
      }
      $user->id = $message->useridfrom;
       
      $userpicture = new \user_picture($user);
      $userpicture->includetoken = true;
       
      $userpictureurl = $userpicture->get_url($PAGE)->out(false);
      

            markn Mark Nelson
            markn Mark Nelson
            Carlos Escobedo Carlos Escobedo
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 hours, 45 minutes
                5h 45m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.