/**
  * Action for saving a new task check item inline edit form.
  * @param string or array $redirectUrl
  */
 public function actionInlineCreateTaskCheckItemSave($relatedModelId, $relatedModelClassName, $relatedModelRelationName, $redirectUrl = null)
 {
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'task-check-item-inline-edit-form') {
         $this->actionInlineEditValidate(new TaskCheckListItem());
     }
     $taskCheckListItem = new TaskCheckListItem();
     $postData = PostUtil::getData();
     $postFormData = ArrayUtil::getArrayValue($postData, get_class($taskCheckListItem));
     $taskCheckListItem->name = $postFormData['name'];
     $task = Task::getById(intval($relatedModelId));
     $task->checkListItems->add($taskCheckListItem);
     $saved = $task->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     if ($task->project->id > 0) {
         ProjectsUtil::logTaskCheckItemEvent($task, $taskCheckListItem);
     }
     if ($redirectUrl != null) {
         $this->redirect($redirectUrl);
     }
 }
 /**
  * Process status update via ajax
  * @param int $id
  * @param int $status
  * @param bool $showCompletionDate whether to show completion date
  */
 protected function processStatusUpdateViaAjax(Task $task, $status, $showCompletionDate = true)
 {
     $currentStatus = $task->status;
     $task->status = intval($status);
     //check for owner in case a user start the task
     if ($currentStatus == Task::STATUS_NEW && $currentStatus != $task->status) {
         $task->owner = Yii::app()->user->userModel;
     }
     if (intval($status) == Task::STATUS_COMPLETED) {
         foreach ($task->checkListItems as $checkItem) {
             $checkItem->completed = true;
             $checkItem->unrestrictedSave();
         }
         $task->status = Task::STATUS_COMPLETED;
         $task->completedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $task->completed = true;
         $task->save();
         if ($showCompletionDate) {
             echo TasksUtil::renderCompletionDateTime($task);
         }
     } else {
         $task->completedDateTime = null;
         $task->completed = false;
         $task->save();
     }
     if ($task->project->id > 0) {
         ProjectsUtil::logTaskStatusChangeEvent($task, Task::getStatusDisplayName(intval($currentStatus)), Task::getStatusDisplayName(intval($status)));
     }
 }
 /**
  * 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);
         }
     }
 }