<![CDATA[ Anyone know how to setup Global Notification of all new posts/new threads? - My Forums]]> https://forums.modx.com/thread/?thread=96163 <![CDATA[Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=3#dis-post-520454 rcarnrick Feb 11, 2015, 05:20 PM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=3#dis-post-520454 <![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=3#dis-post-551624
I have implemented the code on my site but I was confused slightly as to a couple of things.

system setting:
discuss.enable_notifications_moderators -- "yes/no" value?

lexicon entries:
setting_discuss.enable_notifications_moderators, "what do I put here?"
setting_discuss.enable_notifications_moderators_desc "what do I put here?"

Thank you in advance!]]>
rcarnrick Jun 09, 2017, 07:29 PM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=3#dis-post-551624
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541732
]]>
BobRay May 20, 2016, 05:57 PM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541732
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541728
I think BobRay is busy with whatever crisis is going on in the user base, as usual wink He will probably stop by and take a look at your code eventually. Heck the other week i saw him get back to a user on a totally minor point that occurred to him out of the blue from a month earlier. What a resource for us to learn laugh

So this is confirmed as a working solution? Its really a high quality solution.

You really focused well on where you could hook in, and how to generate the proper data. I feel your code is seriously efficient, you just grab what you need and take no prisoners. Also like the error reports so we can see what real testing looks like :p]]>
nuan88 May 20, 2016, 02:37 PM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541728
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541683 ]]> nuan88 May 19, 2016, 11:43 AM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541683 <![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541671 i don't know if my solution is the best way to do it smiley, but it will work.
I've not tested with system settings: global moderators, default moderators

these are my changes:

core/components/discuss/hooks/notifications/send.php
if (empty($url)) {
  /* @var disThread $thread */
  $thread = $modx->getObject('disThread',(int)$scriptProperties['thread']);
  if ($thread) {
	$url = $thread->getUrl(true);
  }
}
----------------Begin -----------------
/* get thread moderators an send notification if system setting is enbaled */
$thread = $modx->getObject('disThread',(int)$scriptProperties['thread']);
if ($thread != null && $modx->getOption('discuss.enable_notifications_moderators',null,true)){
/** @var $thread $moderators */
  $moderators = $thread->getModerators();
  /** @var disUser $moderator */
  foreach ($moderators as $moderator) {

	if ($moderator == null) { continue; }
	$modx->log(modX::LOG_LEVEL_DEBUG, 'moderator get user :'.$moderator->get('id'));
	$user = $modx->getObject('disUser',$moderator->get('id'));

	if ($user == null) { 
	  $modx->log(modX::LOG_LEVEL_DEBUG, 'user null: '.$moderator->get('user'));
	  continue; 
    }
    /* dont notify on own posts! */
	$modx->log(modX::LOG_LEVEL_DEBUG, 'author last : '.$thread->get('author_last').' user: '.$moderator->get('user'));
	if ($thread->get('author_last') == $moderator->get('user')) { continue; }
	$emailProperties = array_merge($scriptProperties,$moderator->toArray());
	$emailProperties['tpl'] = $tpl;
	$emailProperties['name'] = $scriptProperties['title'];
	$emailProperties['type'] = $type;
	$emailProperties['url'] = $url;
	$modx->log(modX::LOG_LEVEL_DEBUG, 'send mail for thread :'.$scriptProperties['thread'].' name '.$user->get('username').' mail '.$user->email);
	$sent = $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
	unset($emailProperties);
  }
}
-------------------------End-------------------------------------

/* send out notifications */
/** @var disUserNotification $notification */
foreach ($notifications as $notification) {


add a new discuss system setting: discuss.enable_notifications_moderators and
lexicon entries: setting_discuss.enable_notifications_moderators,
setting_discuss.enable_notifications_moderators_desc

it is based on the extisting : discuss.enable_notifications extended by _moderators

@BobRay: do you think this is a proper way?

best regards
falko301]]>
falko301 May 19, 2016, 07:35 AM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541671
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541665
I can see the code tries to use the discuss db to get the mod data. this data probably is in there, but it takes a bit more code to access the db fully. I don't understand why, but it does.

The mod list will be in there somewhere, but its not going to easy to get...I mean its in there, you probably have to open up the user classes first and then mod list and then I even doubt you can find the mod list per thread, to be honest. That will be probably data connected with every thread, thread data.]]>
nuan88 May 19, 2016, 01:13 AM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541665
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541664
If you are trying to get the email address of the discuss moderator of a board, that could be a big problem. Because it assumes the classification of who is moderator in discuss is recognized by modx, which its not. the mod class will be known only to discuss, in modx side users have no such class i believe.

or you would have to go into the discuss db to get the info.

maybe try to send to a user first, or a defined email.

[Oh wait he was just sending from site admin to admin...sorry]]]>
nuan88 May 19, 2016, 12:01 AM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541664
<![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541648 BobRay May 18, 2016, 06:02 PM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541648 <![CDATA[Re: Anyone know how to setup Global Notification of all new posts/new threads?]]> https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541612 again thx for your replies.
From my point of view, there are three possible ways to extend discuss.
1) extend the notifications hook, and discuss.class.php
My first try was to send a 'bcc' message to a moderator, but it fails. The bcc was not sent.
  
    
    public function sendEmail($email,$name,$subject,array $properties = array()) {
        if (empty($properties['tpl'])) return false;

        $msg = $this->getChunk($properties['tpl'],$properties);

        $this->modx->getService('mail', 'mail.modPHPMailer');
        $this->modx->mail->set(modMail::MAIL_BODY, $msg);
        $this->modx->mail->set(modMail::MAIL_FROM, $this->modx->getOption('discuss.admin_email'));
        $this->modx->mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('site_name'));
        $this->modx->mail->set(modMail::MAIL_SENDER, $this->modx->getOption('discuss.admin_email'));
        $this->modx->mail->set(modMail::MAIL_SUBJECT, $subject);
        $this->modx->mail->address('to', $email, $name);
-->     $this->modx->mail->address('bcc', $email, $name);
        $this->modx->mail->address('reply-to', $this->modx->getOption('discuss.admin_email'));
        $this->modx->mail->setHTML(true);
        $sent = $this->modx->mail->send();
        $this->modx->mail->reset();

        return $sent;
    }

The moderator or moderators array can be transfered with the properties
2) or only notifications hook

/* send out notifications */

/** @var disUserNotification $notification */

foreach ($notifications as $notification) {

   ...
    $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
    unset($emailProperties);
}
add this-->
/** @var disBoardModerator $notification */

foreach ($notifications as $notification) {

   ...
    $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
    unset($emailProperties);
}

I wolud prefer number 1, but bcc was not sent.
Do you know, why the bcc will not be sent?

regards
falko301]]>
falko301 May 18, 2016, 06:48 AM https://forums.modx.com/thread/96163/anyone-know-how-to-setup-global-notification-of-all-new-posts-new-threads?page=2#dis-post-541612