public function task_completed() { try { $taskId = (int) $_POST['objectId']; $task = $this->teamwork->task($taskId)->find(); $completerFirstName = $task['todo-item']['completer_firstname']; $projectName = $task['todo-item']['project-name']; // $taskListName = $task['todo-item']['todo-list-name']; // $taskName = $task['todo-item']['content']; $taskURL = TEAMWORK_URL . "/tasks/{$taskId}"; $taskTitle = ":ballot_box_with_check: {$taskName}"; $completerId = (int) $task['todo-item']['completer_id']; $completer = $this->teamwork->people($completerId)->find(); $completerIcon = $completer['person']['avatar-url']; $taskDescription = array('fallback' => "✔ {$taskName}", "title" => $taskTitle, "title_link" => $taskURL, 'color' => 'good', 'mrkdwn_in' => array('text', 'pretext', 'fields')); $taskDescription['fields'] = array(array('title' => 'Project', 'value' => $projectName, 'short' => true), array('title' => 'Task list', 'value' => $taskListName, 'short' => true)); $notification = new SlackNotification(); $notification->username = $completerFirstName; $notification->room = SLACK_CHANNEL; $notification->title = $taskName; $notification->attachments = $taskDescription; $notification->icon = $completerIcon; $notification->link = $taskURL; $notification->send(); } catch (Exception $e) { error_log(var_export($e, 1)); } }
public function task_reminder() { try { $taskId = (int) $_POST['objectId']; $task = $this->teamwork->task($taskId)->find(); $creatorFirstName = $task['todo-item']['creator-firstname']; $creatorLastName = $task['todo-item']['creator-lastname']; $projectName = $task['todo-item']['project-name']; $roomName = "tw-" . strtolower(str_replace(" ", "-", $projectName)); $taskListName = $task['todo-item']['todo-list-name']; $taskName = $task['todo-item']['content']; $taskURL = TEAMWORK_URL . "/tasks/{$taskId}"; $taskTitle = ":alarm_clock: Task reminder: {$taskName}"; $creatorId = (int) $task['todo-item']['creator-id']; $creator = $this->teamwork->people($creatorId)->find(); $creatorIcon = $creator['person']['avatar-url']; $taskDescription = array('fallback' => "Task reminder: {$taskName}", "title" => $taskTitle, "title_link" => $taskURL, 'color' => 'good', 'mrkdwn_in' => array('text', 'pretext', 'fields')); $taskDescription['fields'] = array(array('title' => 'Task list', 'value' => $taskListName, 'short' => true)); $notification = new SlackNotification(); $notification->username = "******"; $notification->room = $roomName; $notification->title = $taskName; $notification->attachments = $taskDescription; $notification->icon = $creatorIcon; $notification->link = $taskURL; $notification->send(); } catch (Exception $e) { error_log(var_export($e, 1)); } }