Add email notifications
This commit is contained in:
76
app/Event/BaseNotificationListener.php
Normal file
76
app/Event/BaseNotificationListener.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\Notification;
|
||||
|
||||
/**
|
||||
* Base notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
abstract class BaseNotificationListener implements Listener
|
||||
{
|
||||
/**
|
||||
* Notification model
|
||||
*
|
||||
* @accesss protected
|
||||
* @var Model\Notification
|
||||
*/
|
||||
protected $notification;
|
||||
|
||||
/**
|
||||
* Template name
|
||||
*
|
||||
* @accesss private
|
||||
* @var string
|
||||
*/
|
||||
private $template = '';
|
||||
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getTemplateData(array $data);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Model\Notification $notification Notification model instance
|
||||
* @param string $template Template name
|
||||
*/
|
||||
public function __construct(Notification $notification, $template)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->notification = $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
* @return bool True if the action was executed or false when not executed
|
||||
*/
|
||||
public function execute(array $data)
|
||||
{
|
||||
$values = $this->getTemplateData($data);
|
||||
|
||||
// Get the list of users to be notified
|
||||
$users = $this->notification->getUsersList($values['task']['project_id']);
|
||||
|
||||
// Send notifications
|
||||
if ($users) {
|
||||
$this->notification->sendEmails($this->template, $users, $values);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
30
app/Event/CommentNotificationListener.php
Normal file
30
app/Event/CommentNotificationListener.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Event\BaseNotificationListener;
|
||||
|
||||
/**
|
||||
* Comment notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CommentNotificationListener extends BaseNotificationListener
|
||||
{
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(array $data)
|
||||
{
|
||||
$values = array();
|
||||
$values['comment'] = $this->notification->comment->getById($data['id']);
|
||||
$values['task'] = $this->notification->task->getById($data['task_id'], true);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
30
app/Event/FileNotificationListener.php
Normal file
30
app/Event/FileNotificationListener.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Event\BaseNotificationListener;
|
||||
|
||||
/**
|
||||
* File notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class FileNotificationListener extends BaseNotificationListener
|
||||
{
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(array $data)
|
||||
{
|
||||
$values = array();
|
||||
$values['file'] = $data;
|
||||
$values['task'] = $this->notification->task->getById($data['task_id'], true);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
30
app/Event/SubTaskNotificationListener.php
Normal file
30
app/Event/SubTaskNotificationListener.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Event\BaseNotificationListener;
|
||||
|
||||
/**
|
||||
* SubTask notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubTaskNotificationListener extends BaseNotificationListener
|
||||
{
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(array $data)
|
||||
{
|
||||
$values = array();
|
||||
$values['subtask'] = $this->notification->subtask->getById($data['id'], true);
|
||||
$values['task'] = $this->notification->task->getById($data['task_id'], true);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
29
app/Event/TaskNotificationListener.php
Normal file
29
app/Event/TaskNotificationListener.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Event\BaseNotificationListener;
|
||||
|
||||
/**
|
||||
* Task notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskNotificationListener extends BaseNotificationListener
|
||||
{
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(array $data)
|
||||
{
|
||||
$values = array();
|
||||
$values['task'] = $this->notification->task->getById($data['task_id'], true);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user