Project activity refactoring and listeners improvements
This commit is contained in:
79
app/Event/Base.php
Normal file
79
app/Event/Base.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Core\Registry;
|
||||
use Core\Tool;
|
||||
|
||||
/**
|
||||
* Base Listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*
|
||||
* @property \Model\Comment $comment
|
||||
* @property \Model\Project $project
|
||||
* @property \Model\ProjectActivity $projectActivity
|
||||
* @property \Model\SubTask $subTask
|
||||
* @property \Model\Task $task
|
||||
* @property \Model\TaskFinder $taskFinder
|
||||
*/
|
||||
abstract class Base implements Listener
|
||||
{
|
||||
/**
|
||||
* Registry instance
|
||||
*
|
||||
* @access protected
|
||||
* @var \Core\Registry
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Core\Registry $registry Regsitry instance
|
||||
*/
|
||||
public function __construct(Registry $registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load automatically models
|
||||
*
|
||||
* @access public
|
||||
* @param string $name Model name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return Tool::loadModel($this->registry, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event namespace
|
||||
*
|
||||
* Event = task.close | Namespace = task
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getEventNamespace()
|
||||
{
|
||||
$event_name = $this->registry->event->getLastTriggeredEvent();
|
||||
return substr($event_name, 0, strpos($event_name, '.'));
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\CommentHistory;
|
||||
|
||||
/**
|
||||
* Comment history listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CommentHistoryListener implements Listener
|
||||
{
|
||||
/**
|
||||
* Comment History model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\CommentHistory
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Model\CommentHistory $model Comment History model instance
|
||||
*/
|
||||
public function __construct(CommentHistory $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$creator_id = $this->model->acl->getUserId();
|
||||
|
||||
if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
|
||||
|
||||
$task = $this->model->taskFinder->getById($data['task_id']);
|
||||
|
||||
$this->model->create(
|
||||
$task['project_id'],
|
||||
$data['task_id'],
|
||||
$data['id'],
|
||||
$creator_id,
|
||||
$this->model->event->getLastTriggeredEvent(),
|
||||
$data['comment']
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?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->taskFinder->getDetails($values['comment']['task_id']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?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->taskFinder->getDetails($data['task_id']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
83
app/Event/NotificationListener.php
Normal file
83
app/Event/NotificationListener.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
/**
|
||||
* Notification listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class NotificationListener extends Base
|
||||
{
|
||||
/**
|
||||
* Template name
|
||||
*
|
||||
* @accesss private
|
||||
* @var string
|
||||
*/
|
||||
private $template = '';
|
||||
|
||||
/**
|
||||
* Set template name
|
||||
*
|
||||
* @access public
|
||||
* @param string $template Template name
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$users = $this->notification->getUsersList($values['task']['project_id']);
|
||||
|
||||
if ($users) {
|
||||
$this->notification->sendEmails($this->template, $users, $values);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data for the mail template
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateData(array $data)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
switch ($this->getEventNamespace()) {
|
||||
case 'task':
|
||||
$values['task'] = $this->taskFinder->getDetails($data['task_id']);
|
||||
break;
|
||||
case 'subtask':
|
||||
$values['subtask'] = $this->subtask->getById($data['id'], true);
|
||||
$values['task'] = $this->taskFinder->getDetails($data['task_id']);
|
||||
break;
|
||||
case 'file':
|
||||
$values['file'] = $data;
|
||||
$values['task'] = $this->taskFinder->getDetails($data['task_id']);
|
||||
break;
|
||||
case 'comment':
|
||||
$values['comment'] = $this->comment->getById($data['id']);
|
||||
$values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']);
|
||||
break;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
61
app/Event/ProjectActivityListener.php
Normal file
61
app/Event/ProjectActivityListener.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
/**
|
||||
* Project activity listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectActivityListener extends Base
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (isset($data['task_id'])) {
|
||||
|
||||
$values = $this->getValues($data);
|
||||
|
||||
return $this->projectActivity->createEvent(
|
||||
$values['task']['project_id'],
|
||||
$values['task']['id'],
|
||||
$this->acl->getUserId(),
|
||||
$this->registry->event->getLastTriggeredEvent(),
|
||||
$values
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event activity data
|
||||
*
|
||||
* @access private
|
||||
* @param array $data Event data dictionary
|
||||
* @return array
|
||||
*/
|
||||
private function getValues(array $data)
|
||||
{
|
||||
$values = array();
|
||||
$values['task'] = $this->taskFinder->getDetails($data['task_id']);
|
||||
|
||||
switch ($this->getEventNamespace()) {
|
||||
case 'subtask':
|
||||
$values['subtask'] = $this->subTask->getById($data['id'], true);
|
||||
break;
|
||||
case 'comment':
|
||||
$values['comment'] = $this->comment->getById($data['id']);
|
||||
break;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\Project;
|
||||
|
||||
/**
|
||||
* Project modification date listener
|
||||
*
|
||||
* Update the last modified field for a project
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectModificationDate implements Listener
|
||||
{
|
||||
/**
|
||||
* Project model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Project
|
||||
*/
|
||||
private $project;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Model\Project $project Project model instance
|
||||
*/
|
||||
public function __construct(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (isset($data['project_id'])) {
|
||||
return $this->project->updateModificationDate($data['project_id']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
30
app/Event/ProjectModificationDateListener.php
Normal file
30
app/Event/ProjectModificationDateListener.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
/**
|
||||
* Project modification date listener
|
||||
*
|
||||
* Update the "last_modified" field for a project
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectModificationDateListener extends Base
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (isset($data['project_id'])) {
|
||||
return $this->project->updateModificationDate($data['project_id']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?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->taskFinder->getDetails($data['task_id']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\SubtaskHistory;
|
||||
|
||||
/**
|
||||
* Subtask history listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubtaskHistoryListener implements Listener
|
||||
{
|
||||
/**
|
||||
* Comment History model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\SubtaskHistory
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Model\SubtaskHistory $model Subtask History model instance
|
||||
*/
|
||||
public function __construct(SubtaskHistory $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$creator_id = $this->model->acl->getUserId();
|
||||
|
||||
if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
|
||||
|
||||
$task = $this->model->taskFinder->getById($data['task_id']);
|
||||
|
||||
$this->model->create(
|
||||
$task['project_id'],
|
||||
$data['task_id'],
|
||||
$data['id'],
|
||||
$creator_id,
|
||||
$this->model->event->getLastTriggeredEvent(),
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\TaskHistory;
|
||||
|
||||
/**
|
||||
* Task history listener
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskHistoryListener implements Listener
|
||||
{
|
||||
/**
|
||||
* Task History model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\TaskHistory
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Model\TaskHistory $model Task History model instance
|
||||
*/
|
||||
public function __construct(TaskHistory $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$creator_id = $this->model->acl->getUserId();
|
||||
|
||||
if ($creator_id && isset($data['task_id']) && isset($data['project_id'])) {
|
||||
$this->model->create($data['project_id'], $data['task_id'], $creator_id, $this->model->event->getLastTriggeredEvent());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?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->taskFinder->getDetails($data['task_id']);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,14 @@
|
||||
|
||||
namespace Event;
|
||||
|
||||
use Core\Listener;
|
||||
use Model\Webhook;
|
||||
|
||||
/**
|
||||
* Webhook task events
|
||||
*
|
||||
* @package event
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class WebhookListener implements Listener
|
||||
class WebhookListener extends Base
|
||||
{
|
||||
/**
|
||||
* Webhook model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Webhook
|
||||
*/
|
||||
private $webhook;
|
||||
|
||||
/**
|
||||
* Url to call
|
||||
*
|
||||
@@ -30,27 +19,14 @@ class WebhookListener implements Listener
|
||||
private $url = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Set webhook url
|
||||
*
|
||||
* @access public
|
||||
* @param string $url URL to call
|
||||
* @param \Model\Webhook $webhook Webhook model instance
|
||||
* @param string $url URL to call
|
||||
*/
|
||||
public function __construct($url, Webhook $webhook)
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->webhook = $webhook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user