コード例 #1
0
 /**
  * 
  * @author Ignacio Vazquez - elpepe.uy@gmail.com
  * @param ProjectTask $object
  */
 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();
         //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) {
             $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 {
         // 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();
 }
コード例 #2
0
 /**
  * Copies tasks from milestoneFrom to milestoneTo.
  *
  * @param ProjectMilestone $milestoneFrom
  * @param ProjectMilestone $milestoneTo
  */
 function copyTasks(ProjectMilestone $milestoneFrom, ProjectMilestone $milestoneTo, $as_template = false)
 {
     //FIXME
     foreach ($milestoneFrom->getTasks($as_template) as $sub) {
         if ($sub->getParentId() != 0) {
             continue;
         }
         $new = ProjectTasks::createTaskCopy($sub);
         $new->setMilestoneId($milestoneTo->getId());
         $new->save();
         $object_controller = new ObjectController();
         $members = $milestoneFrom->getMemberIds();
         if (count($members)) {
             $object_controller->add_to_members($new, $members);
         }
         /*
         			foreach ($sub->getWorkspaces() as $workspace) {
         				if (ProjectTask::canAdd(logged_user(), $workspace)) {
         					$new->addToWorkspace($workspace);
         				}
         			}
         
         			if (!$as_template && active_project() instanceof Project && ProjectTask::canAdd(logged_user(), active_project())) {
         				$new->removeFromAllWorkspaces();
         				$new->addToWorkspace(active_project());
         			}
         */
         $new->copyCustomPropertiesFrom($sub);
         $new->copyLinkedObjectsFrom($sub);
         ProjectTasks::copySubTasks($sub, $new, $as_template);
     }
 }
