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

Messaging: Allow for personalization of message by using ##field## similar to database or [[filtertext]]

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.9.5, 2.0.3
    • Fix Version/s: DEV backlog
    • Component/s: Messages
    • Labels:
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE

      Description

      On a site migration, we wanted to send out a message to all users indicating their username. I realized there is currently no way that I could think of to send a message like:

      Dear ##firstname##,

      Welcome to the new site. Your username is ##username##. You can find the new site at http://newsite.com/.

      The goal would be that the ##firstname## and ##username## would get replaced with that individual user's firstname, lastname, or username as specified. This would not be too difficult to do. The name fields would need to be added (firstname, lastname, and username) to the query which would increase the amount of memory and may impact large groups. Otherwise the replacements could be done in /admin/user/user_bulk_message.php.

      if ($confirm and !empty($msg) and confirm_sesskey()) {
      $in = implode(',', $SESSION->bulk_users);
      if ($rs = get_recordset_select('user', "id IN ($in)")) {
      while ($user = rs_fetch_next_record($rs))

      { // this would be a good place for a search and replace on a template like ##username##, ##firstname##, ##lastname## message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct'); }

      }
      redirect($return);
      }

      For now I am just going to handle this with a manual query adding the records to the message table but it would be nice to add some personalization to the bulk messaging. I am not sure how this might relate to the improved messaging system being worked on for Moodle 2.0.

        Gliffy Diagrams

        1. MDL-19851.patch
          2 kB
          Anthony Borrow
        2. MDL-19851.patch
          1 kB
          Anthony Borrow

          Issue Links

            Activity

            Hide
            aborrow Anthony Borrow added a comment -

            Attached is a patch that would implement ##username## and ##fullname##. I added some commented text based on MDL-20199 that suggests modifying fullname so that it could take a parameter (firstname or lastname) to give the name function a little more flexibility. My only concern with this patch is performance. I know that that has been an issue previously with bulk sending messages so I realize that adding this on may complicate things. This patch is primarily to show what I was thinking in terms of flexibility but needs to be tested. Use it in so far as it is helpful. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - Attached is a patch that would implement ##username## and ##fullname##. I added some commented text based on MDL-20199 that suggests modifying fullname so that it could take a parameter (firstname or lastname) to give the name function a little more flexibility. My only concern with this patch is performance. I know that that has been an issue previously with bulk sending messages so I realize that adding this on may complicate things. This patch is primarily to show what I was thinking in terms of flexibility but needs to be tested. Use it in so far as it is helpful. Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            The suggested modification to fullname are related to MDL-20199 and can be found there.

            Show
            aborrow Anthony Borrow added a comment - The suggested modification to fullname are related to MDL-20199 and can be found there.
            Hide
            aborrow Anthony Borrow added a comment -

            Karl Rolfe requested that I work up a patch for Moodle 2.0 that works for both sending bulk messages from the Site admin's browse user page and the participant block page. Here is the link to show what I am thinking - https://github.com/arborrow/moodle/compare/MOODLE_20_STABLE...MDL-19851. I duplicated the code in both places in order to avoid modifying message_post_message because it is used in message/index.php. If we want to allow this type of personalization there as well then the patch could be simplified by doing the pattern replacement in the message_post_message function. I've not really tested this patch but wanted to give Karl something to play with. Let me know if there are any errors and I'll have a look and see if I can clean things up. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - Karl Rolfe requested that I work up a patch for Moodle 2.0 that works for both sending bulk messages from the Site admin's browse user page and the participant block page. Here is the link to show what I am thinking - https://github.com/arborrow/moodle/compare/MOODLE_20_STABLE...MDL-19851 . I duplicated the code in both places in order to avoid modifying message_post_message because it is used in message/index.php. If we want to allow this type of personalization there as well then the patch could be simplified by doing the pattern replacement in the message_post_message function. I've not really tested this patch but wanted to give Karl something to play with. Let me know if there are any errors and I'll have a look and see if I can clean things up. Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            I did a little testing via Participants block and found some dumb mistakes which I've cleaned up. At least it seems functional; however, the text is being displayed as HTML and I don't think it should work that way so I also filed MDL-27823. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - I did a little testing via Participants block and found some dumb mistakes which I've cleaned up. At least it seems functional; however, the text is being displayed as HTML and I don't think it should work that way so I also filed MDL-27823 . Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            Just to be clear, I would not recommend implementing ##username## as that should really not be displayed to anyone else other than the user. Revealing that information could be considered a security vulnerability. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - Just to be clear, I would not recommend implementing ##username## as that should really not be displayed to anyone else other than the user. Revealing that information could be considered a security vulnerability. Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            OK I am recalling now why it was that I had considered including username here and that is because it is for the site admin. The use case would be when a site admin has manually created a number of users via csv import and wants to send a welcome message and provide them with their username. I'm going to leave this in the patch in my repository and its utility can be evaluated upstream. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - OK I am recalling now why it was that I had considered including username here and that is because it is for the site admin. The use case would be when a site admin has manually created a number of users via csv import and wants to send a welcome message and provide them with their username. I'm going to leave this in the patch in my repository and its utility can be evaluated upstream. Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            I'm adding the patch label and pull branch and diff urls. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - I'm adding the patch label and pull branch and diff urls. Peace - Anthony
            Hide
            aborrow Anthony Borrow added a comment -

            An updated patch file based off MOODLE_20_STABLE - the logic and naming of this updated patch better reflects my later comments

            Show
            aborrow Anthony Borrow added a comment - An updated patch file based off MOODLE_20_STABLE - the logic and naming of this updated patch better reflects my later comments
            Hide
            hughnano Edward Hewlett added a comment - - edited

            Thanks for this, Anthony! I managed to tweak this to allow me to notify new users of their new usernames, temporary passwords, etc. - a solution I have been searching for for quite a while now! Only one minor problem, which may have a very obvious solution that I'm overlooking... When the messages are sent out, the users receive two copies: a nice HTML copy which contains the appropriate info, and a text-only copy which contains the hash-tagged field names. Any ideas on what is going wrong for me here?

            UPDATE: Sorry, my bad. I applied the patch manually and neglected to delete the first line marked "-", resulting in two messages being sent out. Thanks again, Anthony!

            Show
            hughnano Edward Hewlett added a comment - - edited Thanks for this, Anthony! I managed to tweak this to allow me to notify new users of their new usernames, temporary passwords, etc. - a solution I have been searching for for quite a while now! Only one minor problem, which may have a very obvious solution that I'm overlooking... When the messages are sent out, the users receive two copies: a nice HTML copy which contains the appropriate info, and a text-only copy which contains the hash-tagged field names. Any ideas on what is going wrong for me here? UPDATE: Sorry, my bad. I applied the patch manually and neglected to delete the first line marked "-", resulting in two messages being sent out. Thanks again, Anthony!
            Hide
            aborrow Anthony Borrow added a comment -

            Edward - Glad you were able to figure it out and that it is working for you. Thanks for posting that you found the issue. Peace - Anthony

            Show
            aborrow Anthony Borrow added a comment - Edward - Glad you were able to figure it out and that it is working for you. Thanks for posting that you found the issue. Peace - Anthony
            Hide
            felicia Felicia Berryman added a comment -

            One of the programmers at my institution created a filter that subs $FIRST_NAME$, $LAST_NAME$, and more for the correct values. It seems to work everywhere except when sending messages, it only shows up correctly in the website (not in the pop-up message or forwarded email). He said I can share the code, so I'll upload the filter here. They are referred to as "tokens," because we are trying to replace them with ANGEL "tokens."

            Show
            felicia Felicia Berryman added a comment - One of the programmers at my institution created a filter that subs $FIRST_NAME$, $LAST_NAME$, and more for the correct values. It seems to work everywhere except when sending messages, it only shows up correctly in the website (not in the pop-up message or forwarded email). He said I can share the code, so I'll upload the filter here. They are referred to as "tokens," because we are trying to replace them with ANGEL "tokens."
            Hide
            felicia Felicia Berryman added a comment -

            filter to substitute $FIRST_NAME$ with firstname.

            Show
            felicia Felicia Berryman added a comment - filter to substitute $FIRST_NAME$ with firstname.
            Hide
            felicia Felicia Berryman added a comment -

            Also, can someone let me know if filters should work in the emails and pop-ups messages. If so, I'll create a tracker report.

            Show
            felicia Felicia Berryman added a comment - Also, can someone let me know if filters should work in the emails and pop-ups messages. If so, I'll create a tracker report.

              People

              • Votes:
                9 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: