/** * * * @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(); }
static function getArrayInfo($raw_data, $full = false) { $desc = ""; if ($full) { if (config_option("wysiwyg_tasks")) { if ($raw_data['type_content'] == "text") { $desc = nl2br(htmlspecialchars($raw_data['text'])); } else { $desc = purify_html(nl2br($raw_data['text'])); } } else { if ($raw_data['type_content'] == "text") { $desc = htmlspecialchars($raw_data['text']); } else { $desc = html_to_text(html_entity_decode(nl2br($raw_data['text']), null, "UTF-8")); } } } $member_ids = ObjectMembers::instance()->getCachedObjectMembers($raw_data['id']); $tmp_task = new TemplateTask(); $tmp_task->setObjectId($raw_data['id']); $tmp_task->setId($raw_data['id']); $tmp_task->setAssignedToContactId($raw_data['assigned_to_contact_id']); $result = array('id' => $raw_data['id'], 't' => $raw_data['name'], 'desc' => $desc, 'members' => $member_ids, 'c' => strtotime($raw_data['created_on']), 'cid' => (int) $raw_data['created_by_id'], 'otype' => $raw_data['object_subtype'], 'pc' => (int) $raw_data['percent_completed'], 'memPath' => str_replace('"', "'", escape_character(json_encode($tmp_task->getMembersIdsToDisplayPath())))); $result['mas'] = (int) array_var($raw_data, 'multi_assignment'); if ($raw_data['completed_by_id'] > 0) { $result['s'] = 1; } if ($raw_data['parent_id'] > 0) { $result['pid'] = (int) $raw_data['parent_id']; } //if ($this->getPriority() != 200) $result['pr'] = (int) $raw_data['priority']; if ($raw_data['milestone_id'] > 0) { $result['mid'] = (int) $raw_data['milestone_id']; } if ($raw_data['assigned_to_contact_id'] > 0) { $result['atid'] = (int) $raw_data['assigned_to_contact_id']; } $result['atName'] = $tmp_task->getAssignedToName(); if ($raw_data['completed_by_id'] > 0) { $result['cbid'] = (int) $raw_data['completed_by_id']; $result['con'] = strtotime($raw_data['completed_on']); } if ($raw_data['due_date'] != EMPTY_DATETIME) { $result['dd'] = strtotime($raw_data['due_date']) + logged_user()->getTimezone() * 3600; $result['udt'] = $raw_data['use_due_time'] ? 1 : 0; } if ($raw_data['start_date'] != EMPTY_DATETIME) { $result['sd'] = strtotime($raw_data['start_date']) + logged_user()->getTimezone() * 3600; $result['ust'] = $raw_data['use_start_time'] ? 1 : 0; } $time_estimate = $raw_data['time_estimate']; $result['te'] = $raw_data['time_estimate']; if ($time_estimate > 0) { $result['et'] = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($time_estimate * 60), 'hm', 60); } $result['tz'] = logged_user()->getTimezone() * 3600; $ot = $tmp_task->getOpenTimeslots(); if ($ot) { $users = array(); $time = array(); $paused = array(); foreach ($ot as $t) { if (!$t instanceof Timeslot) { continue; } $time[] = $t->getSeconds(); $users[] = $t->getContactId(); $paused[] = $t->isPaused() ? 1 : 0; if ($t->isPaused() && $t->getContactId() == logged_user()->getId()) { $result['wpt'] = $t->getPausedOn()->getTimestamp(); } } $result['wt'] = $time; $result['wid'] = $users; $result['wp'] = $paused; } if ($raw_data['repeat_forever'] > 0 || $raw_data['repeat_num'] > 0 || $raw_data['repeat_end'] != EMPTY_DATETIME) { $result['rep'] = 1; } return $result; }
/** * Detach subtask from this task * * @param TemplateTask $task * @param TemplateTaskList $attach_to If you wish you can detach and attach task to * other list with one save query * @return null */ function detachTask(TemplateTask $task, $attach_to = null) { if ($task->getParentId() != $this->getId()) { return; } if ($attach_to instanceof TemplateTask) { $attach_to->attachTask($task); } else { $task->setParentId(0); $task->save(); } }
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); }