コード例 #3
0
 /**
  * Add new task
  *
  * @access public
  * @param void
  * @return null
  */
 function 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;
     }
     // if
     $task = new ProjectTask();
     $task_data = array_var($_POST, 'task');
     if (!is_array($task_data)) {
         $dd = getDateValue(array_var($_POST, 'task_due_date', ''));
         if ($dd instanceof DateTimeValue) {
             $duetime = getTimeValue(array_var($_POST, 'task_due_time'));
             if (is_array($duetime)) {
                 $dd->setHour(array_var($duetime, 'hours'));
                 $dd->setMinute(array_var($duetime, 'mins'));
             }
             $task->setUseDueTime(is_array($duetime));
         }
         $sd = getDateValue(array_var($_POST, 'task_start_date', ''));
         if ($sd instanceof DateTimeValue) {
             $starttime = getTimeValue(array_var($_POST, 'task_start_time'));
             if (is_array($starttime)) {
                 $sd->setHour(array_var($starttime, 'hours'));
                 $sd->setMinute(array_var($starttime, 'mins'));
             }
             $task->setUseStartTime(is_array($starttime));
         }
         $time_estimate = array_var($_POST, 'hours', 0) * 60 + array_var($_POST, 'minutes', 0);
         $task_data = array('milestone_id' => array_var($_POST, 'milestone_id', 0), 'project_id' => 1, 'name' => array_var($_POST, 'name', ''), 'assigned_to_contact_id' => array_var($_POST, 'assigned_to_contact_id', '0'), 'parent_id' => array_var($_POST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => array_var($_POST, 'text', ''), 'start_date' => $sd, 'due_date' => $dd, 'time_estimate' => $time_estimate, 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'percent_completed' => array_var($_POST, "percent_completed", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification' => array_var($_POST, 'notify') && array_var($_POST, 'notify') == 'true');
         // array
         if (Plugins::instance()->isActivePlugin('mail')) {
             $from_email = array_var($_GET, 'from_email');
             $email = MailContents::findById($from_email);
             if ($email instanceof MailContent) {
                 $task_data['name'] = $email->getSubject();
                 $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody());
                 tpl_assign('from_email', $email);
             }
         }
     }
     // if
     if (array_var($_GET, 'replace')) {
         ajx_replace(true);
     }
     tpl_assign('task_data', $task_data);
     tpl_assign('task', $task);
     tpl_assign('pending_task_id', 0);
     $subtasks = array();
     if (array_var($_POST, 'multi_assignment')) {
         $json_subtasks = json_decode(array_var($_POST, 'multi_assignment'));
         $line = 0;
         if (count($json_subtasks) > 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++;
             }
         }
     }
     tpl_assign('multi_assignment', $subtasks);
     if (is_array(array_var($_POST, 'task'))) {
         // order
         $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0)));
         $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date'));
         $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date'));
         if ($task_data['due_date'] instanceof DateTimeValue) {
             $duetime = getTimeValue(array_var($_POST, '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($_POST, '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);
         }
         try {
             $err_msg = $this->setRepeatOptions($task_data);
             if ($err_msg) {
                 flash_error($err_msg);
                 ajx_current("empty");
                 return;
             }
             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();
             $member_ids = json_decode(array_var($_POST, 'members'));
             $task->setFromAttributes($task_data);
             if (!can_task_assignee(logged_user())) {
                 flash_error(lang('no access permissions'));
                 ajx_current("empty");
                 return;
             }
             $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0);
             $task->setTimeEstimate($totalMinutes);
             $id = array_var($_GET, 'id', 0);
             $parent = ProjectTasks::findById($id);
             if ($parent instanceof ProjectTask) {
                 $task->setParentId($id);
                 $member_ids = $parent->getMemberIds();
                 if ($parent->getIsTemplate()) {
                     $task->setIsTemplate(true);
                 }
             }
             if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) {
                 flash_error(lang('task child of child error'));
                 ajx_current("empty");
                 return;
             }
             DB::beginWork();
             $task->save();
             // dependencies
             if (config_option('use tasks dependencies')) {
                 $previous_tasks = array_var($task_data, 'previous');
                 if (is_array($previous_tasks)) {
                     foreach ($previous_tasks as $ptask) {
                         if ($ptask == $task->getId()) {
                             continue;
                         }
                         $dep = ProjectTaskDependencies::findById(array('previous_task_id' => $ptask, 'task_id' => $task->getId()));
                         if (!$dep instanceof ProjectTaskDependency) {
                             $dep = new ProjectTaskDependency();
                             $dep->setPreviousTaskId($ptask);
                             $dep->setTaskId($task->getId());
                             $dep->save();
                         }
                     }
                 }
             }
             if (array_var($_GET, 'copyId', 0) > 0) {
                 // copy remaining stuff from the task with id copyId
                 $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId'));
                 if ($toCopy instanceof ProjectTask) {
                     ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false));
                 }
             }
             // if task is added from task view -> add subscribers
             if (array_var($task_data, 'inputtype') == 'taskview') {
                 if (!isset($_POST['subscribers'])) {
                     $_POST['subscribers'] = array();
                 }
                 $_POST['subscribers']['user_' . logged_user()->getId()] = 'checked';
                 if ($task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())->getUserType()) {
                     $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = 'checked';
                 }
             }
             // Add assigned user to the subscibers list
             if (isset($_POST['subscribers']) && $task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())) {
                 $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = 'checked';
             }
             //Link objects
             $object_controller = new ObjectController();
             $object_controller->add_to_members($task, $member_ids);
             $object_controller->add_subscribers($task);
             $object_controller->link_to_new_object($task);
             $object_controller->add_custom_properties($task);
             $object_controller->add_reminders($task);
             ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD);
             if (config_option('repeating_task') == 1) {
                 $opt_rep_day['saturday'] = false;
                 $opt_rep_day['sunday'] = false;
                 if (array_var($task_data, 'repeat_saturdays', false)) {
                     $opt_rep_day['saturday'] = true;
                 }
                 if (array_var($task_data, 'repeat_sundays', false)) {
                     $opt_rep_day['sunday'] = true;
                 }
                 $this->repetitive_task($task, $opt_rep_day);
             }
             if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) {
                 $subtasks = array_var($_POST, 'multi_assignment');
                 Hook::fire('save_subtasks', $task, $subtasks);
             }
             DB::commit();
             // notify asignee
             if (array_var($task_data, 'send_notification') == 'checked') {
                 try {
                     Notifier::taskAssigned($task);
                 } catch (Exception $e) {
                     evt_add("debug", $e->getMessage());
                 }
                 // try
             }
             if ($task->getIsTemplate()) {
                 flash_success(lang('success add template', $task->getObjectName()));
             } else {
                 flash_success(lang('success add task list', $task->getObjectName()));
             }
             if (array_var($task_data, 'inputtype') != 'taskview') {
                 ajx_current("back");
             } else {
                 ajx_current("reload");
             }
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #4
0
	/**
	 * Copies subtasks from taskFrom to taskTo.
	 *
	 * @param ProjectTask $taskFrom
	 * @param ProjectTask $taskTo
	 */
	function copySubTasks(ProjectTask $taskFrom, ProjectTask $taskTo, $as_template = false) {
		foreach ( $taskFrom->getSubTasks () as $sub ) {
			if ($sub->getId() == $taskTo->getId()) continue;
			$new = ProjectTasks::createTaskCopy ( $sub );
			$new->setIsTemplate ( $as_template );
			$new->setParentId ( $taskTo->getId () );
			$new->setMilestoneId ( $taskTo->getMilestoneId () );
			$new->setOrder ( ProjectTasks::maxOrder ( $new->getParentId (), $new->getMilestoneId () ) );
			if ($sub->getIsTemplate ()) {
				$new->setFromTemplateId ( $sub->getId () );
			}
			$new->save ();
			
			$object_controller = new ObjectController();
			if (count($taskFrom->getMemberIds())) {
				$object_controller->add_to_members($new, $taskFrom->getMemberIds());
			}
			$new->copyCustomPropertiesFrom ( $sub );
			$new->copyLinkedObjectsFrom ( $sub );
			ProjectTasks::copySubTasks ( $sub, $new, $as_template );
		}
	}
