summaryrefslogtreecommitdiff
path: root/plugins/Group_assign/Action
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Group_assign/Action')
-rw-r--r--plugins/Group_assign/Action/AssignGroup.php95
-rw-r--r--plugins/Group_assign/Action/EmailGroup.php80
-rw-r--r--plugins/Group_assign/Action/EmailGroupDue.php116
-rw-r--r--plugins/Group_assign/Action/EmailOtherAssignees.php80
-rw-r--r--plugins/Group_assign/Action/EmailOtherAssigneesDue.php116
5 files changed, 487 insertions, 0 deletions
diff --git a/plugins/Group_assign/Action/AssignGroup.php b/plugins/Group_assign/Action/AssignGroup.php
new file mode 100644
index 00000000..4a63696b
--- /dev/null
+++ b/plugins/Group_assign/Action/AssignGroup.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Action;
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\ProjectGroupRoleModel;
+use Kanboard\Action\Base;
+
+class AssignGroup extends Base
+{
+ /**
+ * Get automatic action description
+ *
+ * @access public
+ * @return string
+ */
+ public function getDescription()
+ {
+ return t('Assign the task to a specific group');
+ }
+
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_CREATE_UPDATE,
+ TaskModel::EVENT_MOVE_COLUMN,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'column_id' => t('Column'),
+ 'group_id' => t('Group'),
+ );
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'task' => array(
+ 'project_id',
+ 'column_id',
+ ),
+ );
+ }
+
+ /**
+ * Execute the action (assign the given user)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'owner_gp' => $this->getParam('group_id'),
+ );
+
+ return $this->taskModificationModel->update($values);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['task']['column_id'] == $this->getParam('column_id');
+ }
+}
diff --git a/plugins/Group_assign/Action/EmailGroup.php b/plugins/Group_assign/Action/EmailGroup.php
new file mode 100644
index 00000000..6d12bc73
--- /dev/null
+++ b/plugins/Group_assign/Action/EmailGroup.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Action;
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\Base;
+
+class EmailGroup extends Base
+{
+
+ public function getDescription()
+ {
+ return t('Send a task by email to assigned group members');
+ }
+
+
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_MOVE_COLUMN,
+ TaskModel::EVENT_CLOSE,
+ TaskModel::EVENT_CREATE,
+ );
+ }
+
+
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'column_id' => t('Column'),
+ 'subject' => t('Email subject'),
+ );
+ }
+
+
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'task' => array(
+ 'project_id',
+ 'column_id',
+ 'owner_id',
+ 'owner_gp',
+ ),
+ );
+ }
+
+
+ public function doAction(array $data)
+ {
+ $groupmembers = $this->groupMemberModel->getMembers($data['task']['owner_gp']);
+
+ if (! empty($groupmembers)) {
+ foreach ($groupmembers as $members) {
+ $user = $this->userModel->getById($members['id']);
+ if (! empty($user['email'])) {
+ $this->emailClient->send(
+ $user['email'],
+ $user['name'] ?: $user['username'],
+ $this->getParam('subject'),
+ $this->template->render('notification/task_create', array(
+ 'task' => $data['task'],
+ ))
+ );
+ }
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+
+
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['task']['column_id'] == $this->getParam('column_id');
+ }
+}
diff --git a/plugins/Group_assign/Action/EmailGroupDue.php b/plugins/Group_assign/Action/EmailGroupDue.php
new file mode 100644
index 00000000..8f1a66a7
--- /dev/null
+++ b/plugins/Group_assign/Action/EmailGroupDue.php
@@ -0,0 +1,116 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Action;
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\Base;
+
+/**
+ * Email a task notification of impending due date
+ */
+class EmailGroupDue extends Base
+{
+ /**
+ * Get automatic action description
+ *
+ * @access public
+ * @return string
+ */
+ public function getDescription()
+ {
+ return t('Send email notification of impending due date to Group Members Assigned');
+ }
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_DAILY_CRONJOB,
+ );
+ }
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'subject' => t('Email subject'),
+ 'duration' => t('Duration in days'),
+ );
+ }
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array('tasks');
+
+ }
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return count($data['tasks']) > 0;
+ }
+
+ public function doAction(array $data)
+ {
+ $results = array();
+ $max = $this->getParam('duration') * 86400;
+
+ foreach ($data['tasks'] as $task) {
+ $groupmembers = $this->groupMemberModel->getMembers($task['owner_gp']);
+
+ if (! empty($groupmembers)) {
+ foreach ($groupmembers as $members) {
+ $user = $this->userModel->getById($members['id']);
+
+ $duration = $task['date_due'] - time();
+ if ($task['date_due'] > 0) {
+ if ($duration < $max) {
+ if (! empty($user['email'])) {
+ $results[] = $this->sendEmail($task['id'], $user);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return in_array(true, $results, true);
+ }
+ /**
+ * Send email
+ *
+ * @access private
+ * @param integer $task_id
+ * @param array $user
+ * @return boolean
+ */
+ private function sendEmail($task_id, array $user)
+ {
+ $task = $this->taskFinderModel->getDetails($task_id);
+ $this->emailClient->send(
+ $user['email'],
+ $user['name'] ?: $user['username'],
+ $this->getParam('subject'),
+ $this->template->render('notification/task_create', array('task' => $task))
+ );
+ return true;
+ }
+}
diff --git a/plugins/Group_assign/Action/EmailOtherAssignees.php b/plugins/Group_assign/Action/EmailOtherAssignees.php
new file mode 100644
index 00000000..f9ab091c
--- /dev/null
+++ b/plugins/Group_assign/Action/EmailOtherAssignees.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Action;
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\Base;
+
+class EmailOtherAssignees extends Base
+{
+
+ public function getDescription()
+ {
+ return t('Send a task by email to the other assignees for a task.');
+ }
+
+
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_MOVE_COLUMN,
+ TaskModel::EVENT_CLOSE,
+ TaskModel::EVENT_CREATE,
+ );
+ }
+
+
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'column_id' => t('Column'),
+ 'subject' => t('Email subject'),
+ );
+ }
+
+
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'task' => array(
+ 'project_id',
+ 'column_id',
+ 'owner_id',
+ 'owner_ms',
+ ),
+ );
+ }
+
+
+ public function doAction(array $data)
+ {
+ $multimembers = $this->multiselectMemberModel->getMembers($data['task']['owner_ms']);
+
+ if (! empty($multimembers)) {
+ foreach ($multimembers as $members) {
+ $user = $this->userModel->getById($members['id']);
+ if (! empty($user['email'])) {
+ $this->emailClient->send(
+ $user['email'],
+ $user['name'] ?: $user['username'],
+ $this->getParam('subject'),
+ $this->template->render('notification/task_create', array(
+ 'task' => $data['task'],
+ ))
+ );
+ }
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+
+
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['task']['column_id'] == $this->getParam('column_id');
+ }
+}
diff --git a/plugins/Group_assign/Action/EmailOtherAssigneesDue.php b/plugins/Group_assign/Action/EmailOtherAssigneesDue.php
new file mode 100644
index 00000000..abd15003
--- /dev/null
+++ b/plugins/Group_assign/Action/EmailOtherAssigneesDue.php
@@ -0,0 +1,116 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Action;
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\Base;
+
+/**
+ * Email a task notification of impending due date
+ */
+class EmailOtherAssigneesDue extends Base
+{
+ /**
+ * Get automatic action description
+ *
+ * @access public
+ * @return string
+ */
+ public function getDescription()
+ {
+ return t('Send email notification of impending due date to the other assignees of a task');
+ }
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskModel::EVENT_DAILY_CRONJOB,
+ );
+ }
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'subject' => t('Email subject'),
+ 'duration' => t('Duration in days'),
+ );
+ }
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array('tasks');
+
+ }
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return count($data['tasks']) > 0;
+ }
+
+ public function doAction(array $data)
+ {
+ $results = array();
+ $max = $this->getParam('duration') * 86400;
+
+ foreach ($data['tasks'] as $task) {
+ $groupmembers = $this->multiselectMemberModel->getMembers($task['owner_ms']);
+
+ if (! empty($groupmembers)) {
+ foreach ($groupmembers as $members) {
+ $user = $this->userModel->getById($members['id']);
+
+ $duration = $task['date_due'] - time();
+ if ($task['date_due'] > 0) {
+ if ($duration < $max) {
+ if (! empty($user['email'])) {
+ $results[] = $this->sendEmail($task['id'], $user);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return in_array(true, $results, true);
+ }
+ /**
+ * Send email
+ *
+ * @access private
+ * @param integer $task_id
+ * @param array $user
+ * @return boolean
+ */
+ private function sendEmail($task_id, array $user)
+ {
+ $task = $this->taskFinderModel->getDetails($task_id);
+ $this->emailClient->send(
+ $user['email'],
+ $user['name'] ?: $user['username'],
+ $this->getParam('subject'),
+ $this->template->render('notification/task_create', array('task' => $task))
+ );
+ return true;
+ }
+}