コード例 #1
0
 /**
  * Add demo tasks for the project
  * @param type $project
  */
 protected static function addDemoTasks($project, $taskInputCount = 1, &$demoDataHelper)
 {
     $randomTasks = self::getRandomTasks();
     for ($i = 0; $i < count($randomTasks); $i++) {
         $task = new Task();
         $task->name = $randomTasks[$i]['name'];
         $task->owner = $demoDataHelper->getRandomByModelName('User');
         $task->requestedByUser = $demoDataHelper->getRandomByModelName('User');
         $task->completedDateTime = '0000-00-00 00:00:00';
         $task->project = $project;
         $task->status = Task::STATUS_NEW;
         $task->save();
         //Notification subscriber
         $notificationSubscriber = new NotificationSubscriber();
         $notificationSubscriber->person = $demoDataHelper->getRandomByModelName('User');
         $notificationSubscriber->hasReadLatest = false;
         //Task check list items
         $task->notificationSubscribers->add($notificationSubscriber);
         $taskCheckListItems = $randomTasks[$i]['checkListItems'];
         foreach ($taskCheckListItems as $itemKey => $name) {
             $taskCheckListItem = new TaskCheckListItem();
             $taskCheckListItem->name = $name;
             if ($itemKey * $i * rand(5, 100) % 3 == 0) {
                 $taskCheckListItem->completed = true;
             }
             $task->checkListItems->add($taskCheckListItem);
             ProjectsUtil::logTaskCheckItemEvent($task, $taskCheckListItem);
         }
         //Comments
         $commentItems = $randomTasks[$i]['comments'];
         foreach ($commentItems as $description) {
             $comment = new Comment();
             $comment->description = $description;
             $comment->setScenario('importModel');
             $comment->createdByUser = $demoDataHelper->getRandomByModelName('User');
             $task->comments->add($comment);
             ProjectsUtil::logAddCommentEvent($task, strval($comment));
         }
         //Add Super user
         $comment = new Comment();
         $comment->description = 'Versatile idea regarding the task';
         $task->comments->add($comment);
         $task->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
         $task->save();
         $currentStatus = $task->status;
         ProjectsUtil::logAddTaskEvent($task);
         $task = Task::getById($task->id);
         $task->status = RandomDataUtil::getRandomValueFromArray(self::getTaskStatusOptions());
         $task->save();
         AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($task, Group::getByName(Group::EVERYONE_GROUP_NAME));
         $task->save();
         ProjectsUtil::logTaskStatusChangeEvent($task, Task::getStatusDisplayName($currentStatus), Task::getStatusDisplayName(intval($task->status)));
     }
 }
 /**
  * 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);
         }
     }
 }