コード例 #5
0
 function instantiate()
 {
     $selected_members = array();
     $id = get_id();
     $template = COTemplates::findById($id);
     if (!$template instanceof COTemplate) {
         flash_error(lang("template dnx"));
         ajx_current("empty");
         return;
     }
     $parameters = TemplateParameters::getParametersByTemplate($id);
     $parameterValues = array_var($_POST, 'parameterValues');
     if (count($parameters) > 0 && !isset($parameterValues)) {
         ajx_current("back");
         return;
     }
     if (array_var($_POST, 'members')) {
         $selected_members = json_decode(array_var($_POST, 'members'));
     } else {
         $context = active_context();
         foreach ($context as $selection) {
             if ($selection instanceof Member) {
                 $selected_members[] = $selection->getId();
             }
         }
     }
     $objects = $template->getObjects();
     $controller = new ObjectController();
     if (count($selected_members > 0)) {
         $selected_members_instances = Members::findAll(array('conditions' => 'id IN (' . implode($selected_members) . ')'));
     } else {
         $selected_members_instances = array();
     }
     DB::beginWork();
     $active_context = active_context();
     foreach ($objects as $object) {
         if (!$object instanceof ContentDataObject) {
             continue;
         }
         // copy object
         $copy = $object->copy();
         if ($copy->columnExists('is_template')) {
             $copy->setColumnValue('is_template', false);
         }
         if ($copy instanceof ProjectTask) {
             // don't copy parent task and milestone
             $copy->setMilestoneId(0);
             $copy->setParentId(0);
         }
         $copy->save();
         /*		if (!can_write(logged_user(), $selected_members_instances, $copy->getObjectTypeId()) ) {
         				flash_error(lang('no context permissions to add', $copy instanceof ProjectTask ? lang("tasks") : ($copy instanceof ProjectMilestone ? lang('milestones') : '')));
         				DB::rollback();
         				ajx_current("empty");
         				return;
         			}*/
         // Copy members from origial object, if it doesn't have then use active context members
         /*	$template_object_members = $object->getMemberIds();
         			if (count($template_object_members) == 0) {
         				$object_member_ids = active_context_members(false);
         				if (count($object_member_ids) > 0) {
         					$template_object_members = Members::findAll(array("id" => true, "conditions" => "id IN (".implode(",", $object_member_ids).")"));
         				}
         			}*/
         /* Set instantiated object members:
          * foreach dimension:
          * 		if no member is active then the instantiated object is put in the same members as the original for current dimension
          * 		if a member is selected in current dimension then the instantiated object will be put in that member  
          */
         $template_object_members = $object->getMembers();
         $object_members = array();
         foreach ($active_context as $selection) {
             if ($selection instanceof Member) {
                 // member selected
                 $object_members[] = $selection->getId();
             } else {
                 if ($selection instanceof Dimension) {
                     // no member selected
                     foreach ($template_object_members as $tom) {
                         if ($tom->getDimensionId() == $selection->getId()) {
                             $object_members[] = $tom->getId();
                         }
                     }
                 }
             }
         }
         $controller->add_to_members($copy, $object_members);
         // copy linked objects
         $copy->copyLinkedObjectsFrom($object);
         // copy subtasks if applicable
         if ($copy instanceof ProjectTask) {
             ProjectTasks::copySubTasks($object, $copy, false);
             foreach ($copy->getOpenSubTasks(false) as $m_task) {
                 $controller->add_to_members($m_task, $object_members);
             }
             $manager = $copy->manager();
         } else {
             if ($copy instanceof ProjectMilestone) {
                 ProjectMilestones::copyTasks($object, $copy, false);
                 foreach ($copy->getTasks(false) as $m_task) {
                     $controller->add_to_members($m_task, $object_members);
                 }
                 $manager = $copy->manager();
             }
         }
         // copy custom properties
         $copy->copyCustomPropertiesFrom($object);
         // set property values as defined in template
         $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId());
         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)) {
                     foreach ($parameterValues as $param => $val) {
                         if (strpos($value, '{' . $param . '}') !== FALSE) {
                             $value = str_replace('{' . $param . '}', $val, $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);
                         $date = $parameterValues[$dateParam];
                         $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);
                         $date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date);
                         $date = new DateTimeValue($date->getTimestamp() - logged_user()->getTimezone() * 3600);
                         // set date to GMT 0
                         $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);
                 }
                 $copy->save();
             }
         }
         // subscribe assigned to
         if ($copy instanceof ProjectTask) {
             foreach ($copy->getOpenSubTasks(false) as $m_task) {
                 if ($m_task->getAssignedTo() instanceof Contact) {
                     $m_task->subscribeUser($copy->getAssignedTo());
                 }
             }
             if ($copy->getAssignedTo() instanceof Contact) {
                 $copy->subscribeUser($copy->getAssignedTo());
             }
         } else {
             if ($copy instanceof ProjectMilestone) {
                 foreach ($copy->getTasks(false) as $m_task) {
                     if ($m_task->getAssignedTo() instanceof Contact) {
                         $m_task->subscribeUser($copy->getAssignedTo());
                     }
                 }
             }
         }
         // copy reminders
         $reminders = ObjectReminders::getByObject($object);
         foreach ($reminders as $reminder) {
             $copy_reminder = new ObjectReminder();
             $copy_reminder->setContext($reminder->getContext());
             $reminder_date = $copy->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($copy);
             $copy_reminder->setType($reminder->getType());
             $copy_reminder->setUserId($reminder->getUserId());
             $copy_reminder->save();
         }
     }
     DB::commit();
     if (is_array($parameters) && count($parameters) > 0) {
         ajx_current("back");
     } else {
         if (!$choose_ctx) {
             ajx_current("back");
         } else {
             ajx_current("reload");
         }
     }
 }
