예제 #1
0
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, &$argsObj)
{
    $req_spec_mgr = new requirement_spec_mgr($dbHandler);
    $tproject_mgr = new testproject($dbHandler);
    $commandMgr = new reqSpecCommands($dbHandler);
    $gui = $commandMgr->initGuiBean();
    $gui->refreshTree = $argsObj->refreshTree;
    $gui->req_spec_cfg = config_get('req_spec_cfg');
    $gui->req_cfg = config_get('req_cfg');
    $gui->external_req_management = $gui->req_cfg->external_req_management == ENABLED ? 1 : 0;
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = $argsObj->user->hasRight($dbHandler, "mgt_modify_req", $argsObj->tproject_id);
    $gui->req_spec = $req_spec_mgr->get_by_id($argsObj->req_spec_id);
    $gui->revCount = $req_spec_mgr->getRevisionsCount($argsObj->req_spec_id);
    $gui->req_spec_id = $argsObj->req_spec_id;
    $gui->parentID = $argsObj->req_spec_id;
    $gui->req_spec_revision_id = $gui->req_spec['revision_id'];
    $gui->name = $gui->req_spec['title'];
    $gui->tproject_id = $argsObj->tproject_id;
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->main_descr = lang_get('req_spec_short') . config_get('gui_title_separator_1') . "[{$gui->req_spec['doc_id']}] :: " . $gui->req_spec['title'];
    $gui->refresh_tree = 'no';
    $gui->cfields = $req_spec_mgr->html_table_of_custom_field_values($argsObj->req_spec_id, $gui->req_spec_revision_id, $argsObj->tproject_id);
    $gui->attachments = $req_spec_mgr->getAttachmentInfos($argsObj->req_spec_id);
    $gui->requirements_count = $req_spec_mgr->get_requirements_count($argsObj->req_spec_id);
    $gui->reqSpecTypeDomain = init_labels($gui->req_spec_cfg->type_labels);
    $prefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->direct_link = $_SESSION['basehref'] . 'linkto.php?tprojectPrefix=' . urlencode($prefix) . '&item=reqspec&id=' . urlencode($gui->req_spec['doc_id']);
    $gui->actions = initializeActions($gui);
    return $gui;
}
/**
 * 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, $rsLevel, $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;
    static $basehref;
    $output = '';
    $reLevel = $rsLevel > 0 ? $rsLevel : 1;
    if (!$req_spec_mgr) {
        $basehref = $_SESSION['basehref'];
        $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', 'attached_files' => 'attached_files', '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 = '';
    if ($options['headerNumbering']) {
        $docHeadingNumbering = "{$tocPrefix}. ";
    }
    if ($options['docType'] != SINGLE_REQSPEC) {
        $output = '<p style="page-break-before: always"></p>';
    }
    // Remember that only H1 to H6 exists
    $reLevel = $reLevel > 6 ? 6 : $reLevel;
    $reLevel = $reLevel < 1 ? 1 : $reLevel;
    $output .= "<table class=\"req_spec\"><tr><th colspan=\"{$tableColspan}\">" . "<h{$reLevel} class=\"doclevel\"> <span class=\"label\">{$docHeadingNumbering}{$labels['requirements_spec']}:</span> " . $name . "</h{$reLevel}></th></tr>\n";
    if ($options['toc']) {
        $spacing = $reLevel == 2 ? "<br>" : "";
        $options['tocCode'] .= $spacing . '<b><p style="padding-left: ' . 10 * $reLevel . '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);
        // NEEDS REFACTOR
        $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>";
            }
        }
    }
    $attachSet = $req_spec_mgr->getAttachmentInfos($spec_id);
    if (count($attachSet)) {
        $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['attached_files'] . "</span></td><td><ul>";
        foreach ($attachSet as $item) {
            $fname = "";
            if ($item['title']) {
                $fname .= htmlspecialchars($item['title']) . " : ";
            }
            $fname .= htmlspecialchars($item['file_name']);
            $output .= "<li>{$fname}</li>";
        }
        $output .= "</ul></td></tr>";
    }
    $output .= "</table><br/>\n";
    return $output;
}