OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



notify author when comment is posted

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

notify author when comment is posted

Postby Rames » Tue Sep 16, 2008 2:18 pm

I'd like to send an automatic email notification to the corresponding author when a comment is entered for their article. I realize I'll need to write a new email template, but I don't know how to call the template when a user clicks the send button displayed from comment.tpl. A nice feature would be to include the text of the comment in the email.

Thanks!

rames
Rames
 
Posts: 13
Joined: Mon Mar 24, 2008 1:02 pm

Re: notify author when comment is posted

Postby mcrider » Thu Sep 18, 2008 5:45 pm

Hi Rames,

To achieve this, you'll have to do some coding within the add() function of pages/comment/CommentHandler.inc.php. It shouldn't be too difficult to setup a mail template, add the comments as a parameter to the template, and send it off to the author. Here's a simple example I grabbed from classes/manager/form/UserManagementForm.inc.php:
Code: Select all
import('mail.MailTemplate');
$mail = &new MailTemplate('USER_REGISTER');
$mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
$mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
$mail->addRecipient($user->getEmail(), $user->getFullName());
$mail->send();


You'll have to make your own template in place of USER_REGISTER, create your own parameters (the comments), and change addRecipients to the author. You'll have to do more coding to allow the author to opt out of receiving emails automatically, and to allow users to subscribe to comments. Let us know how it goes!

Please also note that users will be able to subscribe to comments via RSS feeds in version 2.3 of OJS (you can see this and other future features in our roadmap at http://lib-pkp.lib.sfu.ca/wiki/index.php/OJS).

Hope that helps,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: notify author when comment is posted

Postby Rames » Tue Sep 23, 2008 11:29 am

Hi Matt,

Thanks for the pointer. I created a new email template 'COMMENT_NOTICE' and added the function 'sendNotice()' to CommentForm.inc.php. I call sendNotice() from the add() function in CommentHandler.inc.php, right after the call to execute(). I added a bit of code to let the author know if the comment is a reply to another comment, and if so pull the title of the parent comment into the email.

This worked fine, with the exception of one quirk. If I added any text to the body of the comment, the email template was overridden by the text of the comment body. I noticed in comment.tpl that the name of the form element for the body of the comment was "body" and was able to fix the issue by giving the from elements more unique names. I updated requests to the form names in CommentForm.inc.php where appropriate.

I borrowed some code from author/form/submit/ArticleEventLog.inc.php and got this event added to the Event log, but am not sure how to add the email to the email log. Any pointers would be appreciated.

As you might imagine, comments are a big part of our journal. My next modification is to allow the reviewers to specify a part of their review for anonymous posting to the article's comments section. I'll take a stab at this myself, but will likely start a new thread if/when I have questions.

Thanks again,
rames

Code: Select all
   
function sendNotice($article,$commentId,$parentId,$parent) {
      import('mail.MailTemplate');
      $mail = &new MailTemplate('COMMENT_NOTICE');
      $authors = &$article->getAuthors();
      $author = &$authors[0];
      $mail->addRecipient($author->getEmail(), $author->getFullName());
      
      $journal = &Request::getJournal();
      if($journal->getSetting('copySubmissionAckSpecified'))
         if (!empty($copyAddress)) $mail->addBcc($journal->getSetting('copySubmissionAckAddress'));
      
      $commentText = "";
      if ($parentId > 0)
         $commentText="This is a reply to '{$parent->getTitle()}'.";
   
      $mail->assignParams(array(
         'articleTitle' => strip_tags($article->getArticleTitle()),
         'authorName' => $author->getFullName(),
         'articleUrl' => Request::url(null, 'article', 'view', $article->getBestArticleId()),
         'commentTitle' => $this->getData('commentTitle'),
         'commentBody' => $this->getData('commentBody'),
         'posterName' => $this->getData('posterName'),
         'posterEmail' => $this->getData('posterEmail'),
         'commentId' => $commentId,
         'parentId' => $parentId,
         'commentText' => $commentText
      ));
      $mail->send();
   }
}
Rames
 
Posts: 13
Joined: Mon Mar 24, 2008 1:02 pm

Re: notify author when comment is posted

Postby mcrider » Tue Sep 23, 2008 12:39 pm

Hi Rames,

Glad to see you got this working, and thanks for the update--It might be helpful to others down the line. You can find an example of how to log emails in the log() function in classes/mail/ArticleMailTemplate.inc.php.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: notify author when comment is posted

Postby mcrider » Tue Sep 23, 2008 1:08 pm

Hi again Rames,

Actually, if you just use an ArticleMailTemplate object instead of a MailTemplate object to setup your template, the logging will be automatic.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: notify author when comment is posted

Postby Rames » Wed Sep 24, 2008 11:27 am

Great, I always like the easy answers. Thanks!

rames
Rames
 
Posts: 13
Joined: Mon Mar 24, 2008 1:02 pm


Return to OJS Development

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests