/**
  * 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)));
     }
 }
 /**
  * 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)));
     }
 }