Ozzy47
Well-known member
Working on a addon that sends an email (via a cron) to selected staff when there is a new moderated thread in the mod queue.
Here is the PHP.
Here is the template.
Now when the email comes through, it is partially correct. But what is not being included is the thread title, the message and the go thread bar is not going to the thread.
What do I have to change in the PHP file (and possibly template) to get this to work as wanted?
Here is the PHP.
PHP:
<?php
namespace OzzModz\ModeratedPost\Cron;
class ModeratedPost
{
public static function ModeratedPostEmail()
{
$options = \XF::options();
$sendToUsers = $options->ozzmodzModeratedPost_users;
if (!empty($sendToUsers))
{
$finder = \XF::finder('XF:Thread');
$posts = $finder
->where('post_date', '>', time() - 10 * 60)
->where('discussion_state', 'moderated')
->order('post_date', 'ASC')
->fetch();
foreach ($posts AS $post)
{
foreach ($sendToUsers AS $sendToUser)
{
$mail = \XF::app()->mailer()->newMail();
$user = \XF::app()->find('XF:User', $sendToUser);
if (!empty($user))
{
$mail->setToUser($user);
$mail->setTemplate('ozzmodzModeratedPost_thread_email', [
'post' => $post
]);
$mail->queue();
}
}
}
}
}
}
Here is the template.
HTML:
<mail:subject>
{{ phrase('ozzmodzModeratedPost_new_moderated_thread', {
'title': prefix('thread', $thread, 'escaped') . $thread.title
}) }}
</mail:subject>
{{ phrase('ozzmodzModeratedPost_poster_new_moderated_thread', {
'receiver': $receiver.username,
'poster': username_link_email($post.User, $post.username),
'site': '<a href="' . link('canonical:index') . '">' . $xf.options.boardTitle . '</a>'
}) }}
<h2><a href="{{ link('canonical:posts', $post) }}">{{ prefix('thread', $thread, 'escaped') }}{$thread.title}</a></h2>
<xf:if is="$xf.options.emailWatchedThreadIncludeMessage">
<div class="message">{{ bb_code_type('emailHtml', $post.message, 'post', $post) }}</div>
</xf:if>
<xf:macro template="thread_forum_macros" name="go_thread_bar" arg-thread="{$thread}" arg-watchType="forums" />
Now when the email comes through, it is partially correct. But what is not being included is the thread title, the message and the go thread bar is not going to the thread.
What do I have to change in the PHP file (and possibly template) to get this to work as wanted?