/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj)
{
    $tproject_mgr = new testproject($dbHandler);
    $itemMgr = new requirement_spec_mgr($dbHandler);
    $commandMgr = new reqSpecCommands($dbHandler);
    $gui = $commandMgr->initGuiBean();
    $gui->itemCfg = config_get('req_spec_cfg');
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = $argsObj->hasRight($dbHandler, "mgt_modify_req", $argsObj->tproject_id);
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->glueChar = config_get('testcase_cfg')->glue_character;
    $gui->pieceSep = config_get('gui_title_separator_1');
    $gui->item_id = $argsObj->item_id;
    $info = $itemMgr->getRevisionByID($gui->item_id, array('decode_user' => true));
    $gui->item = $info;
    $gui->cfields = $itemMgr->html_table_of_custom_field_values(null, $gui->item_id, $argsObj->tproject_id);
    $gui->show_title = false;
    $gui->main_descr = lang_get('req_spec') . $gui->pieceSep . $gui->item['name'];
    $gui->showContextInfo = $argsObj->showContextInfo;
    if ($gui->showContextInfo) {
        $gui->parent_descr = lang_get('req_spec_short') . $gui->pieceSep . $gui->item['name'];
    }
    $gui->itemSpecStatus = null;
    $gui->itemTypeDomain = init_labels($gui->itemCfg->type_labels);
    return $gui;
}
Example #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 $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;
}