Пример #1
0
	/**
	 * 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->setObjectName($task->getObjectName()) ;
		$new->setAssignedToContactId ( $task->getAssignedToContactId () );
		$new->setPriority ( $task->getPriority () );
		$new->setTimeEstimate ( $task->getTimeEstimate () );
		$new->setText ( $task->getText () );
		$new->setOrder ( ProjectTasks::maxOrder ( $new->getParentId (), $new->getMilestoneId () ) );
		$new->setStartDate ( $task->getStartDate () );
		$new->setDueDate ( $task->getDueDate () );
		return $new;
	}
Пример #2
0
 /**
  * Save subtasks added in task form, at 'subtasks' tab
  * @param $parent_task: ProjectTask - The parent task to set in the subtasks to save
  * @param $subtasks_data: array - An array with all the subtasks data
  * @param $member_ids: array with the member ids to classify the subtasks
  * @return array with the application logs to generate
  */
 private function saveSubtasks($parent_task, $subtasks_data, $member_ids)
 {
     $to_log = array('add' => array(), 'edit' => array(), 'trash' => array(), 'assigned' => array());
     $subs = $parent_task->getSubscriberIds();
     $subs_array = array();
     foreach ($subs as $sid) {
         $subs_array['user_' . $sid] = 1;
     }
     if ($parent_task instanceof ProjectTask && is_array($subtasks_data)) {
         foreach ($subtasks_data as $stdata) {
             $st = null;
             if ($stdata['id'] > 0) {
                 $st = ProjectTasks::instance()->findById($stdata['id']);
                 // subtask has been deleted, delete object and continue with next subtask
                 if ($stdata['deleted'] == 1 && $st instanceof ProjectTask) {
                     /*$st->trash(false);
                     		$st->save();*/
                     DB::execute("UPDATE " . TABLE_PREFIX . "objects SET trashed_by_id=" . logged_user()->getId() . ", trashed_on=NOW() WHERE id=" . $st->getId());
                     $to_log['trash'][] = $st;
                     continue;
                 }
             }
             $new_subtask = false;
             // new subtask
             if (!$st instanceof ProjectTask) {
                 $st = new ProjectTask();
                 $new_subtask = true;
             }
             if (trim($stdata['name'] == '')) {
                 continue;
             }
             $changed = false;
             if ($st->getObjectName() != $stdata['name'] || $st->getAssignedToContactId() != $stdata['assigned_to']) {
                 $changed = true;
             }
             if ($new_subtask || $changed) {
                 if ($stdata['assigned_to'] > 0 && $stdata['assigned_to'] != $st->getAssignedToContactId()) {
                     $to_log['assigned'][] = $st;
                 }
                 $st->setParentId($parent_task->getId());
                 $st->setObjectName($stdata['name']);
                 $st->setAssignedToContactId($stdata['assigned_to']);
                 $st->setPriority(array_var($stdata, 'priority', ProjectTasks::PRIORITY_NORMAL));
                 $st->setTypeContent(config_option("wysiwyg_tasks") ? 'html' : 'text');
                 $st->save();
                 $object_controller = new ObjectController();
                 $object_controller->add_to_members($st, $member_ids);
                 $st_subs_array = $subs_array;
                 if ($stdata['assigned_to'] > 0 && !in_array($stdata['assigned_to'], $subs)) {
                     $st_subs_array['user_' . $stdata['assigned_to']] = 1;
                 }
                 $object_controller->add_subscribers($st, $st_subs_array);
                 if ($new_subtask) {
                     $to_log['add'][] = $st;
                 } else {
                     $to_log['edit'][] = $st;
                 }
             }
         }
     }
     return $to_log;
 }
