/** * 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; }
function quick_add_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; } ajx_current("empty"); $task = new ProjectTask(); $task_data = array_var($_POST, 'task'); $parent_id = array_var($task_data, 'parent_id', 0); $parent = ProjectTasks::findById($parent_id); if (is_array($task_data)) { $task_data['due_date'] = getDateValue(array_var($task_data, 'task_due_date')); $task_data['start_date'] = getDateValue(array_var($task_data, 'task_start_date')); if ($task_data['due_date'] instanceof DateTimeValue) { $duetime = getTimeValue(array_var($task_data, 'task_due_time')); if (is_array($duetime)) { $task_data['due_date']->setHour(array_var($duetime, 'hours')); $task_data['due_date']->setMinute(array_var($duetime, 'mins')); } $task_data['due_date']->advance(logged_user()->getTimezone() * -3600); $task_data['use_due_time'] = is_array($duetime); } if ($task_data['start_date'] instanceof DateTimeValue) { $starttime = getTimeValue(array_var($task_data, 'task_start_time')); if (is_array($starttime)) { $task_data['start_date']->setHour(array_var($starttime, 'hours')); $task_data['start_date']->setMinute(array_var($starttime, 'mins')); } $task_data['start_date']->advance(logged_user()->getTimezone() * -3600); $task_data['use_start_time'] = is_array($starttime); } if (config_option("wysiwyg_tasks")) { $task_data['type_content'] = "html"; $task_data['text'] = preg_replace("/[\n|\r|\n\r]/", '', array_var($task_data, 'text')); } else { $task_data['type_content'] = "text"; } $task_data['object_type_id'] = $task->getObjectTypeId(); $task->setFromAttributes($task_data); if (array_var($task_data, 'is_completed', false) == 'true') { $task->setCompletedOn(DateTimeValueLib::now()); $task->setCompletedById(logged_user()->getId()); } try { DB::beginWork(); $task->save(); $totalMinutes = array_var($task_data, 'hours') * 60 + array_var($task_data, 'minutes'); $task->setTimeEstimate($totalMinutes); $task->save(); $gb_member_id = array_var($task_data, 'member_id'); $member_ids = array(); $persons_dim = Dimensions::findByCode('feng_persons'); $persons_dim_id = $persons_dim instanceof Dimension ? $persons_dim->getId() : 0; if ($parent) { if (count($parent->getMembers()) > 0) { foreach ($parent->getMembers() as $member) { if ($member->getDimensionId() != $persons_dim_id) { $member_ids[] = $member->getId(); } } } $task->setMilestoneId($parent->getMilestoneId()); $task->save(); } if (count($member_ids) == 0) { $member_ids = active_context_members(false); } if ($gb_member_id && is_numeric($gb_member_id)) { $member_ids[] = $gb_member_id; } $object_controller = new ObjectController(); $object_controller->add_to_members($task, $member_ids); //Add new work timeslot for this task // if (array_var($task_data,'hours') != '' && array_var($task_data,'hours') > 0){ // $hours = array_var($task_data, 'hours'); // $hours = - $hours; // // $timeslot = new Timeslot(); // $dt = DateTimeValueLib::now(); // $dt2 = DateTimeValueLib::now(); // $timeslot->setEndTime($dt); // $dt2 = $dt2->add('h', $hours); // $timeslot->setStartTime($dt2); // $timeslot->setContactId(logged_user()->getId()); // $timeslot->setObjectId($task->getId()); // $timeslot->save(); // } ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD); $assignee = $task->getAssignedToContact(); if ($assignee instanceof Contact) { $task->subscribeUser($assignee); } // create default reminder $reminder = new ObjectReminder(); $reminder->setMinutesBefore(1440); $reminder->setType("reminder_email"); $reminder->setContext("due_date"); $reminder->setObject($task); $reminder->setUserId(0); $date = $task->getDueDate(); if (!isset($minutes)) { $minutes = 0; } if ($date instanceof DateTimeValue) { $rdate = new DateTimeValue($date->getTimestamp() - $minutes * 60); $reminder->setDate($rdate); } $reminder->save(); $subs = array(); if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) { $json_subtasks = json_decode(array_var($_POST, 'multi_assignment')); $line = 0; foreach ($json_subtasks as $json_subtask) { $subtasks[$line]['assigned_to_contact_id'] = $json_subtask->assigned_to_contact_id; $subtasks[$line]['name'] = $json_subtask->name; $subtasks[$line]['time_estimate_hours'] = $json_subtask->time_estimate_hours; $subtasks[$line]['time_estimate_minutes'] = $json_subtask->time_estimate_minutes; $line++; } Hook::fire('save_subtasks', $task, $subtasks); $subtasks = ProjectTasks::findAll(array('conditions' => '`parent_id` = ' . DB::escape($task->getId()))); // findAll foreach ($subtasks as $sub) { $subs[] = $sub->getArrayInfo(); } } // subscribe $task->subscribeUser(logged_user()); DB::commit(); // notify asignee if (array_var($task_data, 'notify') == 'true') { try { Notifier::taskAssigned($task); } catch (Exception $e) { } // try } ajx_extra_data(array("task" => $task->getArrayInfo(), 'subtasks' => $subs)); flash_success(lang('success add task', $task->getObjectName())); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // try } // if }
function quick_add_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 { trim($notAllowedMember) == "" ? flash_error(lang('you must select where to keep', lang('the task'))) : flash_error(lang('no context permissions to add', lang("tasks"), $notAllowedMember)); } ajx_current("empty"); return; } ajx_current("empty"); $task = new ProjectTask(); $task_data = array_var($_POST, 'task'); $parent_id = array_var($task_data, 'parent_id', 0); $parent = ProjectTasks::findById($parent_id); if (is_array($task_data)) { $task_data['due_date'] = getDateValue(array_var($task_data, 'task_due_date')); $task_data['start_date'] = getDateValue(array_var($task_data, 'task_start_date')); if ($task_data['due_date'] instanceof DateTimeValue) { $duetime = getTimeValue(array_var($task_data, 'task_due_time')); if (is_array($duetime)) { $task_data['due_date']->setHour(array_var($duetime, 'hours')); $task_data['due_date']->setMinute(array_var($duetime, 'mins')); $task_data['due_date']->advance(logged_user()->getTimezone() * -3600); } $task_data['use_due_time'] = is_array($duetime); } if ($task_data['start_date'] instanceof DateTimeValue) { $starttime = getTimeValue(array_var($task_data, 'task_start_time')); if (is_array($starttime)) { $task_data['start_date']->setHour(array_var($starttime, 'hours')); $task_data['start_date']->setMinute(array_var($starttime, 'mins')); $task_data['start_date']->advance(logged_user()->getTimezone() * -3600); } $task_data['use_start_time'] = is_array($starttime); } if (config_option("wysiwyg_tasks")) { $task_data['type_content'] = "html"; $task_data['text'] = str_replace(array("\r", "\n", "\r\n"), array('', '', ''), array_var($task_data, 'text')); } else { $task_data['type_content'] = "text"; } $task_data['object_type_id'] = $task->getObjectTypeId(); $task->setFromAttributes($task_data); if (array_var($task_data, 'is_completed', false) == 'true') { $task->setCompletedOn(DateTimeValueLib::now()); $task->setCompletedById(logged_user()->getId()); } try { DB::beginWork(); $task->save(); $totalMinutes = array_var($task_data, 'hours') * 60 + array_var($task_data, 'minutes'); $task->setTimeEstimate($totalMinutes); $task->save(); $gb_member_ids = array_var($task_data, 'members'); $member_ids = array(); $persons_dim = Dimensions::findByCode('feng_persons'); $persons_dim_id = $persons_dim instanceof Dimension ? $persons_dim->getId() : 0; if ($parent) { if (count($parent->getMembers()) > 0) { foreach ($parent->getMembers() as $member) { if ($member->getDimensionId() != $persons_dim_id) { $member_ids[] = $member->getId(); } } } $task->setMilestoneId($parent->getMilestoneId()); $task->save(); } if (count($member_ids) == 0) { $member_ids = active_context_members(false); } // get member ids if ($gb_member_ids && !empty($gb_member_ids)) { $member_ids = json_decode(array_var($task_data, 'members')); } $object_controller = new ObjectController(); $object_controller->add_to_members($task, $member_ids); $assignee = $task->getAssignedToContact(); $assignee_to_me = false; if ($assignee instanceof Contact) { $task->subscribeUser($assignee); //do not notify my self if ($assignee->getId() == logged_user()->getId()) { $assignee_to_me = true; } } // create default reminder by user config option if ($task->getDueDate() != null && user_config_option("add_task_default_reminder")) { $reminder = new ObjectReminder(); $def = explode(",", user_config_option("reminders_tasks")); $minutes = $def[2] * $def[1]; $reminder->setMinutesBefore($minutes); $reminder->setType($def[0]); $reminder->setContext("due_date"); $reminder->setObject($task); $reminder->setUserId(0); $date = $task->getDueDate(); if ($date instanceof DateTimeValue) { $rdate = new DateTimeValue($date->getTimestamp() - $minutes * 60); $reminder->setDate($rdate); } $reminder->save(); } $subs = array(); if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) { $json_subtasks = json_decode(array_var($_POST, 'multi_assignment'), true); $subtasks = array(); $line = 0; if (is_array($json_subtasks)) { foreach ($json_subtasks as $json_subtask) { $subtasks[$line]['assigned_to_contact_id'] = $json_subtask['assigned_to_contact_id']; $subtasks[$line]['name'] = $json_subtask['name']; $subtasks[$line]['time_estimate_hours'] = $json_subtask['time_estimate_hours']; $subtasks[$line]['time_estimate_minutes'] = $json_subtask['time_estimate_minutes']; $line++; } } Hook::fire('save_subtasks', $task, $subtasks); $subtasks = ProjectTasks::findAll(array('conditions' => '`parent_id` = ' . DB::escape($task->getId()))); // findAll foreach ($subtasks as $sub) { $subs[] = $sub->getArrayInfo(); } } // subscribe $task->subscribeUser(logged_user()); //for calculate member status we save de task again after the object have the members $task->save(); DB::commit(); $isSailent = true; // notify asignee if ((array_var($task_data, 'notify') == 'true' || user_config_option("can notify from quick add") && !user_config_option("show_notify_checkbox_in_quick_add")) && !$assignee_to_me) { $isSailent = false; try { Notifier::taskAssigned($task); } catch (Exception $e) { Logger::log($e->getMessage()); Logger::log($e->getTraceAsString()); } // try } ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD, null, $isSailent); ajx_extra_data(array("task" => $task->getArrayInfo(), 'subtasks' => $subs)); flash_success(lang('success add task', $task->getObjectName())); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // try } // if }
/** * 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 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; }
function cloneTask($copy_status = false) { $new_task = new ProjectTask(); $new_task->setParentId($this->getParentId()); $new_task->setTitle($this->getTitle()); $new_task->setText($this->getText()); $new_task->setAssignedToCompanyId($this->getAssignedToCompanyId()); $new_task->setAssignedToUserId($this->getAssignedToUserId()); $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->setIsPrivate($this->getIsPrivate()); $new_task->setIsTemplate($this->getIsTemplate()); $new_task->setFromTemplateId($this->getFromTemplateId()); 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()); } $new_task->save(); $new_task->setTagsFromCSV(implode(",", $this->getTagNames())); foreach ($this->getWorkspaces() as $ws) { $new_task->addToWorkspace($ws); } if (is_array($this->getAllLinkedObjects())) { foreach ($this->getAllLinkedObjects() as $lo) { $new_task->linkObject($lo); } } $sub_tasks = $this->getAllSubTasks(); foreach ($sub_tasks as $st) { if ($st->getParentId() == $this->getId()) { $new_st = $st->cloneTask($copy_status); 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->setIsAnonymous($com->getIsAnonymous()); $new_com->setIsPrivate($com->getIsPrivate()); $new_com->setText($com->getText()); $new_com->setRelObjectId($new_task->getId()); $new_com->setRelObjectManager("ProjectTasks"); $new_com->save(); } $_POST['subscribers'] = array(); foreach ($this->getSubscribers() as $sub) { $_POST['subscribers']["user_" . $sub->getId()] = "checked"; } $obj_controller = new ObjectController(); $obj_controller->add_subscribers($new_task); foreach ($this->getCustomProperties() as $prop) { $new_prop = new ObjectProperty(); $new_prop->setRelObjectId($new_task->getId()); $new_prop->setRelObjectManager($prop->getRelObjectManager()); $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; }