/** * 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; }
$node['version_id'] = $args->req_version_id; $node['revision'] = $args->req_revision; $gui = new stdClass(); $gui->object_name = ''; $gui->object_name = $node['name']; $gui->page_title = sprintf(lang_get('print_requirement'), $node['name']); $gui->tproject_name = $args->tproject_name; $gui->tproject_id = $args->tproject_id; $gui->req_id = $args->req_id; $gui->req_version_id = $args->req_version_id; $gui->req_revision = $args->req_revision; // Struture defined in printDocument.php $options = 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 = ''; $text2print .= renderHTMLHeader($gui->page_title, $_SESSION['basehref'], SINGLE_REQ); $text2print .= renderReqForPrinting($db, $node, $options, null, 0, $args->tproject_id); echo $text2print; /* function: init_args args: returns: */ function init_args() { $_REQUEST = strings_stripSlashes($_REQUEST); $args = new stdClass(); $args->req_id = isset($_REQUEST['req_id']) ? intval($_REQUEST['req_id']) : 0; $args->req_version_id = isset($_REQUEST['req_version_id']) ? intval($_REQUEST['req_version_id']) : 0; $args->req_revision = isset($_REQUEST['req_revision']) ? intval($_REQUEST['req_revision']) : 0; $args->tproject_id = isset($_SESSION['testprojectID']) ? intval($_SESSION['testprojectID']) : 0;
$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(); echo $text2print; /* function: init_args args: returns: */ function init_args(&$treeMgr) { $_REQUEST = strings_stripSlashes($_REQUEST); $args = new stdClass(); $args->reqspec_id = isset($_REQUEST['reqspec_id']) ? intval($_REQUEST['reqspec_id']) : 0;