/** * render a complete tree, consisting of mixed requirement and req spec nodes, * as HTML code for printing * * @author Andreas Simon * * @param resource $db * @param array $node the node to be printed * @param array $options * @param string $tocPrefix Prefix to be printed in TOC before title of each node * @param int $level * @param int $tprojectID * @param int $user_id ID of user which shall be printed as author of the document * * @return string $output HTML Code */ function renderReqSpecTreeForPrinting(&$db, &$node, &$options, $tocPrefix, $rsCnt, $level, $user_id, $tplan_id = 0, $tprojectID = 0) { static $tree_mgr; static $map_id_descr; static $tplan_mgr; $code = null; if (!$tree_mgr) { $tplan_mgr = new testplan($db); $tree_mgr = new tree($db); $map_id_descr = $tree_mgr->node_types; } $verbose_node_type = $map_id_descr[$node['node_type_id']]; switch ($verbose_node_type) { case 'testproject': break; case 'requirement_spec': $tocPrefix .= (!is_null($tocPrefix) ? "." : '') . $rsCnt; $code .= renderReqSpecNodeForPrinting($db, $node, $options, $tocPrefix, $level, $tprojectID); break; case 'requirement': $tocPrefix .= (!is_null($tocPrefix) ? "." : '') . $rsCnt; $code .= renderReqForPrinting($db, $node, $options, $tocPrefix, $level, $tprojectID); break; } if (isset($node['childNodes']) && $node['childNodes']) { $childNodes = $node['childNodes']; $rsCnt = 0; $children_qty = sizeof($childNodes); for ($i = 0; $i < $children_qty; $i++) { $current = $childNodes[$i]; if (is_null($current)) { continue; } if (isset($current['node_type_id']) && $map_id_descr[$current['node_type_id']] == 'requirement_spec') { $rsCnt++; } $code .= renderReqSpecTreeForPrinting($db, $current, $options, $tocPrefix, $rsCnt, $level + 1, $user_id, $tplan_id, $tprojectID); } } if ($verbose_node_type == 'testproject') { if ($options['toc']) { $code = str_replace("{{INSERT_TOC}}", $options['tocCode'], $code); } } return $code; }
$args = init_args($tree_mgr); checkRights($db, $_SESSION['currentUser'], $args); $node = $tree_mgr->get_node_hierarchy_info($args->reqspec_id); $gui = new stdClass(); $gui->object_name = ''; $gui->object_name = $node['name']; $gui->page_title = sprintf(lang_get('print_requirement_specification'), $node['name']); $gui->tproject_name = $args->tproject_name; $gui->tproject_id = $args->tproject_id; $gui->reqspec_id = $args->reqspec_id; // Struture defined in printDocument.php $options = array('toc' => 0, 'req_spec_scope' => 1, 'req_spec_author' => 1, 'req_spec_type' => 1, 'req_spec_cf' => 1, 'req_spec_overwritten_count_reqs' => 1, 'headerNumbering' => 0, 'docType' => SINGLE_REQSPEC); $text2print = ''; $text2print .= renderHTMLHeader($gui->page_title, $_SESSION['basehref'], SINGLE_REQSPEC) . '<body>'; //$text2print .= '<div><h2>' . lang_get('req_specification') . '</h2></div>'; $text2print .= renderReqSpecNodeForPrinting($db, $node, $options, null, 0, $args->tproject_id); // now get all it's children (just requirements). $childrenReq = $reqspec_mgr->get_requirements($args->reqspec_id); if (!is_null($childrenReq) && $req_cfg->show_child_reqs_on_reqspec_print_view) { // IMPORTANT NOTICE: // 'docType' => 'SINGLE_REQ' among other things remove the indent on req table // that is present by default. // That's why we need to pass any other value. $reqPrintOpts = array('toc' => 0, 'req_linked_tcs' => 1, 'req_cf' => 1, 'req_scope' => 1, 'req_relations' => 1, 'req_coverage' => 1, 'req_status' => 1, 'req_type' => 1, 'req_author' => 1, 'displayVersion' => 1, 'displayDates' => 1, 'displayLastEdit' => 1, 'docType' => SINGLE_REQ); $text2print .= '<div><h2>' . lang_get('reqs') . '</h2></div>'; $loop2do = count($childrenReq); for ($rdx = 0; $rdx < $loop2do; $rdx++) { $text2print .= renderReqForPrinting($db, $childrenReq[$rdx], $reqPrintOpts, null, 0, $args->tproject_id); } } $text2print .= renderEOF();