Ejemplo n.º 1
0
 /**
  * 
  * 
  * @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();
 }
Ejemplo n.º 2
0
 function addObject($object)
 {
     if ($this->hasObject($object)) {
         return;
     }
     if (!$object->isTemplate() && $object->canBeTemplate()) {
         // the object isn't a template but can be, create a template copy
         $copy = $object->copy();
         $copy->setColumnValue('is_template', true);
         if ($copy instanceof ProjectTask) {
             // don't copy milestone and parent task
             $copy->setMilestoneId(0);
             $copy->setParentId(0);
         }
         $copy->save();
         // copy subtasks
         if ($copy instanceof ProjectTask) {
             ProjectTasks::copySubTasks($object, $copy, true);
         } else {
             if ($copy instanceof ProjectMilestone) {
                 ProjectMilestones::copyTasks($object, $copy, true);
             }
         }
         // copy tags
         $tags = implode(',', $object->getTagNames());
         $copy->setTagsFromCSV($tags);
         // copy custom properties
         $copy->copyCustomPropertiesFrom($object);
         // copy linked objects
         $linked_objects = $object->getAllLinkedObjects();
         if (is_array($linked_objects)) {
             foreach ($linked_objects as $lo) {
                 $copy->linkObject($lo);
             }
         }
         // copy reminders
         $reminders = ObjectReminders::getByObject($object);
         foreach ($reminders as $reminder) {
             $copy_reminder = new ObjectReminder();
             $copy_reminder->setContext($reminder->getContext());
             $copy_reminder->setDate(EMPTY_DATETIME);
             $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
             $copy_reminder->setObject($copy);
             $copy_reminder->setType($reminder->getType());
             $copy_reminder->setUserId($reminder->getUserId());
             $copy_reminder->save();
         }
         $template = $copy;
     } else {
         // the object is already a template or can't be one, use it as it is
         $template = $object;
     }
     $to = new TemplateObject();
     $to->setObject($template);
     $to->setTemplate($this);
     $to->save();
     return $template->getId();
 }
Ejemplo n.º 3
0
	/**
	 * 
	 * 
	 * @param ProjectTask $object
	 */
	function addObject($object, $additional_attributes = array()) {
		if ($this->hasObject($object)) return;
		if (!$object->isTemplate() && $object->canBeTemplate()) {
			// the object isn't a template but can be, create a template copy
			$copy = $object->copy();
			
			$copy->setColumnValue('is_template', true);
			if ($copy instanceof ProjectTask) {
				// don't copy milestone and parent task
				$copy->setMilestoneId(0);
				$copy->setParentId(0);
				if (isset($additional_attributes['milestone'])) {
					$copy->setMilestoneId($additional_attributes['milestone']);
				}
			}
			$copy->save();
			
			//Also copy members..
// 			$memberIds = json_decode(array_var($_POST, 'members'));
// 			$controller  = new ObjectController() ;
// 			$controller->add_to_members($copy, $memberIds);
			
			// copy subtasks
			if ($copy instanceof ProjectTask) {
				ProjectTasks::copySubTasks($object, $copy, true);
			} else if ($copy instanceof ProjectMilestone) {
				ProjectMilestones::copyTasks($object, $copy, true);
			}
			
			
			// copy custom properties			
			$copy->copyCustomPropertiesFrom($object);
			// copy linked objects
			$linked_objects = $object->getAllLinkedObjects();
			if (is_array($linked_objects)) {
				foreach ($linked_objects as $lo) {
					$copy->linkObject($lo);
				}
			}
			// copy reminders
			$reminders = ObjectReminders::getByObject($object);
			foreach ($reminders as $reminder /* @var ObjectReminder $reminder */ ) {
				$copy_reminder = new ObjectReminder();
				$copy_reminder->setContext($reminder->getContext());
				$copy_reminder->setDate(EMPTY_DATETIME);
				$copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
				$copy_reminder->setObject($copy);
				$copy_reminder->setType($reminder->getType());
				// $copy_reminder->setContactId($reminder->getContactId()); //TODO Feng 2 -  No  anda 
				$copy_reminder->save();
			}
			$template = $copy;
		} else {
			if ($object instanceof ProjectTask && isset($additional_attributes['milestone'])) {
				$object->setMilestoneId($additional_attributes['milestone']);
				$object->save();
			}
			// the object is already a template or can't be one, use it as it is
			$template = $object;
		}
		$to = new TemplateObject();
		$to->setObject($template);
		$to->setTemplate($this);
		$to->save();
		return $template->getObjectId();
	}
Ejemplo n.º 4
0
        $this->Method1();
        $this->Method2();
        $this->Method3();
    }
}
class TemplateObject extends TemplateBase
{
}
class TemplateObject1 extends TemplateBase
{
    public function Method3()
    {
        echo "TemplateObject1 Method3\n";
    }
}
class TemplateObject2 extends TemplateBase
{
    public function Method2()
    {
        echo "TemplateObject2 Method2\n";
    }
}
//实例化
$objTemplate = new TemplateObject();
$objTemplate1 = new TemplateObject1();
$objTemplate2 = new TemplateObject2();
$objTemplate->doSomethind();
echo "\n";
$objTemplate1->doSomethind();
echo "\n";
$objTemplate2->doSomethind();
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * The previous item
  * @return TemplateObject
  */
 private function PreviousItem()
 {
     $this->previous = $this->GetTreeItem('previous');
     return $this->previous->Exists() ? $this->previous : null;
 }
Ejemplo n.º 7
0
    public function doSomeThing()
    {
        $this->Method1();
        $this->Method2();
        $this->Method3();
    }
}
class TemplateObject extends TemplateBase
{
}
class TemplateObject1 extends TemplateBase
{
    public function Method3()
    {
        echo "TemplateObject1 Method3\n";
    }
}
class TemplateObject2 extends TemplateBase
{
    public function Method2()
    {
        echo "TemplateObject2 Method2\n";
    }
}
// 实例化
$objTemplate = new TemplateObject();
$objTemplate1 = new TemplateObject1();
$objTemplate2 = new TemplateObject2();
$objTemplate->doSomeThing();
$objTemplate1->doSomeThing();
$objTemplate2->doSomeThing();