Skip to content

Commit

Permalink
NEW: Initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
aljawaid committed Oct 18, 2022
1 parent 0a2f804 commit 6cc4c44
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
1 change: 0 additions & 1 deletion Action/EmailTaskHistory

This file was deleted.

112 changes: 112 additions & 0 deletions Action/EmailTaskHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Kanboard\Plugin\KanboardEmailHistory\Action;

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

class EmailTaskHistory extends Base
{

public function getDescription()
{
return t('Send full task description and comments by email');
}


public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_CLOSE,
);
}


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')),
'check_box_include_title' => t('Include Task Title and ID in subject line?'),
);
}


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


public function doAction(array $data)
{
$historySent = FALSE;
if ($this->getParam('check_box_include_title') == true ){
$subject = $this->getParam('subject') . ": " . $data['task']['title'] . "(#" . $data['task']['id'] . ")";
} else {
$subject = $this->getParam('subject');
}

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'],
$subject,
<?= $this->template->render('task_comments/show', array(
'task' => $task,
'comments' => $comments,
'project' => $project,
'editable' => false,
))
);
$this->commentModel->create( array(
'comment' => t('Task history emailed to "%s" with subject "%s".', $values['email'], $values['subject']),
'user_id' => $user,
'task_id' => $task['id'],
));
$historySent = 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'],
$subject,
<?= $this->template->render('task_comments/show', array(
'task' => $this->getTask(),
'comments' => $this->commentModel->getAll($task['id'], $commentSortingDirection),
'project' => $this->projectModel->getById($task['project_id']),
'editable' => false,
))
);
$this->commentModel->create( array(
'comment' => t('Task history emailed to "%s" with subject "%s".', $values['email'], $values['subject']),
'user_id' => $user,
'task_id' => $task['id'],
));
$historySent = TRUE;
}
}
return $historySent;
}



public function hasRequiredCondition(array $data)
{
return true;
}
}

0 comments on commit 6cc4c44

Please sign in to comment.