/** * Process notifications on modal details screen */ private function processNotificationsToBeSent() { if (array_key_exists('status', $this->originalAttributeValues)) { if ($this->status == Task::STATUS_AWAITING_ACCEPTANCE && $this->requestedByUser->id != Yii::app()->user->userModel->id) { TasksNotificationUtil::submitTaskNotificationMessage($this, TasksNotificationUtil::TASK_STATUS_BECOMES_AWAITING_ACCEPTANCE, Yii::app()->user->userModel); } elseif ($this->status == Task::STATUS_REJECTED && $this->owner->id != Yii::app()->user->userModel->id) { TasksNotificationUtil::submitTaskNotificationMessage($this, TasksNotificationUtil::TASK_STATUS_BECOMES_REJECTED, Yii::app()->user->userModel); } elseif ($this->status == Task::STATUS_COMPLETED) { TasksNotificationUtil::submitTaskNotificationMessage($this, TasksNotificationUtil::TASK_STATUS_BECOMES_COMPLETED, Yii::app()->user->userModel); } } if ($this->isNewModel) { if ($this->owner->id != $this->requestedByUser->id && $this->owner->id != Yii::app()->user->userModel->id) { TasksNotificationUtil::submitTaskNotificationMessage($this, TasksNotificationUtil::TASK_NEW); } } elseif (array_key_exists('owner', $this->originalAttributeValues) && $this->owner->id != Yii::app()->user->userModel->id) { TasksNotificationUtil::submitTaskNotificationMessage($this, TasksNotificationUtil::TASK_OWNER_CHANGE); } }
/** * Close task * @param $id * @throws NotSupportedException */ public function actionCloseTask($id) { $task = Task::getById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($task); $task->status = Task::STATUS_COMPLETED; $saved = $task->save(); if (!$saved) { throw new NotSupportedException(); } TasksNotificationUtil::submitTaskNotificationMessage($task, TasksNotificationUtil::TASK_STATUS_BECOMES_COMPLETED, Yii::app()->user->userModel); }
public function testTaskAddCommentWithExtraSubscribers() { $task = new Task(); $task->name = 'Her Task'; $task->owner = self::$sally; $task->requestedByUser = self::$katie; $notificationSubscriber = new NotificationSubscriber(); $notificationSubscriber->person = self::$steve; $notificationSubscriber->hasReadLatest = false; $task->notificationSubscribers->add($notificationSubscriber); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Notification::getCount()); $this->assertTrue($task->save()); $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(1, Notification::getCount()); EmailMessage::deleteAll(); Notification::deleteAll(); $taskId = $task->id; $task->forget(); $task = Task::getById($taskId); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Notification::getCount()); //Now add comment $comment = new Comment(); $comment->description = 'some comment'; $task->comments->add($comment); $this->assertTrue($task->save()); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Notification::getCount()); TasksNotificationUtil::submitTaskNotificationMessage($task, TasksNotificationUtil::TASK_NEW_COMMENT, self::$super, $comment); $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(3, Notification::getCount()); $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX); $this->assertCount(3, $emailMessages); $this->assertTrue('*****@*****.**' == $emailMessages[0]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[1]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[2]->recipients[0]->toAddress); $this->assertTrue('*****@*****.**' == $emailMessages[0]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[1]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[2]->recipients[0]->toAddress); $this->assertTrue('*****@*****.**' == $emailMessages[0]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[1]->recipients[0]->toAddress || '*****@*****.**' == $emailMessages[2]->recipients[0]->toAddress); }
/** * Override to handle sending email messages on new comment */ protected function afterSuccessfulSave($model) { assert('$model instanceof Item'); parent::afterSuccessfulSave($model); $user = Yii::app()->user->userModel; if ($this->relatedModel instanceof Conversation) { $participants = ConversationsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants); } elseif ($this->relatedModel instanceof Mission) { $participants = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user); CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants); } elseif ($this->relatedModel instanceof Task) { TasksNotificationUtil::submitTaskNotificationMessage($this->relatedModel, TasksNotificationUtil::TASK_NEW_COMMENT, $model->createdByUser, $model); //Log the event if ($this->relatedModel->project->id > 0) { ProjectsUtil::logAddCommentEvent($this->relatedModel, $model->description); } } }