/**
  * Add task to this list
  *
  * @param string $text
  * @param User $assigned_to_user
  * @param Company $assigned_to_company
  * @return ProjectTask
  * @throws DAOValidationError
  */
 function addTask($text, $assigned_to_user = null, $assigned_to_company = null)
 {
     $task = new ProjectTask();
     $task->setText($text);
     if ($assigned_to_user instanceof User) {
         $task->setAssignedToUserId($assigned_to_user->getId());
         $task->setAssignedToCompanyId($assigned_to_user->getCompanyId());
     } elseif ($assigned_to_company instanceof Company) {
         $task->setAssignedToCompanyId($assigned_to_company->getId());
     }
     // if
     $this->attachTask($task);
     // this one will save task
     return $task;
 }
 /**
  * Copy task list then redirect to edit
  *
  * @access public
  * @param void
  * @return null
  */
 function copy_list()
 {
     $task_list = ProjectTaskLists::findById(get_id());
     if (!$task_list instanceof ProjectTaskList) {
         flash_error(lang('task list dnx'));
         $this->redirectTo('task', 'index');
     }
     // if
     if (!$task_list->canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('task', 'index');
     }
     // if
     try {
         DB::beginWork();
         $source_task_list = $task_list;
         $task_list = new ProjectTaskList();
         $task_list->setName($source_task_list->getName() . ' (' . lang('copy') . ')');
         $task_list->setPriority($source_task_list->getPriority());
         $task_list->setDescription($source_task_list->getDescription());
         $task_list->setMilestoneId($source_task_list->getMilestoneId());
         $task_list->setDueDate($source_task_list->getDueDate());
         $task_list->setIsPrivate($source_task_list->getIsPrivate());
         $task_list->setOrder($source_task_list->getOrder());
         $task_list->setProjectId($source_task_list->getProjectId());
         $task_list->save();
         $task_count = 0;
         $source_tasks = $source_task_list->getTasks();
         if (is_array($source_tasks)) {
             foreach ($source_tasks as $source_task) {
                 $task = new ProjectTask();
                 $task->setText($source_task->getText());
                 $task->setAssignedToUserId($source_task->getAssignedToUserId());
                 $task->setAssignedToCompanyId($source_task->getAssignedToCompanyId());
                 $task->setOrder($source_task->getOrder());
                 $task->setDueDate($source_task->getDueDate());
                 $task_list->attachTask($task);
                 $task_count++;
             }
         }
         ApplicationLogs::createLog($task_list, active_project(), ApplicationLogs::ACTION_ADD);
         DB::commit();
         flash_success(lang('success copy task list', $source_task_list->getName(), $task_list->getName(), $task_count));
         //$this->redirectToUrl($task_list->getEditUrl());
         $this->redirectTo('task', 'index');
     } catch (Exception $e) {
         DB::rollback();
         tpl_assign('error', $e);
     }
     // try
 }
 /**
  * Returns an unsaved copy of the task. Copies everything except open/closed state,
  * anything that needs the task to have an id (like tags, properties, subtask),
  * administrative info like who created the task and when, etc.
  *
  * @param ProjectTask $task
  * @return ProjectTask
  */
 function createTaskCopy(ProjectTask $task)
 {
     $new = new ProjectTask();
     $new->setMilestoneId($task->getMilestoneId());
     $new->setParentId($task->getParentId());
     $new->setTitle($task->getTitle());
     $new->setAssignedToCompanyId($task->getAssignedToCompanyId());
     $new->setAssignedToUserId($task->getAssignedToUserId());
     $new->setPriority($task->getPriority());
     $new->setTimeEstimate($task->getTimeEstimate());
     $new->setText($task->getText());
     $new->setIsPrivate($task->getIsPrivate());
     $new->setOrder(ProjectTasks::maxOrder($new->getParentId(), $new->getMilestoneId()));
     $new->setStartDate($task->getStartDate());
     $new->setDueDate($task->getDueDate());
     return $new;
 }