Send comments by email
This commit is contained in:
74
app/Controller/CommentMailController.php
Normal file
74
app/Controller/CommentMailController.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Class CommentMailController
|
||||
*
|
||||
* @package Kanboard\Controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CommentMailController extends BaseController
|
||||
{
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$task = $this->getTask();
|
||||
|
||||
$this->response->html($this->helper->layout->task('comment_mail/create', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'task' => $task,
|
||||
'project' => $project,
|
||||
)));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$values = $this->request->getValues();
|
||||
$values['task_id'] = $task['id'];
|
||||
$values['user_id'] = $this->userSession->getId();
|
||||
|
||||
list($valid, $errors) = $this->commentValidator->validateEmailCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
$this->sendByEmail($values);
|
||||
$values = $this->prepareComment($values);
|
||||
|
||||
if ($this->commentModel->create($values) !== false) {
|
||||
$this->flash->success(t('Comment sent by email successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to create your comment.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true);
|
||||
} else {
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
}
|
||||
|
||||
protected function sendByEmail(array $values)
|
||||
{
|
||||
$html = $this->template->render('comment_mail/email', array(
|
||||
'email' => $values,
|
||||
));
|
||||
|
||||
$this->emailClient->send(
|
||||
$values['email'],
|
||||
$values['email'],
|
||||
$values['subject'],
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
protected function prepareComment(array $values)
|
||||
{
|
||||
$values['comment'] .= "\n\n_".t('Sent by email to [%s](mailto:%s) (%s)', $values['email'], $values['email'], $values['subject']).'_';
|
||||
|
||||
unset($values['subject']);
|
||||
unset($values['email']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Dodaj',
|
||||
'Replace' => 'Zamijeni',
|
||||
'Import' => 'Uvoz',
|
||||
'change sorting' => 'Promijeni sortiranje',
|
||||
'Change sorting' => 'Promijeni sortiranje',
|
||||
'Tasks Importation' => 'Uvoz zadataka',
|
||||
'Delimiter' => 'Djelilac',
|
||||
'Enclosure' => 'Prilog',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Anhängen',
|
||||
'Replace' => 'Ersetzen',
|
||||
'Import' => 'Import',
|
||||
'change sorting' => 'Sortierung ändern',
|
||||
'Change sorting' => 'Sortierung ändern',
|
||||
'Tasks Importation' => 'Aufgaben Import',
|
||||
'Delimiter' => 'Trennzeichen',
|
||||
'Enclosure' => 'Textbegrenzer',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Προσθήκη',
|
||||
'Replace' => 'Αντικατάσταση',
|
||||
'Import' => 'Εισαγωγή',
|
||||
'change sorting' => 'Αλλαγή ταξινόμησης',
|
||||
'Change sorting' => 'Αλλαγή ταξινόμησης',
|
||||
'Tasks Importation' => 'Εισαγωγή εργασιών',
|
||||
'Delimiter' => 'Delimiter',
|
||||
'Enclosure' => 'Enclosure',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Añadir',
|
||||
'Replace' => 'Reemplazar',
|
||||
'Import' => 'Importar',
|
||||
'change sorting' => 'Cambiar orden',
|
||||
'Change sorting' => 'Cambiar orden',
|
||||
'Tasks Importation' => 'Importación de tareas',
|
||||
'Delimiter' => 'Delimitador',
|
||||
'Enclosure' => 'Recinto',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Ajouter',
|
||||
'Replace' => 'Remplaçer',
|
||||
'Import' => 'Importation',
|
||||
'change sorting' => 'changer l\'ordre',
|
||||
'Change sorting' => 'changer l\'ordre',
|
||||
'Tasks Importation' => 'Importation des tâches',
|
||||
'Delimiter' => 'Délimiteur',
|
||||
'Enclosure' => 'Caractère d\'encadrement',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Hozzáfűz',
|
||||
'Replace' => 'Helyettesít',
|
||||
'Import' => 'Importál',
|
||||
'change sorting' => 'rendezési sorrend megváltoztatása',
|
||||
'Change sorting' => 'rendezési sorrend megváltoztatása',
|
||||
'Tasks Importation' => 'Feladat importálás',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Tambahkan',
|
||||
'Replace' => 'Ganti',
|
||||
'Import' => 'Impor',
|
||||
'change sorting' => 'ubah pengurutan',
|
||||
'Change sorting' => 'ubah pengurutan',
|
||||
'Tasks Importation' => 'Importasi Tugas',
|
||||
'Delimiter' => 'Pembatas',
|
||||
'Enclosure' => 'Lampiran',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Aggiungi',
|
||||
'Replace' => 'Sostituisci',
|
||||
'Import' => 'Importa',
|
||||
'change sorting' => 'cambia ordinamento',
|
||||
'Change sorting' => 'cambia ordinamento',
|
||||
'Tasks Importation' => 'Importazione task',
|
||||
'Delimiter' => 'Delimitatore',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => '추가',
|
||||
'Replace' => '변경',
|
||||
'Import' => '가져오기',
|
||||
'change sorting' => '정렬 변경',
|
||||
'Change sorting' => '정렬 변경',
|
||||
'Tasks Importation' => '할일 가져오기',
|
||||
'Delimiter' => '구분자',
|
||||
'Enclosure' => '동봉',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Dołącz',
|
||||
'Replace' => 'Zastąp',
|
||||
'Import' => 'Importuj',
|
||||
'change sorting' => 'odwróć sortowanie',
|
||||
'Change sorting' => 'odwróć sortowanie',
|
||||
'Tasks Importation' => 'Import zadań',
|
||||
'Delimiter' => 'Separator pola',
|
||||
'Enclosure' => 'Separator tekstu',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Adicionar',
|
||||
'Replace' => 'Substituir',
|
||||
'Import' => 'Importar',
|
||||
'change sorting' => 'alterar ordenação',
|
||||
'Change sorting' => 'alterar ordenação',
|
||||
'Tasks Importation' => 'Importação de Tarefas',
|
||||
'Delimiter' => 'Separador',
|
||||
'Enclosure' => 'Delimitador de campos',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Acrescentar',
|
||||
'Replace' => 'Substituir',
|
||||
'Import' => 'Importar',
|
||||
'change sorting' => 'alterar ordernação',
|
||||
'Change sorting' => 'alterar ordernação',
|
||||
'Tasks Importation' => 'Importação de Tarefas',
|
||||
'Delimiter' => 'Delimitador',
|
||||
'Enclosure' => 'Clausura',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Добавление',
|
||||
'Replace' => 'Замена',
|
||||
'Import' => 'Импорт',
|
||||
'change sorting' => 'изменить сортировку',
|
||||
'Change sorting' => 'изменить сортировку',
|
||||
'Tasks Importation' => 'Импортирование задач',
|
||||
'Delimiter' => 'Разделитель',
|
||||
'Enclosure' => 'Тип кавычек',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
// 'Append' => '',
|
||||
// 'Replace' => '',
|
||||
// 'Import' => '',
|
||||
// 'change sorting' => '',
|
||||
// 'Change sorting' => '',
|
||||
// 'Tasks Importation' => '',
|
||||
// 'Delimiter' => '',
|
||||
// 'Enclosure' => '',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'เพิ่มเติม',
|
||||
'Replace' => 'แทนที่',
|
||||
'Import' => 'นำเข้า',
|
||||
'change sorting' => 'เปลี่ยนการเรียง',
|
||||
'Change sorting' => 'เปลี่ยนการเรียง',
|
||||
'Tasks Importation' => 'การนำเข้างาน',
|
||||
'Delimiter' => 'คั่น',
|
||||
'Enclosure' => 'กำหนดข้อความ',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => 'Ekle',
|
||||
'Replace' => 'Üzerine yaz',
|
||||
'Import' => 'İçeri aktar',
|
||||
'change sorting' => 'sıralamayı değiştir',
|
||||
'Change sorting' => 'sıralamayı değiştir',
|
||||
'Tasks Importation' => 'Görevleri içeri aktar',
|
||||
'Delimiter' => 'Ayırıcı',
|
||||
'Enclosure' => 'Enclosure',
|
||||
|
||||
@@ -844,7 +844,7 @@ return array(
|
||||
'Append' => '追加',
|
||||
'Replace' => '替换',
|
||||
'Import' => '导入',
|
||||
'change sorting' => '改变排序',
|
||||
'Change sorting' => '改变排序',
|
||||
'Tasks Importation' => '任务重要性',
|
||||
'Delimiter' => '分隔符',
|
||||
'Enclosure' => '附件',
|
||||
|
||||
@@ -8,26 +8,28 @@
|
||||
<?php endif ?>
|
||||
|
||||
<small class="comment-date"><?= t('Created at:') ?> <?= $this->dt->datetime($comment['date_creation']) ?></small>
|
||||
<small class="comment-date"><?= t('Updated at:')?> <?= $this->dt->datetime($comment['date_modification']) ?></small>
|
||||
<small class="comment-date"><?= t('Updated at:') ?> <?= $this->dt->datetime($comment['date_modification']) ?></small>
|
||||
</div>
|
||||
|
||||
<?php if (! isset($hide_actions)): ?>
|
||||
<div class="comment-actions">
|
||||
<div class="comment-actions">
|
||||
<div class="dropdown">
|
||||
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog"></i><i class="fa fa-caret-down"></i></a>
|
||||
<ul>
|
||||
<li>
|
||||
<i class="fa fa-link fa-fw"></i>
|
||||
<a href="#comment-<?= $comment['id'] ?>"><?= t('link') ?></a>
|
||||
<?= $this->url->icon('link', t('Link'), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', '', $this->app->isAjax(), 'comment-'.$comment['id']) ?>
|
||||
</li>
|
||||
<?php if ($editable && ($this->user->isAdmin() || $this->user->isCurrentUser($comment['user_id']))): ?>
|
||||
<li>
|
||||
<?= $this->modal->medium('edit', t('edit'), 'CommentController', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
|
||||
<?= $this->modal->medium('edit', t('Edit'), 'CommentController', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
|
||||
</li>
|
||||
<li>
|
||||
<?= $this->modal->confirm('trash-o', t('remove'), 'CommentController', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
|
||||
<?= $this->modal->confirm('trash-o', t('Remove'), 'CommentController', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="comment-content">
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<div class="page-header">
|
||||
<h2><?= $this->text->e($task['title']) ?> > <?= t('Comments') ?></h2>
|
||||
<h2><?= $this->text->e($task['title']) ?></h2>
|
||||
<?php if (!isset($is_public) || !$is_public): ?>
|
||||
<div class="comment-sorting">
|
||||
<small>
|
||||
<?= $this->url->icon('sort', t('change sorting'), 'CommentListController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'js-modal-replace') ?>
|
||||
</small>
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
<?= $this->url->icon('sort', t('Change sorting'), 'CommentListController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'js-modal-replace') ?>
|
||||
</li>
|
||||
<?php if ($editable): ?>
|
||||
<li>
|
||||
<?= $this->modal->medium('paper-plane', t('Send by email'), 'CommentMailController', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="comments">
|
||||
<?php foreach ($comments as $comment): ?>
|
||||
<?= $this->render('comment/show', array(
|
||||
'comment' => $comment,
|
||||
'task' => $task,
|
||||
'project' => $project,
|
||||
'editable' => $editable,
|
||||
'comment' => $comment,
|
||||
'task' => $task,
|
||||
'project' => $project,
|
||||
'editable' => $editable,
|
||||
'is_public' => isset($is_public) && $is_public,
|
||||
)) ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
21
app/Template/comment_mail/create.php
Normal file
21
app/Template/comment_mail/create.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<div class="page-header">
|
||||
<h2><?= t('Create and send comment by email') ?></h2>
|
||||
</div>
|
||||
<form method="post" action="<?= $this->url->href('CommentMailController', 'save', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>" autocomplete="off">
|
||||
<?= $this->form->csrf() ?>
|
||||
<?= $this->form->hidden('task_id', $values) ?>
|
||||
<?= $this->form->hidden('user_id', $values) ?>
|
||||
|
||||
<?= $this->form->label(t('Email'), 'email') ?>
|
||||
<?= $this->form->email('email', $values, $errors, array('autofocus', 'required', 'tabindex="1"')) ?>
|
||||
|
||||
<?= $this->form->label(t('Subject'), 'subject') ?>
|
||||
<?= $this->form->text('subject', $values, $errors, array('required', 'tabindex="2"')) ?>
|
||||
|
||||
<?= $this->form->textEditor('comment', $values, $errors, array('required' => true, 'tabindex' => 3)) ?>
|
||||
|
||||
<?= $this->modal->submitButtons(array(
|
||||
'submitLabel' => t('Send by email'),
|
||||
'tabindex' => 4,
|
||||
)) ?>
|
||||
</form>
|
||||
1
app/Template/comment_mail/email.php
Normal file
1
app/Template/comment_mail/email.php
Normal file
@@ -0,0 +1 @@
|
||||
<?= $this->text->markdown($email['comment'], true) ?>
|
||||
@@ -6,25 +6,28 @@
|
||||
<?php if (!isset($is_public) || !$is_public): ?>
|
||||
<div class="comment-sorting">
|
||||
<small>
|
||||
<?= $this->url->icon('sort', t('change sorting'), 'CommentController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
|
||||
<?= $this->url->icon('sort', t('Change sorting'), 'CommentController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
|
||||
<?php if ($editable): ?>
|
||||
<?= $this->modal->medium('paper-plane', t('Send by email'), 'CommentMailController', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
|
||||
<?php endif ?>
|
||||
</small>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php foreach ($comments as $comment): ?>
|
||||
<?= $this->render('comment/show', array(
|
||||
'comment' => $comment,
|
||||
'task' => $task,
|
||||
'project' => $project,
|
||||
'editable' => $editable,
|
||||
'comment' => $comment,
|
||||
'task' => $task,
|
||||
'project' => $project,
|
||||
'editable' => $editable,
|
||||
'is_public' => isset($is_public) && $is_public,
|
||||
)) ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php if ($editable): ?>
|
||||
<?= $this->render('task_comments/create', array(
|
||||
'values' => array(),
|
||||
'errors' => array(),
|
||||
'task' => $task,
|
||||
'values' => array(),
|
||||
'errors' => array(),
|
||||
'task' => $task,
|
||||
)) ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,31 @@ use SimpleValidator\Validators;
|
||||
*/
|
||||
class CommentValidator extends BaseValidator
|
||||
{
|
||||
/**
|
||||
* Validate comment email creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Required parameters to save an action
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateEmailCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
new Validators\Required('user_id', t('This value is required')),
|
||||
new Validators\Required('subject', t('This field is required')),
|
||||
new Validators\Required('email', t('This field is required')),
|
||||
new Validators\Email('email', t('Email address invalid')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate comment creation
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user