/** * * @return Tracker_RuleFactory */ function getRuleFactory() { return Tracker_RuleFactory::instance(); }
/** * create - use this to create a new Tracker in the database. * * @param Project $project_id the group id of the new tracker * @param int $project_id_template the template group id (used for the copy) * @param int $id_template the template tracker id * @param string $name the name of the new tracker * @param string $description the description of the new tracker * @param string $itemname the itemname of the new tracker * @param Array $ugroup_mapping the ugroup mapping * * @return mixed array(Tracker object, field_mapping array) or false on failure. */ function create($project_id, $project_id_template, $id_template, $name, $description, $itemname, $ugroup_mapping = false) { if ($this->validMandatoryInfoOnCreate($name, $description, $itemname, $project_id)) { // Get the template tracker $template_tracker = $this->getTrackerById($id_template); if (!$template_tracker) { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_common_type', 'invalid_tracker_tmpl')); return false; } $template_group = $template_tracker->getProject(); if (!$template_group || !is_object($template_group) || $template_group->isError()) { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_common_type', 'invalid_templ')); return false; } $project_id_template = $template_group->getId(); //Ask to dao to duplicate the tracker if ($id = $this->getDao()->duplicate($id_template, $project_id, $name, $description, $itemname)) { // Duplicate Form Elements $field_mapping = Tracker_FormElementFactory::instance()->duplicate($id_template, $id, $ugroup_mapping); if ($ugroup_mapping) { $duplicate_type = PermissionsDao::DUPLICATE_NEW_PROJECT; } else { if ($project_id == $project_id_template) { $duplicate_type = PermissionsDao::DUPLICATE_SAME_PROJECT; } else { $duplicate_type = PermissionsDao::DUPLICATE_OTHER_PROJECT; } } // Duplicate workflow foreach ($field_mapping as $mapping) { if ($mapping['workflow']) { WorkflowFactory::instance()->duplicate($id_template, $id, $mapping['from'], $mapping['to'], $mapping['values'], $field_mapping, $ugroup_mapping, $duplicate_type); } } // Duplicate Reports Tracker_ReportFactory::instance()->duplicate($id_template, $id, $field_mapping); // Duplicate Semantics Tracker_SemanticFactory::instance()->duplicate($id_template, $id, $field_mapping); // Duplicate Canned Responses Tracker_CannedResponseFactory::instance()->duplicate($id_template, $id); //Duplicate field dependencies Tracker_RuleFactory::instance()->duplicate($id_template, $id, $field_mapping); $tracker = $this->getTrackerById($id); // Process event that tracker is created $em =& EventManager::instance(); $pref_params = array('atid_source' => $id_template, 'atid_dest' => $id); $em->processEvent('Tracker_created', $pref_params); //Duplicate Permissions $this->duplicatePermissions($id_template, $id, $ugroup_mapping, $field_mapping, $duplicate_type); $this->postCreateActions($tracker); return array('tracker' => $tracker, 'field_mapping' => $field_mapping); } } return false; }