コード例 #6
0
 /**
  * Add new task
  *
  * @access public
  * @param void
  * @return null
  */
 function add_task()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $project = active_or_personal_project();
     if (!ProjectTask::canAdd(logged_user(), $project)) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $task = new ProjectTask();
     $task_data = array_var($_POST, 'task');
     if (!is_array($task_data)) {
         $task_data = array('milestone_id' => array_var($_POST, 'milestone_id', 0), 'project_id' => array_var($_POST, 'project_id', active_or_personal_project()->getId()), 'title' => array_var($_POST, 'title', ''), 'assigned_to' => array_var($_POST, 'assigned_to', '0:0'), 'parent_id' => array_var($_POST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => array_var($_POST, 'text', ''), 'start_date' => getDateValue(array_var($_POST, 'task_start_date', '')), 'due_date' => getDateValue(array_var($_POST, 'task_due_date', '')), 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'tags' => array_var($_POST, "tags", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification' => array_var($_POST, 'notify') && array_var($_POST, 'notify') == 'true');
         // array
         $from_email = array_var($_GET, 'from_email');
         $email = MailContents::findById($from_email);
         if ($email instanceof MailContent) {
             $task_data['title'] = $email->getSubject();
             $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody());
             $task_data['tags'] = implode(", ", $email->getTagNames());
             tpl_assign('from_email', $email);
         }
     }
     // if
     if (array_var($_GET, 'replace')) {
         ajx_replace(true);
     }
     tpl_assign('task_data', $task_data);
     tpl_assign('task', $task);
     if (is_array(array_var($_POST, 'task'))) {
         $proj = Projects::findById(array_var($task_data, 'project_id'));
         if ($proj instanceof Project) {
             $project = $proj;
         }
         // order
         $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0)));
         $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date'));
         $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date'));
         try {
             $err_msg = $this->setRepeatOptions($task_data);
             if ($err_msg) {
                 flash_error($err_msg);
                 ajx_current("empty");
                 return;
             }
             $task->setFromAttributes($task_data);
             $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0);
             $task->setTimeEstimate($totalMinutes);
             $task->setIsPrivate(false);
             // Not used, but defined as not null.
             // Set assigned to
             $assigned_to = explode(':', array_var($task_data, 'assigned_to', ''));
             $company_id = array_var($assigned_to, 0, 0);
             $user_id = array_var($assigned_to, 1, 0);
             $can_assign = can_assign_task_to_company_user(logged_user(), $task, $company_id, $user_id);
             if ($can_assign !== true) {
                 flash_error($can_assign);
                 ajx_current("empty");
                 return;
             }
             $task->setAssignedToCompanyId($company_id);
             $task->setAssignedToUserId($user_id);
             $id = array_var($_GET, 'id', 0);
             $parent = ProjectTasks::findById($id);
             if ($parent instanceof ProjectTask) {
                 $task->setParentId($id);
                 if ($parent->getIsTemplate()) {
                     $task->setIsTemplate(true);
                 }
             }
             if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) {
                 flash_error(lang('task child of child error'));
                 ajx_current("empty");
                 return;
             }
             //Add handins
             $handins = array();
             for ($i = 0; $i < 4; $i++) {
                 if (isset($task_data["handin{$i}"]) && is_array($task_data["handin{$i}"]) && trim(array_var($task_data["handin{$i}"], 'title')) != '') {
                     $assigned_to = explode(':', array_var($task_data["handin{$i}"], 'assigned_to', ''));
                     $handins[] = array('title' => array_var($task_data["handin{$i}"], 'title'), 'responsible_company_id' => array_var($assigned_to, 0, 0), 'responsible_user_id' => array_var($assigned_to, 1, 0));
                     // array
                 }
                 // if
             }
             // for
             DB::beginWork();
             $task->save();
             //$task->setProject($project);
             //echo 'pepe'; DB::rollback(); die();
             $task->setTagsFromCSV(array_var($task_data, 'tags'));
             foreach ($handins as $handin_data) {
                 $handin = new ObjectHandin();
                 $handin->setFromAttributes($handin_data);
                 $handin->setObjectId($task->getId());
                 $handin->setObjectManager(get_class($task->manager()));
                 $handin->save();
             }
             // foreach*/
             if (array_var($_GET, 'copyId', 0) > 0) {
                 // copy remaining stuff from the task with id copyId
                 $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId'));
                 if ($toCopy instanceof ProjectTask) {
                     ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false));
                 }
             }
             //Link objects
             $object_controller = new ObjectController();
             if ($parent instanceof ProjectTask) {
                 // task is being added as subtask of another, so place in same workspace
                 $task->addToWorkspace($parent->getProject());
             } else {
                 $object_controller->add_to_workspaces($task);
             }
             $object_controller->link_to_new_object($task);
             $object_controller->add_subscribers($task);
             $object_controller->add_custom_properties($task);
             $object_controller->add_reminders($task);
             ApplicationLogs::createLog($task, $task->getWorkspaces(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             // notify asignee
             if (array_var($task_data, 'send_notification') == 'checked') {
                 try {
                     Notifier::taskAssigned($task);
                 } catch (Exception $e) {
                     evt_add("debug", $e->getMessage());
                 }
                 // try
             }
             if ($task->getIsTemplate()) {
                 flash_success(lang('success add template', $task->getTitle()));
             } else {
                 flash_success(lang('success add task list', $task->getTitle()));
             }
             if (array_var($task_data, 'inputtype') != 'taskview') {
                 ajx_current("back");
             } else {
                 ajx_current("reload");
             }
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #7
0
 /**
  * Add new task
  *
  * @access public
  * @param void
  * @return null
  */
 function add_task()
 {
     //is template task?
     $isTemplateTask = false;
     if (array_var($_REQUEST, 'template_task') == true) {
         $isTemplateTask = true;
         if (array_var($_REQUEST, 'template_id')) {
             $template_id = array_var($_REQUEST, 'template_id');
         } else {
             $template_id = 0;
         }
         tpl_assign('template_id', $template_id);
         tpl_assign('additional_tt_params', array_var($_REQUEST, 'additional_tt_params'));
     }
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $email = null;
     $context = active_context();
     $member_ids = json_decode(array_var($_POST, 'members', null));
     if (is_array($member_ids) && count($member_ids) > 0) {
         $context = Members::findAll(array('conditions' => 'id IN (' . implode(',', $member_ids) . ')'));
     }
     $notAllowedMember = '';
     if (!ProjectTask::canAdd(logged_user(), $context, $notAllowedMember) && !$isTemplateTask && is_array(array_var($_POST, 'task'))) {
         if (str_starts_with($notAllowedMember, '-- req dim --')) {
             $msg = lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in));
         } else {
             trim($notAllowedMember) == "" ? $msg = lang('you must select where to keep', lang('the task')) : ($msg = lang('no context permissions to add', lang("tasks"), $notAllowedMember));
         }
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             $this->setTemplate(get_template_path("empty"));
             $params = array('errorMessage' => $msg, 'errorCode' => 1, 'showMessage' => 1, 'reload' => array_var($_REQUEST, 'reload'));
             print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx'));
         } else {
             flash_success($msg);
         }
         ajx_current("empty");
         return;
     }
     //is template task?
     if (array_var($_REQUEST, 'template_task') == true) {
         $task = new TemplateTask();
         $this->setTemplate(get_template_path('add_template_task', 'template_task'));
     } else {
         $task = new ProjectTask();
     }
     $task_data = array_var($_POST, 'task');
     if (is_array($task_data)) {
         foreach ($task_data as $k => &$v) {
             $v = remove_scripts($v);
         }
     }
     if (!is_array($task_data)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $dd = getDateValue(array_var($_POST, 'task_due_date', ''));
         if ($dd instanceof DateTimeValue) {
             $duetime = getTimeValue(array_var($_POST, 'task_due_time'));
             if (is_array($duetime)) {
                 $dd->setHour(array_var($duetime, 'hours'));
                 $dd->setMinute(array_var($duetime, 'mins'));
             }
             $task->setUseDueTime(is_array($duetime));
         }
         $sd = getDateValue(array_var($_POST, 'task_start_date', ''));
         if ($sd instanceof DateTimeValue) {
             $starttime = getTimeValue(array_var($_POST, 'task_start_time'));
             if (is_array($starttime)) {
                 $sd->setHour(array_var($starttime, 'hours'));
                 $sd->setMinute(array_var($starttime, 'mins'));
             }
             $task->setUseStartTime(is_array($starttime));
         }
         $time_estimate = array_var($_POST, 'hours', 0) * 60 + array_var($_POST, 'minutes', 0);
         if (config_option("wysiwyg_tasks")) {
             $text_post = preg_replace("/[\n|\r|\n\r]/", '', array_var($_POST, 'text', ''));
         } else {
             $text_post = array_var($_POST, 'text', '');
         }
         $task_data = array('milestone_id' => array_var($_REQUEST, 'milestone_id', 0), 'project_id' => 1, 'name' => array_var($_REQUEST, 'name', ''), 'assigned_to_contact_id' => array_var($_REQUEST, 'assigned_to_contact_id', '0'), 'selected_members_ids' => json_decode(array_var($_POST, 'members', null)), 'parent_id' => array_var($_REQUEST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => $text_post, 'start_date' => $sd, 'due_date' => $dd, 'time_estimate' => $time_estimate, 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'percent_completed' => array_var($_POST, "percent_completed", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification_subscribers' => user_config_option("can notify subscribers"));
         // array
         if (Plugins::instance()->isActivePlugin('mail')) {
             $from_email = array_var($_GET, 'from_email');
             $email = MailContents::findById($from_email);
             if ($email instanceof MailContent) {
                 $task_data['name'] = $email->getSubject();
                 $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody());
                 $task_data['selected_members_ids'] = $email->getMemberIds();
                 tpl_assign('from_email', $email);
             }
         }
         tpl_assign('additional_onsubmit', array_var($_REQUEST, 'additional_onsubmit'));
     }
     // if
     if (array_var($_GET, 'replace')) {
         ajx_replace(true);
     }
     tpl_assign('task_data', $task_data);
     tpl_assign('task', $task);
     tpl_assign('pending_task_id', 0);
     $subtasks = array();
     if (array_var($_POST, 'multi_assignment')) {
         $subtasks = json_decode(array_var($_POST, 'multi_assignment'), true);
     }
     tpl_assign('multi_assignment', $subtasks);
     if (is_array(array_var($_POST, 'task'))) {
         try {
             // order
             $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0)));
             try {
                 $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date'));
                 $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date'));
             } catch (Exception $e) {
                 throw new Exception(lang('date format error', date_format_tip(user_config_option('date_format'))));
             }
             if ($task_data['due_date'] instanceof DateTimeValue) {
                 $duetime = getTimeValue(array_var($_POST, '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($_POST, '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);
             }
             $err_msg = $this->setRepeatOptions($task_data);
             if ($err_msg) {
                 throw new Exception($err_msg);
             }
             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();
             $member_ids = json_decode(array_var($_POST, 'members'));
             $task->setFromAttributes($task_data);
             if (!can_task_assignee(logged_user())) {
                 flash_error(lang('no access permissions'));
                 ajx_current("empty");
                 return;
             }
             $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0);
             $task->setTimeEstimate($totalMinutes);
             $id = array_var($_GET, 'id', 0);
             if ($task instanceof TemplateTask) {
                 //evt_add("template task added", array("id_template_task" => $file->getId()));
                 $parent = TemplateTasks::findById($id);
                 if ($parent instanceof TemplateTask) {
                     $task->setParentId($id);
                     $member_ids = $parent->getMemberIds();
                 }
                 //template id
                 $task->setTemplateId($template_id);
             } else {
                 $parent = ProjectTasks::findById($id);
                 if ($parent instanceof ProjectTask) {
                     $task->setParentId($id);
                     $member_ids = $parent->getMemberIds();
                 }
             }
             if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) {
                 flash_error(lang('task child of child error'));
                 ajx_current("empty");
                 return;
             }
             if ($task instanceof TemplateTask) {
                 $task->setSessionId(logged_user()->getId());
             }
             DB::beginWork();
             $task->save();
             // dependencies
             if (config_option('use tasks dependencies')) {
                 $previous_tasks = array_var($task_data, 'previous');
                 if (is_array($previous_tasks)) {
                     foreach ($previous_tasks as $ptask) {
                         if ($ptask == $task->getId()) {
                             continue;
                         }
                         $dep = ProjectTaskDependencies::findById(array('previous_task_id' => $ptask, 'task_id' => $task->getId()));
                         if (!$dep instanceof ProjectTaskDependency) {
                             $dep = new ProjectTaskDependency();
                             $dep->setPreviousTaskId($ptask);
                             $dep->setTaskId($task->getId());
                             $dep->save();
                         }
                     }
                 }
             }
             if (array_var($_GET, 'copyId', 0) > 0) {
                 // copy remaining stuff from the task with id copyId
                 $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId'));
                 if ($toCopy instanceof ProjectTask) {
                     ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false));
                 }
             }
             // if task is added from task view -> add subscribers
             if (array_var($task_data, 'inputtype') == 'taskview') {
                 if (!isset($_POST['subscribers'])) {
                     $_POST['subscribers'] = array();
                 }
                 $_POST['subscribers']['user_' . logged_user()->getId()] = '1';
                 if ($task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())->getUserType()) {
                     $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = '1';
                 }
             }
             // Add assigned user to the subscibers list
             if (isset($_POST['subscribers']) && $task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())) {
                 $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = '1';
             }
             //Link objects
             $object_controller = new ObjectController();
             if ($task instanceof TemplateTask) {
                 //if(!empty($member_ids)){
                 $object_controller->add_to_members($task, $member_ids, null, false);
                 //}
             } else {
                 $object_controller->add_to_members($task, $member_ids);
             }
             $is_template = $task instanceof TemplateTask;
             $object_controller->add_subscribers($task, null, !$is_template);
             $object_controller->link_to_new_object($task);
             $object_controller->add_custom_properties($task);
             $object_controller->add_reminders($task);
             if (config_option('repeating_task') == 1) {
                 $opt_rep_day['saturday'] = false;
                 $opt_rep_day['sunday'] = false;
                 if (array_var($task_data, 'repeat_saturdays', false)) {
                     $opt_rep_day['saturday'] = true;
                 }
                 if (array_var($task_data, 'repeat_sundays', false)) {
                     $opt_rep_day['sunday'] = true;
                 }
                 $this->repetitive_task($task, $opt_rep_day);
             }
             if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) {
                 $subtasks = array_var($_POST, 'multi_assignment');
                 Hook::fire('save_subtasks', $task, $subtasks);
             }
             //for calculate member status we save de task again after the object have the members
             $task->save();
             DB::commit();
             // save subtasks added in 'subtasks' tab
             DB::beginWork();
             $sub_tasks_to_log = $this->saveSubtasks($task, array_var($task_data, 'subtasks'), $member_ids);
             DB::commit();
             foreach ($sub_tasks_to_log['add'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_ADD);
             }
             foreach ($sub_tasks_to_log['edit'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_EDIT);
             }
             foreach ($sub_tasks_to_log['trash'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_TRASH);
             }
             //Send Template task to view
             if ($task instanceof TemplateTask) {
                 $objectId = $task->getObjectId();
                 $id = $task->getId();
                 $objectTypeName = $task->getObjectTypeName();
                 $objectName = $task->getObjectName();
                 $manager = get_class($task->manager());
                 $milestoneId = $task instanceof TemplateTask ? $task->getMilestoneId() : '0';
                 $subTasks = array();
                 $parentId = $task->getParentId();
                 $ico = "ico-task";
                 $action = "add";
                 $object = TemplateController::prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico);
                 $template_task_data = array('object' => $object);
                 if (array_var($_REQUEST, 'additional_tt_params')) {
                     $additional_tt_params = json_decode(str_replace("'", '"', array_var($_REQUEST, 'additional_tt_params')), true);
                     foreach ($additional_tt_params as $k => $v) {
                         $template_task_data[$k] = $v;
                     }
                 }
                 if (!array_var($_REQUEST, 'modal')) {
                     evt_add("template object added", $template_task_data);
                 }
             }
             // notify asignee
             if (array_var($task_data, 'send_notification')) {
                 if ($task instanceof ProjectTask && $task->getAssignedToContactId() != $task->getAssignedById()) {
                     try {
                         Notifier::taskAssigned($task);
                     } catch (Exception $e) {
                         evt_add("debug", $e->getMessage());
                     }
                     // try
                 }
                 // notify asignee for subtasks
                 foreach ($sub_tasks_to_log['assigned'] as $st_to_log) {
                     if ($st_to_log instanceof ProjectTask && $st_to_log->getAssignedToContactId() != $st_to_log->getAssignedById()) {
                         try {
                             Notifier::taskAssigned($st_to_log);
                         } catch (Exception $e) {
                             evt_add("debug", $e->getMessage());
                         }
                         // try
                     }
                 }
             }
             //notify subscribers
             $isSilent = true;
             if (array_var($task_data, 'send_notification_subscribers')) {
                 $isSilent = false;
             }
             ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD, null, $isSilent);
             if (array_var($_REQUEST, 'modal')) {
                 ajx_current("empty");
                 $this->setLayout("json");
                 $this->setTemplate(get_template_path("empty"));
                 // reload task info because plugins may have updated some task info (for example: name prefix)
                 if ($is_template) {
                     $task = TemplateTasks::findById($task->getId());
                 } else {
                     $task = ProjectTasks::findById($task->getId());
                 }
                 $params = array('msg' => lang('success add task list', $task->getObjectName()), 'task' => $task->getArrayInfo(), 'reload' => array_var($_REQUEST, 'reload'));
                 if ($task instanceof TemplateTask) {
                     $params['msg'] = lang('success add template', $task->getObjectName());
                     $params['object'] = $template_task_data['object'];
                 }
                 print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx'));
             } else {
                 if ($task instanceof TemplateTask) {
                     flash_success(lang('success add template', $task->getObjectName()));
                 } else {
                     flash_success(lang('success add task list', $task->getObjectName()));
                 }
                 if (array_var($task_data, 'inputtype') != 'taskview') {
                     ajx_current("back");
                 } else {
                     ajx_current("reload");
                 }
             }
         } catch (Exception $e) {
             DB::rollback();
             if (array_var($_REQUEST, 'modal')) {
                 $this->setLayout("json");
                 $this->setTemplate(get_template_path("empty"));
                 print_modal_json_response(array('errorCode' => 1, 'errorMessage' => $e->getMessage(), 'showMessage' => 1), true, array_var($_REQUEST, 'use_ajx'));
             } else {
                 flash_error($e->getMessage());
             }
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #8
0
 function instantiate()
 {
     $id = get_id();
     $template = COTemplates::findById($id);
     if (!$template instanceof COTemplate) {
         flash_error(lang("template dnx"));
         ajx_current("empty");
         return;
     }
     $parameters = TemplateParameters::getParametersByTemplate($id);
     $parameterValues = array_var($_POST, 'parameterValues');
     if (count($parameters) > 0 && !isset($parameterValues)) {
         ajx_current("back");
         return;
     }
     $objects = $template->getObjects();
     foreach ($objects as $object) {
         if (!$object instanceof ProjectDataObject) {
             continue;
         }
         // copy object
         $copy = $object->copy();
         if ($copy->columnExists('is_template')) {
             $copy->setColumnValue('is_template', false);
         }
         if ($copy instanceof ProjectTask) {
             // don't copy parent task and milestone
             $copy->setMilestoneId(0);
             $copy->setParentId(0);
         }
         $copy->save();
         $wsId = array_var($_POST, 'project_id', active_or_personal_project()->getId());
         // if specified, set workspace
         $workspace = Projects::findById($wsId);
         if (!$workspace instanceof Project) {
             $workspace = active_or_personal_project();
         }
         $copy->addToWorkspace($workspace);
         // add object tags and specified tags
         $tags = implode(',', $object->getTagNames());
         $copy->setTagsFromCSV($tags . "," . array_var($_POST, 'tags'));
         // copy linked objects
         $copy->copyLinkedObjectsFrom($object);
         // copy subtasks if applicable
         if ($copy instanceof ProjectTask) {
             ProjectTasks::copySubTasks($object, $copy, false);
             $manager = new ProjectTask();
         } else {
             if ($copy instanceof ProjectMilestone) {
                 ProjectMilestones::copyTasks($object, $copy, false);
                 $manager = new ProjectMilestone();
             }
         }
         // copy custom properties
         $copy->copyCustomPropertiesFrom($object);
         // set property values as defined in template
         $objProp = TemplateObjectProperties::getPropertiesByTemplateObject($id, $object->getId());
         foreach ($objProp as $property) {
             $propName = $property->getProperty();
             $value = $property->getValue();
             if ($manager->getColumnType($propName) == DATA_TYPE_STRING) {
                 if (is_array($parameterValues)) {
                     foreach ($parameterValues as $param => $val) {
                         $value = str_replace('{' . $param . '}', $val, $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) {
                         $dateParam = substr($value, 1, strpos($value, '}') - 1);
                         $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);
                         $date = $parameterValues[$dateParam];
                         $date = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $date);
                         $value = $date->add($dateUnit, $dateNum);
                     }
                 } else {
                     if ($manager->getColumnType($propName) == DATA_TYPE_INTEGER) {
                         if (is_array($parameterValues)) {
                             foreach ($parameterValues as $param => $val) {
                                 $value = str_replace('{' . $param . '}', $val, $value);
                             }
                         }
                     }
                 }
             }
             if ($value != '') {
                 $copy->setColumnValue($propName, $value);
                 $copy->save();
             }
         }
         //copy assigned to company if applicable
         if ($copy->getAssignedToUserId() != 0) {
             $copy->setAssignedToCompanyId($copy->getAssignedTo()->getCompanyId());
             $copy->save();
         }
         // copy reminders
         $reminders = ObjectReminders::getByObject($object);
         foreach ($reminders as $reminder) {
             $copy_reminder = new ObjectReminder();
             $copy_reminder->setContext($reminder->getContext());
             $reminder_date = $copy->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($copy);
             $copy_reminder->setType($reminder->getType());
             $copy_reminder->setUserId($reminder->getUserId());
             $copy_reminder->save();
         }
     }
     if (is_array($parameters) && count($parameters) > 0) {
         ajx_current("back");
     } else {
         ajx_current("reload");
     }
 }
