summaryrefslogtreecommitdiff
path: root/app/Controller/CommentMailController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller/CommentMailController.php')
-rw-r--r--app/Controller/CommentMailController.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Controller/CommentMailController.php b/app/Controller/CommentMailController.php
new file mode 100644
index 00000000..e30d6a55
--- /dev/null
+++ b/app/Controller/CommentMailController.php
@@ -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;
+ }
+}