Пример #3
0
 private function save_object($request)
 {
     $response = false;
     if (!empty($request['args'])) {
         $service = $request['srv'];
         switch ($service) {
             case "task":
                 if ($request['args']['id']) {
                     $object = ProjectTasks::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectTask();
                 }
                 if ($object instanceof ProjectTask) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['description'])) {
                         $object->setText($request['args']['description']);
                     }
                     if (!empty($request['args']['due_date'])) {
                         if ($request['args']['due_date'] != '' && $request['args']['due_date'] != date_format_tip('dd/mm/yyyy')) {
                             $date_format = 'dd/mm/yyyy';
                             $object->setDueDate(DateTimeValueLib::dateFromFormatAndString($date_format, $value));
                         }
                     }
                     if (!empty($request['args']['completed'])) {
                         $object->setPercentCompleted($request['args']['completed']);
                     }
                     if (!empty($request['args']['assign_to'])) {
                         $object->setAssignedToContactId($request['args']['assign_to']);
                     }
                     if (!empty($request['args']['priority'])) {
                         $object->setPriority($request['args']['priority']);
                     }
                 }
                 break;
             case 'note':
                 if ($request['args']['id']) {
                     $object = ProjectMessages::instance()->findByid($request['args']['id']);
                 } else {
                     $object = new ProjectMessage();
                 }
                 if ($object instanceof ProjectMessage) {
                     if (!empty($request['args']['title'])) {
                         $object->setObjectName($request['args']['title']);
                     }
                     if (!empty($request['args']['title'])) {
                         $object->setText($request['args']['text']);
                     }
                 }
                 break;
         }
         // END SWITCH
         if ($object) {
             try {
                 $context = array();
                 $members = array();
                 if (!empty($request['args']['members'])) {
                     $members = $request['args']['members'];
                     $context = get_context_from_array($members);
                 }
                 //Check permissions:
                 if ($request['args']['id'] && $object->canEdit(logged_user()) || !$request['args']['id'] && $object->canAdd(logged_user(), $context)) {
                     DB::beginWork();
                     $object->save();
                     $object_controller = new ObjectController();
                     if (!$request['args']['id']) {
                         $object_controller->add_to_members($object, $members);
                     }
                     DB::commit();
                     $response = true;
                 }
             } catch (Exception $e) {
                 DB::rollback();
                 return false;
             }
         }
     }
     return $this->response('json', $response);
 }
 /**
  * Copy this template task to a project task
  *
  * @access public
  * @param void
  * @return null
  */
 function copyToProjectTask($instantiation_id = 0)
 {
     //$new_st_date='',$new_due_date='',$copy_status = false,$copy_repeat_options = true,$parent_subtask=0
     //param
     $parent_subtask = 0;
     $new_st_date = '';
     $new_due_date = '';
     $copy_status = false;
     $copy_repeat_options = true;
     $new_task = new ProjectTask();
     /*if($parent_subtask != 0){
     			$new_task->setParentId($parent_subtask);
     		}else{
     			$new_task->setParentId($this->getParentId());
     		}*/
     $new_task->setObjectName($this->getObjectName());
     $new_task->setText($this->getText());
     $new_task->setAssignedToContactId($this->getAssignedToContactId());
     $new_task->setAssignedOn($this->getAssignedOn());
     $new_task->setAssignedById($this->getAssignedById());
     $new_task->setTimeEstimate($this->getTimeEstimate());
     $new_task->setStartedOn($this->getStartedOn());
     $new_task->setStartedById($this->getStartedById());
     $new_task->setPriority($this->getPriority());
     $new_task->setState($this->getState());
     $new_task->setOrder($this->getOrder());
     $new_task->setMilestoneId($this->getMilestoneId());
     $new_task->setFromTemplateId($this->getTemplateId());
     $new_task->setUseStartTime($this->getUseStartTime());
     $new_task->setUseDueTime($this->getUseDueTime());
     $new_task->setTypeContent($this->getTypeContent());
     $new_task->setFromTemplateObjectId($this->getId());
     $new_task->setParentId($this->getParentId());
     $new_task->setOriginalTaskId(0);
     $new_task->setInstantiationId($instantiation_id);
     if ($this->getDueDate() instanceof DateTimeValue) {
         $new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
     }
     if ($this->getStartDate() instanceof DateTimeValue) {
         $new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
     }
     if ($copy_status) {
         $new_task->setCompletedById($this->getCompletedById());
         $new_task->setCompletedOn($this->getCompletedOn());
     }
     if ($copy_repeat_options) {
         $new_task->setRepeatEnd($this->getRepeatEnd());
         $new_task->setRepeatForever($this->getRepeatForever());
         $new_task->setRepeatNum($this->getRepeatNum());
         $new_task->setRepeatBy($this->getRepeatBy());
         $new_task->setRepeatD($this->getRepeatD());
         $new_task->setRepeatM($this->getRepeatM());
         $new_task->setRepeatY($this->getRepeatY());
     }
     if ($new_st_date != "") {
         if ($new_task->getStartDate() instanceof DateTimeValue) {
             $new_task->setStartDate($new_st_date);
         }
     }
     if ($new_due_date != "") {
         if ($new_task->getDueDate() instanceof DateTimeValue) {
             $new_task->setDueDate($new_due_date);
         }
     }
     $new_task->setDontMakeCalculations(true);
     $new_task->save();
     // Copy members, linked_objects, custom_properties, subscribers, reminders and comments
     copy_additional_object_data($this, $new_task);
     // Ensure that assigned user is subscribed
     if ($new_task->getAssignedTo() instanceof Contact) {
         $new_task->subscribeUser($new_task->getAssignedTo());
     }
     return $new_task;
 }
