/** * The singleton method * * @return Tracker_ResponseFactory An instance of canned response factory */ public static function instance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public function testImport() { $xml = simplexml_load_file(dirname(__FILE__) . '/_fixtures/TestTracker-1.xml'); $responses = array(); foreach ($xml->cannedResponses->cannedResponse as $index => $response) { $responses[] = Tracker_CannedResponseFactory::instance()->getInstanceFromXML($response); } $this->assertEqual($responses[0]->title, 'new response'); $this->assertEqual($responses[0]->body, 'this is the message of the new canned response'); }
/** * Creates a Tracker Object * * @param SimpleXMLElement $xml containing the structure of the imported tracker * @param int $groupId - id of the project into which the tracker is imported * @param string $name of the tracker given by the user * @param string $description of the tracker given by the user * @param string $itemname - short_name of the tracker given by the user * * @return Tracker Object */ protected function getInstanceFromXML($xml, $groupId, $name, $description, $itemname) { // set general settings // real id will be set during Database update $att = $xml->attributes(); $row = array('id' => 0, 'name' => $name, 'group_id' => $groupId, 'description' => $description, 'item_name' => $itemname, 'submit_instructions' => (string) $xml->submit_instructions, 'browse_instructions' => (string) $xml->browse_instructions, 'status' => '', 'deletion_date' => '', 'color' => (string) $xml->color); $row['allow_copy'] = isset($att['allow_copy']) ? (int) $att['allow_copy'] : 0; $row['instantiate_for_new_projects'] = isset($att['instantiate_for_new_projects']) ? (int) $att['instantiate_for_new_projects'] : 0; $row['log_priority_changes'] = isset($att['log_priority_changes']) ? (int) $att['log_priority_changes'] : 0; $row['stop_notification'] = isset($att['stop_notification']) ? (int) $att['stop_notification'] : 0; $tracker = $this->tracker_factory->getInstanceFromRow($row); // set canned responses if (isset($xml->cannedResponses)) { foreach ($xml->cannedResponses->cannedResponse as $index => $response) { $tracker->cannedResponses[] = $this->canned_response_factory->getInstanceFromXML($response); } } // set formElements foreach ($xml->formElements->formElement as $index => $elem) { $tracker->formElements[] = $this->formelement_factory->getInstanceFromXML($tracker, $elem, $this->xmlFieldsMapping); } // set semantics if (isset($xml->semantics)) { foreach ($xml->semantics->semantic as $xml_semantic) { $semantic = $this->semantic_factory->getInstanceFromXML($xml_semantic, $this->xmlFieldsMapping, $tracker); if ($semantic) { $tracker->semantics[] = $semantic; } } } /* * Legacy compatibility * * All new Tuleap versions will not export dependencies but rules instead. * However, we still want to be able to import old xml files. * * SimpleXML does not allow for nodes to be moved so have to recursively * generate rules from the dependencies data. */ if (isset($xml->dependencies)) { $list_rules = null; if (!isset($xml->rules)) { $list_rules = $xml->addChild('rules')->addChild('list_rules'); } elseif (!isset($xml->rules->list_rules)) { $list_rules = $xml->rules->addChild('list_rules', $xml->dependencies); } if ($list_rules !== null) { foreach ($xml->dependencies->rule as $old_rule) { $source_field_attributes = $old_rule->source_field->attributes(); $target_field_attributes = $old_rule->target_field->attributes(); $source_value_attributes = $old_rule->source_value->attributes(); $target_value_attributes = $old_rule->target_value->attributes(); $new_rule = $list_rules->addChild('rule', $old_rule); $new_rule->addChild('source_field')->addAttribute('REF', $source_field_attributes['REF']); $new_rule->addChild('target_field')->addAttribute('REF', $target_field_attributes['REF']); $new_rule->addChild('source_value')->addAttribute('REF', $source_value_attributes['REF']); $new_rule->addChild('target_value')->addAttribute('REF', $target_value_attributes['REF']); } } } //set field rules if (isset($xml->rules)) { $tracker->rules = $this->rule_factory->getInstanceFromXML($xml->rules, $this->xmlFieldsMapping, $tracker); } // set report if (isset($xml->reports)) { foreach ($xml->reports->report as $report) { $tracker->reports[] = $this->report_factory->getInstanceFromXML($report, $this->xmlFieldsMapping, $groupId); } } //set workflow if (isset($xml->workflow->field_id)) { $tracker->workflow = $this->workflow_factory->getInstanceFromXML($xml->workflow, $this->xmlFieldsMapping, $tracker); } //set permissions if (isset($xml->permissions->permission)) { $allowed_tracker_perms = array(Tracker::PERMISSION_ADMIN, Tracker::PERMISSION_FULL, Tracker::PERMISSION_SUBMITTER, Tracker::PERMISSION_ASSIGNEE, Tracker::PERMISSION_SUBMITTER_ONLY); $allowed_field_perms = array('PLUGIN_TRACKER_FIELD_READ', 'PLUGIN_TRACKER_FIELD_UPDATE', 'PLUGIN_TRACKER_FIELD_SUBMIT'); foreach ($xml->permissions->permission as $permission) { switch ((string) $permission['scope']) { case 'tracker': //tracker permissions $ugroup = (string) $permission['ugroup']; $type = (string) $permission['type']; if (isset($GLOBALS['UGROUPS'][$ugroup]) && in_array($type, $allowed_tracker_perms)) { $tracker->setCachePermission($GLOBALS['UGROUPS'][$ugroup], $type); } break; case 'field': //field permissions $ugroup = (string) $permission['ugroup']; $REF = (string) $permission['REF']; $type = (string) $permission['type']; if (isset($this->xmlFieldsMapping[$REF]) && isset($GLOBALS['UGROUPS'][$ugroup]) && in_array($type, $allowed_field_perms)) { $this->xmlFieldsMapping[$REF]->setCachePermission($GLOBALS['UGROUPS'][$ugroup], $type); } break; default: break; } } } return $tracker; }
protected function displayAdminResponse(TrackerManager $tracker_manager, $request, $current_user) { if ($response = Tracker_CannedResponseFactory::instance()->getCannedResponse($this->tracker, (int) $request->get('edit'))) { $hp = Codendi_HTMLPurifier::instance(); $this->tracker->displayAdminItemHeader($tracker_manager, 'editcanned', array(array('url' => TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => 'admin-canned', 'edit' => (int) $response->id)), 'title' => $response->title, 'description' => ''))); //Display creation form echo '<h3>' . $GLOBALS['Language']->getText('plugin_tracker_admin_index', 'modify_cannedresponse') . '</h3>'; echo '<p>'; echo $GLOBALS['Language']->getText('plugin_tracker_include_canned', 'save_time'); echo '<p>'; echo '<form action="' . TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => 'admin-canned', 'update' => (int) $response->id)) . '" method="POST">'; echo '<b>' . $GLOBALS['Language']->getText('plugin_tracker_include_canned', 'title') . ':</b><br />'; echo '<input type="text" name="title" value="' . $hp->purify($response->title, CODENDI_PURIFIER_CONVERT_HTML) . '" size="50">'; echo '<p>'; echo '<b>' . $GLOBALS['Language']->getText('plugin_tracker_include_canned', 'message_body') . '</b><br />'; echo '<textarea name="body" rows="20" cols="65" wrap="hard">' . $hp->purify($response->body, CODENDI_PURIFIER_CONVERT_HTML) . '</textarea>'; echo '<p>'; echo '<input type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" />'; echo '</from>'; echo '<p><a href="' . TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => 'admin-canned')) . '">« Go back to canned responses</a></p>'; $this->tracker->displayFooter($tracker_manager); exit; } }
/** * 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; }
/** * @return Tracker_CannedResponseFactory */ public function getCannedResponseFactory() { return Tracker_CannedResponseFactory::instance(); }