コード例 #9
0
 /**
  * Copies tasks from milestoneFrom to milestoneTo.
  *
  * @param ProjectMilestone $milestoneFrom
  * @param ProjectMilestone $milestoneTo
  */
 function copyTasks(ProjectMilestone $milestoneFrom, ProjectMilestone $milestoneTo, $as_template = false)
 {
     foreach ($milestoneFrom->getTasks() as $sub) {
         if ($sub->getParentId() != 0) {
             continue;
         }
         $new = ProjectTasks::createTaskCopy($sub);
         $new->setIsTemplate($as_template);
         $new->setMilestoneId($milestoneTo->getId());
         if ($sub->getIsTemplate()) {
             $new->setFromTemplateId($sub->getId());
         }
         $new->save();
         foreach ($sub->getWorkspaces() as $workspace) {
             if (ProjectTask::canAdd(logged_user(), $workspace)) {
                 $new->addToWorkspace($workspace);
             }
         }
         if (!$as_template && active_project() instanceof Project && ProjectTask::canAdd(logged_user(), active_project())) {
             $new->removeFromAllWorkspaces();
             $new->addToWorkspace(active_project());
         }
         $new->copyCustomPropertiesFrom($sub);
         $new->copyLinkedObjectsFrom($sub);
         $new->setTagsFromCSV(implode(",", $sub->getTagNames()));
         ProjectTasks::copySubTasks($sub, $new, $as_template);
     }
 }
コード例 #10
0
 /**
  * Copies subtasks from taskFrom to taskTo.
  *
  * @param ProjectTask $taskFrom
  * @param ProjectTask $taskTo
  */
 function copySubTasks(ProjectTask $taskFrom, ProjectTask $taskTo, $as_template = false)
 {
     foreach ($taskFrom->getSubTasks() as $sub) {
         $new = ProjectTasks::createTaskCopy($sub);
         $new->setIsTemplate($as_template);
         $new->setParentId($taskTo->getId());
         $new->setMilestoneId($taskTo->getMilestoneId());
         $new->setOrder(ProjectTasks::maxOrder($new->getParentId(), $new->getMilestoneId()));
         if ($sub->getIsTemplate()) {
             $new->setFromTemplateId($sub->getId());
         }
         $new->save();
         foreach ($taskTo->getWorkspaces() as $workspace) {
             if (ProjectTask::canAdd(logged_user(), $workspace)) {
                 $new->addToWorkspace($workspace);
             }
         }
         $new->copyCustomPropertiesFrom($sub);
         $new->copyLinkedObjectsFrom($sub);
         $new->setTagsFromCSV(implode(",", $sub->getTagNames()));
         ProjectTasks::copySubTasks($sub, $new, $as_template);
     }
 }