Esempio n. 1
0
/**
 * render a requirement specification node 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 node
 * @param int $level
 * @param int $tprojectID
 * 
 * @return string $output HTML Code
 */
function renderReqSpecNodeForPrinting(&$db, &$node, &$options, $tocPrefix, $level, $tprojectID)
{
    static $tableColspan;
    static $firstColWidth;
    static $labels;
    static $title_separator;
    static $req_spec_mgr;
    static $tplan_mgr;
    static $req_spec_cfg;
    static $reqSpecTypeLabels;
    static $nodeTypes;
    $output = '';
    $level = $level > 0 ? $level : 1;
    if (!$req_spec_mgr) {
        $req_spec_cfg = config_get('req_spec_cfg');
        $firstColWidth = '20%';
        $tableColspan = 2;
        $labels = array('requirements_spec' => 'requirements_spec', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'overwritten_count' => 'req_total', 'coverage' => 'coverage', 'revision' => 'revision', 'undefined_req_spec_type' => 'undefined_req_spec_type', 'custom_field' => 'custom_field', 'not_aplicable' => 'not_aplicable');
        $labels = init_labels($labels);
        $reqSpecTypeLabels = init_labels($req_spec_cfg->type_labels);
        $title_separator = config_get('gui_title_separator_1');
        $req_spec_mgr = new requirement_spec_mgr($db);
        $tplan_mgr = new testplan($db);
        $nodeTypes = array_flip($tplan_mgr->tree_manager->get_available_node_types());
    }
    switch ($nodeTypes[$node['node_type_id']]) {
        case 'requirement_spec_revision':
            $spec = $req_spec_mgr->getRevisionByID($node['id']);
            $spec_id = $spec['parent_id'];
            $who = array('parent_id' => $spec['parent_id'], 'item_id' => $spec['id'], 'tproject_id' => $spec['testproject_id']);
            break;
        case 'requirement_spec':
            $spec = $req_spec_mgr->get_by_id($node['id']);
            $spec_id = $spec['id'];
            $who = array('parent_id' => $spec['id'], 'item_id' => $spec['revision_id'], 'tproject_id' => $spec['testproject_id']);
            break;
    }
    $name = htmlspecialchars($spec['doc_id'] . $title_separator . $spec['title']);
    $docHeadingNumbering = $options['headerNumbering'] ? "{$tocPrefix}. " : '';
    if ($options['docType'] != SINGLE_REQSPEC) {
        $output = '<p style="page-break-before: always"></p>';
    }
    $output .= "<table class=\"req_spec\"><tr><th colspan=\"{$tableColspan}\">" . "<h{$level} class=\"doclevel\"> <span class=\"label\">{$docHeadingNumbering}{$labels['requirements_spec']}:</span> " . $name . "</th></tr></h{$level}>\n";
    if ($options['toc']) {
        $spacing = $level == 2 ? "<br>" : "";
        $options['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $level . 'px;">' . '<a href="#' . prefixToHTMLID($tocPrefix) . '">' . $docHeadingNumbering . $name . "</a></p></b>\n";
        $output .= "<a name='" . prefixToHTMLID($tocPrefix) . "'></a>\n";
    }
    $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['revision'] . "</span></td><td> " . $spec['revision'] . "</td></tr>\n";
    if ($options['req_spec_author']) {
        // get author name for node
        $author = tlUser::getById($db, $spec['author_id']);
        $whois = is_null($author) ? lang_get('undefined') : $author->getDisplayName();
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['author'] . "</span></td><td> " . htmlspecialchars($whois) . "</td></tr>\n";
    }
    if ($options['req_spec_type']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['type'] . "</span></td>" . "<td>";
        if (isset($reqSpecTypeLabels[$spec['type']])) {
            $output .= $reqSpecTypeLabels[$spec['type']];
        } else {
            $output .= sprintf($labels['undefined_req_spec_type'], $spec['type']);
        }
        $output .= "</td></tr>";
    }
    if ($options['req_spec_overwritten_count_reqs']) {
        $current = $req_spec_mgr->get_requirements_count($spec['id']);
        $expected = $spec['total_req'];
        $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['overwritten_count'] . " (" . $labels['coverage'] . ")</span></td>" . "<td>" . $coverage . "</td></tr>";
    }
    if ($options['req_spec_scope']) {
        $output .= "<tr><td colspan=\"{$tableColspan}\">" . $spec['scope'] . "</td></tr>";
    }
    if ($options['req_spec_cf']) {
        $linked_cf = $req_spec_mgr->get_linked_cfields($who);
        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/>\n";
    return $output;
}
Esempio n. 2
0
/**
 * render a requirement specification node 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 renderReqSpecNodeForPrinting(&$db, &$node, &$printingOptions, $tocPrefix, $level, $tprojectID)
{
    static $tableColspan;
    static $firstColWidth;
    static $labels;
    static $title_separator;
    static $req_spec_mgr;
    static $tplan_mgr;
    static $req_spec_cfg;
    static $reqSpecTypeLabels;
    if (!$req_spec_mgr) {
        $req_spec_cfg = config_get('req_spec_cfg');
        $firstColWidth = '20%';
        $tableColspan = 2;
        $labels = array('requirements_spec' => 'requirements_spec', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'overwritten_count' => 'req_total', 'coverage' => 'coverage', 'custom_field' => 'custom_field', 'not_aplicable' => 'not_aplicable');
        $labels = init_labels($labels);
        $reqSpecTypeLabels = init_labels($req_spec_cfg->type_labels);
        $title_separator = config_get('gui_title_separator_1');
        $req_spec_mgr = new requirement_spec_mgr($db);
        $tplan_mgr = new testplan($db);
    }
    $spec = $req_spec_mgr->get_by_id($node['id']);
    $name = htmlspecialchars($spec['doc_id'] . $title_separator . $spec['title']);
    $docHeadingNumbering = '';
    if ($printingOptions['headerNumbering']) {
        $docHeadingNumbering = "{$tocPrefix}. ";
    }
    $output = "<table class=\"req_spec\"><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$docHeadingNumbering}{$labels['requirements_spec']}:</span> " . $name . "</th></tr>\n";
    if ($printingOptions['toc']) {
        $spacing = $level == 2 ? "<br>" : "";
        $printingOptions['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $level . 'px;">' . '<a href="#' . prefixToHTMLID($tocPrefix) . '">' . $docHeadingNumbering . $name . "</a></p></b>\n";
        $output .= "<a name='" . prefixToHTMLID($tocPrefix) . "'></a>\n";
    }
    if ($printingOptions['req_spec_author']) {
        // get author name for node
        $author = tlUser::getById($db, $spec['author_id']);
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['author'] . "</span></td><td> " . htmlspecialchars($author->getDisplayName()) . "</td></tr>\n";
    }
    if ($printingOptions['req_spec_type']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['type'] . "</span></td>" . "<td>" . $reqSpecTypeLabels[$spec['type']] . "</td></tr>";
    }
    if ($printingOptions['req_spec_overwritten_count_reqs']) {
        $current = $req_spec_mgr->get_requirements_count($spec['id']);
        $expected = $spec['total_req'];
        $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['overwritten_count'] . " (" . $labels['coverage'] . ")</span></td>" . "<td>" . $coverage . "</td></tr>";
    }
    if ($printingOptions['req_spec_scope']) {
        $output .= "<tr><td colspan=\"{$tableColspan}\"><span class=\"label\">" . $labels['scope'] . "</span><br/>" . $spec['scope'] . "</td></tr>";
    }
    if ($printingOptions['req_spec_cf']) {
        $linked_cf = $req_spec_mgr->get_linked_cfields($spec['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/>\n";
    return $output;
}