/** * render a requirement as HTML code for printing * * @author Andreas Simon * * @param resource $db * @param array $node the node to be printed * @param array $options * displayDates: true display creation and last edit date (including hh:mm:ss) * * @param string $tocPrefix Prefix to be printed in TOC before title of node * @param int $level * @param int $tprojectID * * @return string $output HTML Code * * @internal revisions * */ function renderReqForPrinting(&$db, $node, &$options, $tocPrefix, $level, $tprojectID) { static $tableColspan; static $firstColWidth; static $labels; static $title_separator; static $req_mgr; static $tplan_mgr; static $req_cfg; static $req_spec_cfg; static $decodeReq; static $force = null; if (!$req_mgr) { $req_cfg = config_get('req_cfg'); $req_spec_cfg = config_get('req_spec_cfg'); $firstColWidth = '20%'; $tableColspan = 2; $labels = array('requirement' => 'requirement', 'status' => 'status', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'not_aplicable' => 'not_aplicable', 'coverage' => 'coverage', 'last_edit' => 'last_edit', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs', 'version' => 'version', 'revision' => 'revision'); $labels = init_labels($labels); $decodeReq = array(); $decodeReq['status'] = init_labels($req_cfg->status_labels); $decodeReq['type'] = init_labels($req_cfg->type_labels); $force['displayVersion'] = isset($options['displayVersion']) ? $options['displayVersion'] : false; $force['displayLastEdit'] = isset($options['displayLastEdit']) ? $options['displayLastEdit'] : false; $title_separator = config_get('gui_title_separator_1'); $req_mgr = new requirement_mgr($db); $tplan_mgr = new testplan($db); } $versionID = isset($node['version_id']) ? intval($node['version_id']) : requirement_mgr::LATEST_VERSION; $revision = isset($node['revision']) ? intval($node['revision']) : null; if (is_null($revision)) { // will get last revision of requested req version $dummy = $req_mgr->get_by_id($node['id'], $versionID); } else { $dummy = $req_mgr->get_version_revision($versionID, array('number' => $revision)); if (!is_null($dummy)) { // do this way instead of using SQL alias on get_version_revision(), in order // to avoid issues (potential not confirmed)on different DBMS. $dummy[0]['id'] = $dummy[0]['req_id']; } } $req = $dummy[0]; // update with values got from req, this is needed if user did not provide it $versionID = $req['version_id']; $revision = $req['revision']; $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']); $table_style = ""; if (isset($options['docType']) && $options['docType'] == SINGLE_REQ) { $table_style = "style=\"margin-left: 0;\""; } $output = "<table class=\"req\" {$table_style}><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n"; if ($force['displayVersion']) { foreach (array('version', 'revision') as $key) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels[$key] . ':</span></td>' . '<td>' . $req[$key] . "</td></tr>\n"; } } if ($options['toc']) { $options['tocCode'] .= '<p style="padding-left: ' . 15 * $level . 'px;"><a href="#' . prefixToHTMLID('req' . $node['id']) . '">' . $name . '</a></p>'; $output .= '<a name="' . prefixToHTMLID('req' . $node['id']) . '"></a>'; } if ($options['req_author']) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['author'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['author_id'])); if (isset($options['displayDates']) && $options['displayDates']) { $dummy = null; $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['creation_ts']); } $output .= "</td></tr>\n"; if ($req['modifier_id'] > 0) { // add updater if available and differs from author OR forced if ($force['displayLastEdit'] || $req['modifier_id'] != $req['modifier_id']) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['last_edit'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['modifier_id'])); if (isset($options['displayDates']) && $options['displayDates']) { $dummy = null; $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['modification_ts']); } $output .= "</td></tr>\n"; } } } foreach (array('status', 'type') as $key) { if ($options['req_' . $key]) { $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels[$key] . "</span></td>" . "<td>" . $decodeReq[$key][$req[$key]] . "</td></tr>"; } } if ($options['req_coverage']) { $current = count($req_mgr->get_coverage($req['id'])); $expected = $req['expected_coverage']; $coverage = $labels['not_aplicable'] . " ({$current}/0)"; if ($expected) { $percentage = round(100 / $expected * $current, 2); $coverage = "{$percentage}% ({$current}/{$expected})"; } $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['coverage'] . "</span></td>" . "<td>{$coverage}</td></tr>"; } if ($options['req_scope']) { $output .= "<tr><td colspan=\"{$tableColspan}\"> <br/>" . $req['scope'] . "</td></tr>"; } if ($options['req_relations']) { $relations = $req_mgr->get_relations($req['id']); if ($relations['num_relations']) { $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['relations'] . "</span></td><td>"; $filler = str_repeat(' ', 5); // MAGIC allowed foreach ($relations['relations'] as $rel) { $output .= "{$rel['type_localized']}: <br/>{$filler}" . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . "{$filler}{$labels['status']}: " . "{$decodeReq['status'][$rel['related_req']['status']]} <br/>"; if ($req_cfg->relations->interproject_linking) { $output .= "{$filler}{$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>"; } } $output .= "</td></tr>"; } } if ($options['req_linked_tcs']) { $req_coverage = $req_mgr->get_coverage($req['id']); if (count($req_coverage)) { $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['related_tcs'] . "</span></td>" . "<td>"; foreach ($req_coverage as $tc) { $output .= htmlspecialchars($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>"; } $output .= "</td></tr>"; } } if ($options['req_cf']) { $childID = is_null($revision) || $req['revision_id'] < 0 ? $req['version_id'] : $req['revision_id']; $linked_cf = $req_mgr->get_linked_cfields($req['id'], $childID); if ($linked_cf) { foreach ($linked_cf as $key => $cf) { $cflabel = htmlspecialchars($cf['label']); $value = htmlspecialchars($cf['value']); $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $cflabel . "</span></td>" . "<td>{$value}</td></tr>"; } } } $output .= "</table><br/>"; return $output; }