Пример #5
0
	function cloneTask($new_st_date='',$new_due_date='',$copy_status = false,$copy_repeat_options = true,$parent_subtask=0) {

		$new_task = new ProjectTask();
		
		if($parent_subtask != 0){
			$new_task->setParentId($parent_subtask);
		}else{
			$new_task->setParentId($this->getParentId());
		}
		$new_task->setObjectName($this->getObjectName());
		$new_task->setText($this->getText());
		$new_task->setAssignedToContactId($this->getAssignedToContactId());
		$new_task->setAssignedOn($this->getAssignedOn());
		$new_task->setAssignedById($this->getAssignedById());
		$new_task->setTimeEstimate($this->getTimeEstimate());
		$new_task->setStartedOn($this->getStartedOn());
		$new_task->setStartedById($this->getStartedById());
		$new_task->setPriority(($this->getPriority()));
		$new_task->setState($this->getState());
		$new_task->setOrder($this->getOrder());
		$new_task->setMilestoneId($this->getMilestoneId());
		$new_task->setIsTemplate($this->getIsTemplate());
		$new_task->setFromTemplateId($this->getFromTemplateId());
		$new_task->setUseStartTime($this->getUseStartTime());
		$new_task->setUseDueTime($this->getUseDueTime());
		$new_task->setTypeContent($this->getTypeContent());
		if($this->getParentId() == 0){//if not subtask
			if($this->getOriginalTaskId() == 0){
				$new_task->setOriginalTaskId($this->getObjectId());
			}else{
				$new_task->setOriginalTaskId($this->getOriginalTaskId());
			}
		}
		if ($this->getDueDate() instanceof DateTimeValue ) {
			$new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
		}
		if ($this->getStartDate() instanceof DateTimeValue ) {
			$new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
		}
		if ($copy_status) {
			$new_task->setCompletedById($this->getCompletedById());
			$new_task->setCompletedOn($this->getCompletedOn());
		}
		if ($copy_repeat_options) {
			$new_task->setRepeatEnd($this->getRepeatEnd());
			$new_task->setRepeatForever($this->getRepeatForever());
			$new_task->setRepeatNum($this->getRepeatNum());
			$new_task->setRepeatBy($this->getRepeatBy());
			$new_task->setRepeatD($this->getRepeatD());
			$new_task->setRepeatM($this->getRepeatM());
			$new_task->setRepeatY($this->getRepeatY());
		}		
		if($new_st_date != "") {
			if ($new_task->getStartDate() instanceof DateTimeValue) $new_task->setStartDate($new_st_date);
		}
		if($new_due_date != "") {
			if ($new_task->getDueDate() instanceof DateTimeValue) $new_task->setDueDate($new_due_date);
		}		
		$new_task->save();
		
		if (is_array($this->getAllLinkedObjects())) {
			foreach ($this->getAllLinkedObjects() as $lo) {
				$new_task->linkObject($lo);
			}
		}
		
		$sub_tasks = $this->getAllSubTasks();
		foreach ($sub_tasks as $st) {
			$new_dates = $this->getNextRepetitionDatesSubtask($st,$new_task, $new_st_date, $new_due_date);
			if ($st->getParentId() == $this->getId()) {
				$new_st = $st->cloneTask(array_var($new_dates, 'st'),array_var($new_dates, 'due'),$copy_status, $copy_repeat_options, $new_task->getId());
				if ($copy_status) {
					$new_st->setCompletedById($st->getCompletedById());
					$new_st->setCompletedOn($st->getCompletedOn());
					$new_st->save();
				}
				$new_task->attachTask($new_st);
			}
		}
                
		foreach ($this->getAllComments() as $com) {
			$new_com = new Comment();
			$new_com->setAuthorEmail($com->getAuthorEmail());
			$new_com->setAuthorName($com->getAuthorName());
			$new_com->setAuthorHomepage($com->getAuthorHomepage());
			$new_com->setCreatedById($com->getCreatedById());
			$new_com->setCreatedOn($com->getCreatedOn());
			$new_com->setUpdatedById($com->getUpdatedById());
			$new_com->setUpdatedOn($com->getUpdatedOn());
			$new_com->setText($com->getText());
			$new_com->setRelObjectId($new_task->getId());
			
			$new_com->save();
		}
                
		$_POST['subscribers'] = array();
		foreach ($this->getSubscribers() as $sub) {
			$_POST['subscribers']["user_" . $sub->getId()] = "checked";
		}
                
		$obj_controller = new ObjectController();
		$obj_controller->add_to_members($new_task, $this->getMemberIds());
		$obj_controller->add_subscribers($new_task);
		
		foreach($this->getCustomProperties() as $prop) {
			$new_prop = new ObjectProperty();
			$new_prop->setRelObjectId($new_task->getId());
			$new_prop->setPropertyName($prop->getPropertyName());
			$new_prop->setPropertyValue($prop->getPropertyValue());
			$new_prop->save();
		}
		
		$custom_props = CustomProperties::getAllCustomPropertiesByObjectType("ProjectTasks");
		foreach ($custom_props as $c_prop) {
			$values = CustomPropertyValues::getCustomPropertyValues($this->getId(), $c_prop->getId());
			if (is_array($values)) {
				foreach ($values as $val) {
					$cp = new CustomPropertyValue();
					$cp->setObjectId($new_task->getId());
					$cp->setCustomPropertyId($val->getCustomPropertyId());
					$cp->setValue($val->getValue());
					$cp->save();
				}
			}
		}
		
		$reminders = ObjectReminders::getByObject($this);
		foreach($reminders as $reminder) {
			$copy_reminder = new ObjectReminder();
			$copy_reminder->setContext($reminder->getContext());
			$reminder_date = $new_task->getColumnValue($reminder->getContext());
			if ($reminder_date instanceof DateTimeValue) {
				$reminder_date = new DateTimeValue($reminder_date->getTimestamp());
				$reminder_date->add('m', -$reminder->getMinutesBefore());
			}
			$copy_reminder->setDate($reminder_date);
			$copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
			$copy_reminder->setObject($new_task);
			$copy_reminder->setType($reminder->getType());
			$copy_reminder->setUserId($reminder->getUserId());
			$copy_reminder->save();
		}
		
		return $new_task;
	}
 function cloneTask($new_st_date = '', $new_due_date = '', $copy_status = false, $copy_repeat_options = true, $parent_subtask = 0)
 {
     $new_task = new ProjectTask();
     if ($parent_subtask != 0) {
         $new_task->setParentId($parent_subtask);
     } else {
         $new_task->setParentId($this->getParentId());
     }
     $new_task->setObjectName($this->getObjectName());
     $new_task->setText($this->getText());
     $new_task->setAssignedToContactId($this->getAssignedToContactId());
     $new_task->setAssignedOn($this->getAssignedOn());
     $new_task->setAssignedById($this->getAssignedById());
     $new_task->setTimeEstimate($this->getTimeEstimate());
     $new_task->setStartedOn($this->getStartedOn());
     $new_task->setStartedById($this->getStartedById());
     $new_task->setPriority($this->getPriority());
     $new_task->setState($this->getState());
     $new_task->setOrder($this->getOrder());
     $new_task->setMilestoneId($this->getMilestoneId());
     $new_task->setFromTemplateId($this->getFromTemplateId());
     $new_task->setUseStartTime($this->getUseStartTime());
     $new_task->setUseDueTime($this->getUseDueTime());
     $new_task->setTypeContent($this->getTypeContent());
     if ($this->getParentId() == 0) {
         //if not subtask
         if ($this->getOriginalTaskId() == 0) {
             $new_task->setOriginalTaskId($this->getObjectId());
         } else {
             $new_task->setOriginalTaskId($this->getOriginalTaskId());
         }
     }
     if ($this->getDueDate() instanceof DateTimeValue) {
         $new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
     }
     if ($this->getStartDate() instanceof DateTimeValue) {
         $new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
     }
     if ($copy_status) {
         $new_task->setCompletedById($this->getCompletedById());
         $new_task->setCompletedOn($this->getCompletedOn());
     }
     if ($copy_repeat_options) {
         $new_task->setRepeatEnd($this->getRepeatEnd());
         $new_task->setRepeatForever($this->getRepeatForever());
         $new_task->setRepeatNum($this->getRepeatNum());
         $new_task->setRepeatBy($this->getRepeatBy());
         $new_task->setRepeatD($this->getRepeatD());
         $new_task->setRepeatM($this->getRepeatM());
         $new_task->setRepeatY($this->getRepeatY());
     }
     if ($new_st_date != "") {
         if ($new_task->getStartDate() instanceof DateTimeValue) {
             $new_task->setStartDate($new_st_date);
         }
     }
     if ($new_due_date != "") {
         if ($new_task->getDueDate() instanceof DateTimeValue) {
             $new_task->setDueDate($new_due_date);
         }
     }
     $new_task->save();
     // Copy members, linked_objects, custom_properties, subscribers, reminders and comments
     copy_additional_object_data($this, $new_task);
     // Ensure that assigned user is subscribed
     if ($new_task->getAssignedTo() instanceof Contact) {
         $new_task->subscribeUser($new_task->getAssignedTo());
     }
     $sub_tasks = $this->getAllSubTasks();
     foreach ($sub_tasks as $st) {
         $new_dates = $this->getNextRepetitionDatesSubtask($st, $new_task, $new_st_date, $new_due_date);
         if ($st->getParentId() == $this->getId()) {
             $new_st = $st->cloneTask(array_var($new_dates, 'st'), array_var($new_dates, 'due'), $copy_status, $copy_repeat_options, $new_task->getId());
             if ($copy_status) {
                 $new_st->setCompletedById($st->getCompletedById());
                 $new_st->setCompletedOn($st->getCompletedOn());
                 $new_st->save();
             }
             $new_task->attachTask($new_st);
         }
     }
     return $new_task;
 }