/** * * * @param ContentDataObject $object * @param $additional_attributes array * @param $go_deep bool copy all subtasks or if is a milestone copy all tasks * @return int Template Object id */ function addObject($object, $additional_attributes = array(), $go_deep = true) { //if ($this->hasObject($object)) return; //if object is a ProjectTask if ($object instanceof ProjectTask) { if ($go_deep) { $object = TemplateTask::copyFromProjectTaskIncludeSubTasks($object, $this->getId()); } else { $object = TemplateTask::copyFromProjectTask($object, $this->getId()); } //if object is a ProjectMilestone } else { if ($object instanceof ProjectMilestone) { $object = TemplateMilestone::copyFromProjectMilestone($object, $this->getId(), $go_deep); //if object is a TemplateTask } else { if ($object instanceof TemplateTask) { $object->setColumnValue('template_id', $this->getId()); $object->setColumnValue('session_id', null); if (isset($additional_attributes['milestone'])) { $object->setMilestoneId($additional_attributes['milestone']); } $object->save(); //if object is a TemplateMilestone } else { if ($object instanceof TemplateMilestone) { $object->setColumnValue('template_id', $this->getId()); $object->setColumnValue('session_id', null); $object->save(); } } } } // the object is already a template or can't be one, use it as it is $template = $object; //create a TemplateObject $to = new TemplateObject(); $to->setObject($template); $to->setTemplate($this); $to->save(); return $template->getObjectId(); }
/** * Copy a project task to a template task and all subtasks (go deep) * * @access public * @param $project_task ProjectTask project task * @param $template_id int the template id * @param $parent_id int the parent id if is a subtask * @return TemplateTask */ function copyFromProjectTaskIncludeSubTasks($project_task, $template_id, $parent_id = 0, $milestone_id = 0) { //Copy task $tmp_task = TemplateTask::copyFromProjectTask($project_task, $template_id, $parent_id, $milestone_id); // Copy Subtasks $tmp_sub_tasks = $project_task->getSubTasks(false, false); foreach ($tmp_sub_tasks as $c) { if ($c instanceof ProjectTask) { $sub = TemplateTask::copyFromProjectTaskIncludeSubTasks($c, $template_id, $tmp_task->getId(), $milestone_id); //create a TemplateObject $to = new TemplateObject(); $to->setObject($sub); $to->setTemplateId($template_id); $to->save(); } } return $tmp_task; }