/** * Copy task * * @access public * @param void * @return null */ function copy_task() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $notAllowedMember = ''; if (!ProjectTask::canAdd(logged_user(), active_context(), $notAllowedMember)) { if (str_starts_with($notAllowedMember, '-- req dim --')) { flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in))); } else { flash_error(lang('no context permissions to add', lang("tasks"), $notAllowedMember)); } ajx_current("empty"); return; } // if $id = get_id(); $task = ProjectTasks::findById($id); if (!$task instanceof ProjectTask) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $title = $task->getIsTemplate() ? $task->getObjectName() : lang("copy of", $task->getObjectName()); $dd = $task->getDueDate() instanceof DateTimeValue ? $task->getDueDate()->advance(logged_user()->getTimezone() * 3600, false) : null; $sd = $task->getStartDate() instanceof DateTimeValue ? $task->getStartDate()->advance(logged_user()->getTimezone() * 3600, false) : null; $task_data = array('milestone_id' => $task->getMilestoneId(), 'title' => $title, 'name' => $title, 'due_date' => getDateValue($dd), 'start_date' => getDateValue($sd), 'assigned_to_contact_id' => $task->getAssignedToContactId(), 'parent_id' => $task->getParentId(), 'priority' => $task->getPriority(), 'time_estimate' => $task->getTimeEstimate(), 'text' => $task->getText(), 'copyId' => $task->getId(), 'percent_completed' => $task->getPercentCompleted()); // array $newtask = new ProjectTask(); if ($task->getUseStartTime()) { $newtask->setUseStartTime($task->getUseStartTime()); } if ($task->getUseDueTime()) { $newtask->setUseDueTime($task->getUseDueTime()); } tpl_assign('task_data', $task_data); tpl_assign('task', $newtask); tpl_assign('base_task', $task); tpl_assign('pending_task_id', 0); tpl_assign('multi_assignment', array()); $this->setTemplate("add_task"); }
/** * 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; }
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 instantiate_template_task_parameters(TemplateTask $object, ProjectTask $copy, $parameterValues = array()) { $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($object->getTemplateId(), $object->getId()); $manager = $copy->manager(); foreach ($objProp as $property) { $propName = $property->getProperty(); $value = $property->getValue(); if ($manager->getColumnType($propName) == DATA_TYPE_STRING || $manager->getColumnType($propName) == DATA_TYPE_INTEGER) { if (is_array($parameterValues)) { $is_present = false; foreach ($parameterValues as $param => $val) { if (strpos($value, '{' . $param . '}') !== FALSE) { $value = str_replace('{' . $param . '}', $val, $value); $is_present = true; } } // if parameter not present replace the parameter code with empty string if (!$is_present) { $value = preg_replace('/[{].*[}]/U', '', $value); } } } else { if ($manager->getColumnType($propName) == DATA_TYPE_DATE || $manager->getColumnType($propName) == DATA_TYPE_DATETIME) { $operator = '+'; if (strpos($value, '+') === false) { $operator = '-'; } $opPos = strpos($value, $operator); if ($opPos !== false) { // Is parametric $dateParam = substr($value, 1, strpos($value, '}') - 1); if ($dateParam == 'task_creation') { $date = DateTimeValueLib::now(); } else { $date = getDateValue($parameterValues[$dateParam]); if (!$date instanceof DateTimeValue) { $date = DateTimeValueLib::now(); } if ($copy instanceof ProjectTask && config_option('use_time_in_task_dates') && $propName == "due_date") { $copy->setUseDueTime(1); $hour_min = getTimeValue(user_config_option('work_day_end_time')); $hour_min['hours']; $hour_min['mins']; $date->setHour($hour_min['hours']); $date->setMinute($hour_min['mins']); $date = $date->add('s', -logged_user()->getTimezone() * 3600); } if ($copy instanceof ProjectTask && config_option('use_time_in_task_dates') && $propName == "start_date") { $copy->setUseStartTime(1); $hour_min = getTimeValue(user_config_option('work_day_start_time')); $hour_min['hours']; $hour_min['mins']; $date->setHour($hour_min['hours']); $date->setMinute($hour_min['mins']); $date = $date->add('s', -logged_user()->getTimezone() * 3600); } } $dateUnit = substr($value, strlen($value) - 1); // d, w or m (for days, weeks or months) if ($dateUnit == 'm') { $dateUnit = 'M'; // make month unit uppercase to call DateTimeValue::add with correct parameter } $dateNum = (int) substr($value, strpos($value, $operator), strlen($value) - 2); //Hook::fire('template_param_date_calculation', array('op' => $operator, 'date' => $date, 'template_id' => $object->getTemplateId(), 'original' => $object, 'copy' => $copy), $dateNum); $value = $date->add($dateUnit, $dateNum); } else { $value = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value); } } } if ($value != '') { if (!$copy->setColumnValue($propName, $value)) { $copy->object->setColumnValue($propName, $value); } if ($propName == 'text' && $copy->getTypeContent() == 'text') { $copy->setText(html_to_text($copy->getText())); } $copy->save(); } } // Ensure that assigned user is subscribed if ($copy instanceof ProjectTask && $copy->getAssignedTo() instanceof Contact) { $copy->subscribeUser($copy->getAssignedTo()); } $ret = null; Hook::fire('after_template_object_param_instantiation', array('template_id' => $object->getTemplateId(), 'original' => $object, 'copy' => $copy, 'parameter_values' => $parameterValues), $ret); }
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; }