Skip to content

Commit

Permalink
Send Comment by email added
Browse files Browse the repository at this point in the history
  • Loading branch information
creecros committed Jun 14, 2019
1 parent 8f6d970 commit 8992e7f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
90 changes: 90 additions & 0 deletions Action/SendTaskComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Kanboard\Plugin\SendEmailCreator\Action;

use Kanboard\Model\TaskModel;
use Kanboard\Model\CommentModel;
use Kanboard\Action\Base;

class SendTaskComment extends Base
{

public function getDescription()
{
return t('Send new comments on a task by email');
}


public function getCompatibleEvents()
{
return array(
CommentModel::EVENT_CREATE,
);
}


public function getActionRequiredParameters()
{
return array(
'subject' => t('Email subject'),
'send_to' => array('assignee' => t('Send to Assignee'), 'creator' => t('Send to Creator'), 'both' => t('Send to Both')),
);
}


public function getEventRequiredParameters()
{
return array(
'comment',
'task',
);
}


public function doAction(array $data)
{
$commentSent = FALSE;
if ($this->getParam('send_to') !== null) { $send_to = $this->getParam('send_to'); } else { $send_to = 'both'; }

if ($send_to == 'assignee' || $send_to == 'both') {
$user = $this->userModel->getById($data['task']['owner_id']);

if (! empty($user['email'])) {
$this->emailClient->send(
$user['email'],
$user['name'] ?: $user['username'],
$this->getParam('subject'),
$this->template->render('notification/comment_create', array(
'task' => $data['task'],
'comment' => $data['comment'],
))
);
$commentSent = TRUE;
}
}
if ($send_to == 'creator' || $send_to == 'both') {
$user = $this->userModel->getById($data['task']['creator_id']);

if (! empty($user['email'])) {
$this->emailClient->send(
$user['email'],
$user['name'] ?: $user['username'],
$this->getParam('subject'),
$this->template->render('notification/comment_create', array(
'task' => $data['task'],
'comment' => $data['comment'],
))
);
$commentSent = TRUE;
}
}
return $commentSent;
}



public function hasRequiredCondition(array $data)
{
return true;
}
}
10 changes: 8 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Kanboard\Plugin\SendEmailCreator;

use Kanboard\Core\Plugin\Base;
use Kanboard\Model\CommentModel;
use Kanboard\Plugin\SendEmailCreator\Action\SendTaskAssignee;
use Kanboard\Plugin\SendEmailCreator\Action\SendTaskCreator;
use Kanboard\Plugin\SendEmailCreator\Action\SendTaskComment;
use Kanboard\Plugin\SendEmailCreator\Action\TaskEmailDue;
use Kanboard\Plugin\SendEmailCreator\Action\SubTaskEmailDue;
use Kanboard\Core\Translator;
Expand All @@ -18,9 +20,13 @@ public function initialize()
{

$this->actionManager->register(new SendTaskCreator($this->container));
$this->actionManager->register(new SendTaskAssignee($this->container));
$this->actionManager->register(new SendTaskAssignee($this->container));
$this->actionManager->register(new TaskEmailDue($this->container));
$this->actionManager->register(new SubTaskEmailDue($this->container));
$this->actionManager->register(new SendTaskComment($this->container));

$this->eventManager->register(CommentModel::EVENT_CREATE, 'On comment creation');

}

public function onStartup()
Expand All @@ -41,7 +47,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.1.0';
return '1.2.0';
}

public function getPluginDescription()
Expand Down

1 comment on commit 8992e7f

@creecros
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#11

Please sign in to comment.