Changing username display to custom user attributes first name in discussion "monitoring" emails
Permalink Browser Info Environment
I need to adjust the email received when users monitor a discussion / forum to show custom user attribute first name (Fname) and last name (Lname) to replace the username ($name) and poster's username ($postername) in the following code found in /packages/discussion/mail/discussion_track.php. Any help would be appreciated
<?php if (defined('DISCUSSION_MONITOR_FROM_EMAIL')) { $from = array(DISCUSSION_MONITOR_FROM_EMAIL, DISCUSSION_MONITOR_FROM_NAME); } $subject = "{$thread_title}: {$title}"; $body = t('Dear')." {$name}, {$posterName} ".t('has posted to a discussion you\'re monitoring')." ".t('Subject').": {$post_title} ".t('Message').": {$post_body} ".t('Click the link below to view the discussion').": {$link}"; if (ENABLE_USER_PROFILES) { $body .= "
Viewing 15 lines of 20 lines. View entire code block.
Type: | Discussion |
---|---|
Status: | Archived |
Many thanks for the quick reply, Ryan. When I replace the code with that given above, no monitor email is sent. Maybe I am missing something?
The example code Ryan provided includes php tags, but you wouldn't include the surrounding php tags in your code. Was that what was occurring?
No, I did not include the php tags
Can you post the code snippet as you changed it? It's hard to troubleshoot without knowing what you've changed.
Many thanks Evan
Original code from around line 121 of packages/discussion/models/discussion_track.php ...
going on the above post I tried a few things but in the first place tried the following ...
Original code from around line 121 of packages/discussion/models/discussion_track.php ...
//this is the forum title $mh->addParameter('title', $this->c->getCollectionName()); $threadTitle=(strlen($this->thread_title))? $this->thread_title: $this->post_title; $mh->addParameter('thread_title', $threadTitle); $mh->addParameter('post_title', $this->post_title); $mh->addParameter('post_body', $this->post_body); $mh->addParameter('name', $u->getUserName()); $mh->addParameter('posterName', $posting_u->getUserName()); $mh->addParameter('posterProfile', BASE_URL . View::url('/profile',$poster_uID)); $mh->to($ui->getUserEmail()); $mh->load('discussion_track', 'discussion'); Loader::library("mail/importer"); $mi = MailImporter::getByHandle("discussion_post_reply"); if (is_object($mi) && is_object($newEntry) && $mi->isMailImporterEnabled()) { $data = new stdClass;
Viewing 15 lines of 20 lines. View entire code block.
going on the above post I tried a few things but in the first place tried the following ...
//this is the forum title $mh->addParameter('title', $this->c->getCollectionName()); $threadTitle=(strlen($this->thread_title))? $this->thread_title: $this->post_title; $mh->addParameter('thread_title', $threadTitle); $mh->addParameter('post_title', $this->post_title); $mh->addParameter('post_body', $this->post_body); $ui = UserInfo::getByUserName($name); $name = $ui->getAttribute('fName'). " ". $ui->getAttribute('lName'); $mh->addParameter('name', $u->getUserName()); $mh->addParameter('posterName', $posting_u->getUserName()); $mh->addParameter('posterProfile', BASE_URL . View::url('/profile',$poster_uID)); $mh->to($ui->getUserEmail()); $mh->load('discussion_track', 'discussion'); Loader::library("mail/importer"); $mi = MailImporter::getByHandle("discussion_post_reply");
Viewing 15 lines of 22 lines. View entire code block.
I see. The issue is that you don't have $name defined before you use it to get the username by name.
Instead of:
It should be:
Then I think you want the 'name' parameter to be this first name + last name combined string, so instead of:
It should be:
Since $name now contains that combined first name / last name string.
Does that make sense?
Also, with files like this that kind of run in the "background" you can check your logs (type "logs" in intelligent search) and it will show you errors that are occurring. In this case, I think you're calling methods on $ui, but $ui hasn't been defined since the username provided in UserInfo::getByUserName is null.
Edit: whoops, typo previously in first "instead" :).
Instead of:
$ui = UserInfo::getByUserName($name);
It should be:
$ui = UserInfo::getByUserName($u->getUserName());
Then I think you want the 'name' parameter to be this first name + last name combined string, so instead of:
$mh->addParameter('name', $u->getUserName());
It should be:
$mh->addParameter('name', $name);
Since $name now contains that combined first name / last name string.
Does that make sense?
Also, with files like this that kind of run in the "background" you can check your logs (type "logs" in intelligent search) and it will show you errors that are occurring. In this case, I think you're calling methods on $ui, but $ui hasn't been defined since the username provided in UserInfo::getByUserName is null.
Edit: whoops, typo previously in first "instead" :).
Many thanks Evan - that works great!
Here is the code block for others looking to also have personalised discussion forum notification emails with user's first name and poster's first name and last name displayed in the notification email. A copy of the file packages/discussion/models/discussion_track.php was placed in folder models/discussion_track.php. And the code block at around line 121 was replaced with the below. Note this is using custom user attributes 'fname' and 'lname' for first name and last name respectively ...
Here is the code block for others looking to also have personalised discussion forum notification emails with user's first name and poster's first name and last name displayed in the notification email. A copy of the file packages/discussion/models/discussion_track.php was placed in folder models/discussion_track.php. And the code block at around line 121 was replaced with the below. Note this is using custom user attributes 'fname' and 'lname' for first name and last name respectively ...
//this is the forum title $mh->addParameter('title', $this->c->getCollectionName()); $threadTitle=(strlen($this->thread_title))? $this->thread_title: $this->post_title; $mh->addParameter('thread_title', $threadTitle); $mh->addParameter('post_title', $this->post_title); $mh->addParameter('post_body', $this->post_body); $ui = UserInfo::getByUserName($u->getUserName()); $name = $ui->getAttribute('fname'); $mh->addParameter('name', $name); $up = UserInfo::getByUserName($posting_u->getUserName()); $postername = $up->getAttribute('fname'). " ". $up->getAttribute('lname'); $mh->addParameter('posterName', $postername); $mh->addParameter('posterProfile', BASE_URL . View::url('/profile',$poster_uID)); $mh->to($ui->getUserEmail()); $mh->load('discussion_track', 'discussion');
Viewing 15 lines of 24 lines. View entire code block.
Sweet! Good to hear.
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.
To re-open this issue, reply to this message.
To re-open this issue, reply to this message.
in the notify() method around line 121 you'll see:
If you wanted to contain your changes to the mail template only you could get the user info object by the username too.