/** * 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; }
/** * render a requirement as HTML code for printing * * @author Andreas Simon * * @param resource $db * @param array $node the node to be printed * @param array $printingOptions * @param string $tocPrefix Prefix to be printed in TOC before title of node * @param int $level * @param int $tprojectID * * @return string $output HTML Code */ function renderRequirementNodeForPrinting(&$db, $node, &$printingOptions, $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 $reqStatusLabels; static $reqTypeLabels; 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', 'coverage' => 'coverage', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs'); $labels = init_labels($labels); $reqStatusLabels = init_labels($req_cfg->status_labels); $reqTypeLabels = init_labels($req_cfg->type_labels); $title_separator = config_get('gui_title_separator_1'); $req_mgr = new requirement_mgr($db); $tplan_mgr = new testplan($db); } $arrReq = $req_mgr->get_by_id($node['id']); $req = $arrReq[0]; $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']); $output = "<table class=\"req\"><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n"; if ($printingOptions['toc']) { $printingOptions['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 ($printingOptions['req_author']) { $author = tlUser::getById($db, $req['author_id']); $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['author'] . "</span></td><td> " . htmlspecialchars($author->getDisplayName()) . "</td></tr>\n"; } if ($printingOptions['req_status']) { $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['status'] . "</span></td>" . "<td>" . $reqStatusLabels[$req['status']] . "</td></tr>"; } if ($printingOptions['req_type']) { $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['type'] . "</span></td>" . "<td>" . $reqTypeLabels[$req['type']] . "</td></tr>"; } if ($printingOptions['req_coverage']) { $current = count($req_mgr->get_coverage($req['id'])); $expected = $req['expected_coverage']; $coverage = lang_get('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 ($printingOptions['req_scope']) { $output .= "<tr><td colspan=\"{$tableColspan}\"><span class=\"label\">" . $labels['scope'] . "</span><br/>" . $req['scope'] . "</td></tr>"; } if ($printingOptions['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>"; foreach ($relations['relations'] as $rel) { $output .= "{$rel['type_localized']}: <br/> " . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . " {$labels['status']}: " . "{$reqStatusLabels[$rel['related_req']['status']]} <br/>"; if ($req_cfg->relations->interproject_linking) { $output .= " {$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>"; } } $output .= "</td></tr>"; } } if ($printingOptions['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 .= htmlentities($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>"; } $output .= "</td></tr>"; } } if ($printingOptions['req_cf']) { //BUGID 2877 - Custom Fields linked to Req versions $linked_cf = $req_mgr->get_linked_cfields($req['id'], $req['version_id']); 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; }
if ($expected > 0) { $percentage = round(100 / $expected * $tc_coverage, 2); $padded_data = sprintf("%010d", $percentage); //bring all percentages to same length $coverage_string = "<!-- {$padded_data} --> {$percentage}% ({$tc_coverage}/{$expected})"; } $result[] = $coverage_string; } $result[] = $type_labels[$version['type']]; $result[] = $status_labels[$version['status']]; if ($relations_enabled) { $result[] = $relations; } // BUGID 2877 - Custom Fields linked to Req versions // get custom field values for this req version $linked_cfields = (array) $req_mgr->get_linked_cfields($id, $version['version_id']); foreach ($linked_cfields as $cf) { $verbose_type = trim($req_mgr->cfield_mgr->custom_field_types[$cf['type']]); $value = preg_replace('!\\s+!', ' ', htmlspecialchars($cf['value'], ENT_QUOTES, $charset)); // 20100921 - asimon - added datetime formatting and calendar week for date custom fields if ($verbose_type == 'date' && is_numeric($value) && $value != 0) { $value = strftime("{$date_format_cfg} ({$week_short} %W)", $value); } if ($verbose_type == 'datetime' && is_numeric($value) && $value != 0) { $value = strftime("{$time_format_cfg} ({$week_short} %W)", $value); } $result[] = $value; } $rows[] = $result; } }
// get type and status labels $type_labels = init_labels($req_cfg->type_labels); $status_labels = init_labels($req_cfg->status_labels); $labels2get = array('no' => 'No', 'yes' => 'Yes', 'not_aplicable' => null, 'req_spec_short' => null, 'title' => null, 'version' => null, 'th_coverage' => null, 'frozen' => null, 'type' => null, 'status' => null, 'th_relations' => null, 'requirements' => null, 'number_of_reqs' => null, 'number_of_versions' => null); $labels = init_labels($labels2get); $gui->cfields4req = (array) $cfield_mgr->get_linked_cfields_at_design($args->tproject_id, 1, null, 'requirement', null, 'name'); $version_option = $args->all_versions ? requirement_mgr::ALL_VERSIONS : requirement_mgr::LATEST_VERSION; // array to gather table data row per row $rows = array(); foreach ($gui->reqIDs as $id) { // now get the rest of information for this requirement $req = $req_mgr->get_by_id($id, $version_option); // coverage data $tc_coverage = count($req_mgr->get_coverage($id)); // BUGID 3254: $linked_cfields = (array) $req_mgr->get_linked_cfields($id); // number of relations, if feature is enabled if ($relations_enabled) { $relations = $req_mgr->count_relations($id); $relations = "<!-- " . sprintf("%010d", $relations) . " -->" . $relations; } // create the link to display $title = htmlentities($req[0]['req_doc_id'], ENT_QUOTES, $charset) . $glue_char . htmlentities($req[0]['title'], ENT_QUOTES, $charset); // add html comment with title for easier sorting $linked_title = '<!-- ' . $title . ' -->' . '<a href="javascript:openLinkedReqWindow(' . $id . ')">' . $title . '</a>'; // reqspec-"path" to requirement $path = $req_mgr->tree_mgr->get_path($req[0]['srs_id']); foreach ($path as $key => $p) { $path[$key] = $p['name']; } $path = htmlentities(implode("/", $path), ENT_QUOTES, $charset);