Ejemplo n.º 1
0
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj)
{
    $tproject_mgr = new testproject($dbHandler);
    $req_mgr = new requirement_mgr($dbHandler);
    $commandMgr = new reqCommands($db);
    $gui = $commandMgr->initGuiBean();
    $gui->req_cfg = config_get('req_cfg');
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = has_rights($db, "mgt_modify_req");
    $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->req_id = $argsObj->req_id;
    $gui->req_versions = $req_mgr->get_by_id($gui->req_id);
    $gui->req = current($gui->req_versions);
    $gui->req_coverage = $req_mgr->get_coverage($gui->req_id);
    // This seems weird but is done to adapt template than can display multiple
    // requirements. This logic has been borrowed from test case versions management
    $gui->current_version[0] = array($gui->req);
    // BUGID 2877 - Custom Fields linked to Requirement Versions
    $gui->cfields_current_version[0] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $gui->req['version_id'], $argsObj->tproject_id);
    // Now CF for other Versions
    $gui->other_versions[0] = null;
    $gui->cfields_other_versions[] = null;
    if (count($gui->req_versions) > 1) {
        $gui->other_versions[0] = array_slice($gui->req_versions, 1);
        $loop2do = count($gui->other_versions[0]);
        for ($qdx = 0; $qdx < $loop2do; $qdx++) {
            $target_version = $gui->other_versions[0][$qdx]['version_id'];
            $gui->cfields_other_versions[0][$qdx] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $target_version, $argsObj->tproject_id);
        }
    }
    $gui->show_title = false;
    $gui->main_descr = lang_get('req') . $gui->pieceSep . $gui->req['title'];
    $gui->showReqSpecTitle = $argsObj->showReqSpecTitle;
    if ($gui->showReqSpecTitle) {
        $gui->parent_descr = lang_get('req_spec_short') . $gui->pieceSep . $gui->req['req_spec_title'];
    }
    // BUGID 2877 - Custom Fields linked to Requirement Versions
    // $gui->cfields = array();
    // $gui->cfields[] = $req_mgr->html_table_of_custom_field_values($gui->req_id,$argsObj->tproject_id);
    $gui->attachments[$gui->req_id] = getAttachmentInfosFrom($req_mgr, $gui->req_id);
    $gui->attachmentTableName = $req_mgr->getAttachmentTableName();
    $gui->reqStatus = init_labels($gui->req_cfg->status_labels);
    $gui->reqTypeDomain = init_labels($gui->req_cfg->type_labels);
    // added req relations for BUGID 1748
    $gui->req_relations = FALSE;
    $gui->req_relation_select = FALSE;
    $gui->testproject_select = FALSE;
    $gui->req_add_result_msg = isset($argsObj->relation_add_result_msg) ? $argsObj->relation_add_result_msg : "";
    if ($gui->req_cfg->relations->enable) {
        $gui->req_relations = $req_mgr->get_relations($gui->req_id);
        $gui->req_relation_select = $req_mgr->init_relation_type_select();
        if ($gui->req_cfg->relations->interproject_linking) {
            $gui->testproject_select = initTestprojectSelect($db, $argsObj, $tproject_mgr);
        }
    }
    return $gui;
}
 function get_requirements($id, $range = 'all', $testcase_id = null, $options = null, $filters = null)
 {
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $req_mgr = new requirement_mgr($this->db);
     $my['options'] = array('order_by' => " ORDER BY NH_REQ.node_order,NH_REQ.name,REQ.req_doc_id", 'output' => 'standard');
     $my['options'] = array_merge($my['options'], (array) $options);
     // null => do not filter
     $my['filters'] = array('status' => null, 'type' => null);
     $my['filters'] = array_merge($my['filters'], (array) $filters);
     switch ($my['options']['output']) {
         case 'count':
             $rs = 0;
             break;
         case 'standard':
         default:
             $rs = null;
             break;
     }
     $sql = '';
     $tcase_filter = '';
     // First Step - get only req info
     $sql = "/* {$debugMsg} */ SELECT NH_REQ.id FROM {$this->tables['nodes_hierarchy']} NH_REQ ";
     switch ($range) {
         case 'all':
             break;
         case 'assigned':
             $sql .= " JOIN {$this->tables['req_coverage']} REQ_COV ON REQ_COV.req_id=NH_REQ.id ";
             if (!is_null($testcase_id)) {
                 $tcase_filter = " AND REQ_COV.testcase_id={$testcase_id}";
             }
             break;
     }
     $sql .= " WHERE NH_REQ.parent_id={$id} " . " AND NH_REQ.node_type_id = {$this->node_types_descr_id['requirement']} {$tcase_filter}";
     $itemSet = $this->db->fetchRowsIntoMap($sql, 'id');
     if (!is_null($itemSet)) {
         $reqSet = array_keys($itemSet);
         $sql = "/* {$debugMsg} */ SELECT MAX(NH_REQV.id) AS version_id" . " FROM {$this->tables['nodes_hierarchy']} NH_REQV " . " WHERE NH_REQV.parent_id IN (" . implode(",", $reqSet) . ") " . " GROUP BY NH_REQV.parent_id ";
         $latestVersionSet = $this->db->fetchRowsIntoMap($sql, 'version_id');
         $reqVersionSet = array_keys($latestVersionSet);
         $getOptions = null;
         if (!is_null($my['options']['order_by'])) {
             $getOptions = array('order_by' => $my['options']['order_by']);
         }
         $rs = $req_mgr->get_by_id($reqSet, $reqVersionSet, null, $getOptions, $my['filters']);
         switch ($my['options']['output']) {
             case 'standard':
                 break;
             case 'count':
                 $rs = !is_null($rs) ? count($rs) : 0;
                 break;
         }
     }
     return $rs;
 }
Ejemplo n.º 3
0
/**
 * replace BBCode-link tagged links in req/reqspec scope with actual links
 *
 * @internal revisions:
 * 20110525 - Julian - BUGID 4487 - allow to specify requirement version for internal links
 * 20100301 - asimon - added anchor and tproj parameters to tags
 * 
 * @param resource $dbHandler database handle
 * @param string $scope text in which to replace tags with links
 * @param integer $tprojectID ID of testproject to which req/reqspec belongs
 * @return string $scope text with generated links
 */
function req_link_replace($dbHandler, $scope, $tprojectID)
{
    // Use this to improve performance when is called in loops
    static $tree_mgr;
    static $tproject_mgr;
    static $req_mgr;
    static $cfg;
    static $l18n;
    static $title;
    static $tables;
    if (!$tproject_mgr) {
        $tproject_mgr = new testproject($dbHandler);
        $tree_mgr = new tree($dbHandler);
        $req_mgr = new requirement_mgr($dbHandler);
        $tables = tlObjectWithDB::getDBTables(array('requirements', 'req_specs'));
        $cfg = config_get('internal_links');
        $l18n['version'] = lang_get('tcversion_indicator');
        $prop2loop = array('req' => array('prop' => 'req_link_title', 'default_lbl' => 'requirement'), 'req_spec' => array('prop' => 'req_spec_link_title', 'default_lbl' => 'req_spec_short'));
        // configure link title (first part of the generated link)
        $title = array();
        foreach ($prop2loop as $key => $elem) {
            $prop = $elem['prop'];
            if ($cfg->{$prop}->type == 'string' && $cfg->{$prop}->value != '') {
                $title[$key] = lang_get($cfg->{$prop}->value);
            } else {
                if ($cfg->{$prop}->type == 'none') {
                    $title[$key] = '';
                } else {
                    $title[$key] = lang_get($elem['default_lbl']) . ": ";
                }
            }
        }
    }
    $prefix = $tproject_mgr->getTestCasePrefix($tprojectID);
    $string2replace = array();
    // configure target in which link shall open
    // use a reasonable default value if nothing is set in config
    $cfg->target = isset($cfg->target) ? $cfg->target : 'popup';
    switch ($cfg->target) {
        case 'popup':
            // use javascript to open popup window
            $string2replace['req'] = '<a href="javascript:openLinkedReqVersionWindow(%s,%s,\'%s\')">%s%s%s</a>';
            $string2replace['req_spec'] = '<a href="javascript:openLinkedReqSpecWindow(%s,\'%s\')">%s%s</a>';
            break;
        case 'window':
        case 'frame':
            // open in same frame
            $target = $cfg->target == 'window' ? 'target="_blank"' : 'target="_self"';
            $string2replace['req'] = '<a ' . $target . ' href="lib/requirements/reqView.php?' . 'item=requirement&requirement_id=%s&req_version_id=%s#%s">%s%s%s</a>';
            $string2replace['req_spec'] = '<a ' . $target . ' href="lib/requirements/reqSpecView.php?' . 'item=req_spec&req_spec_id=%s#%s">%s%s</a>';
            break;
    }
    // now the actual replacing
    $patterns2search = array();
    $patterns2search['req'] = "#\\[req(.*)\\](.*)\\[/req\\]#iU";
    $patterns2search['req_spec'] = "#\\[req_spec(.*)\\](.*)\\[/req_spec\\]#iU";
    $patternPositions = array('complete_string' => 0, 'attributes' => 1, 'doc_id' => 2);
    $items2search['req'] = array('tproj', 'anchor', 'version');
    $items2search['req_spec'] = array('tproj', 'anchor');
    $itemPositions = array('item' => 0, 'item_value' => 1);
    $sql2exec = array();
    $sql2exec['req'] = " SELECT id, req_doc_id AS doc_id " . " FROM {$tables['requirements']} WHERE req_doc_id=";
    $sql2exec['req_spec'] = " SELECT id, doc_id FROM {$tables['req_specs']} " . " WHERE doc_id=";
    foreach ($patterns2search as $accessKey => $pattern) {
        $matches = array();
        preg_match_all($pattern, $scope, $matches);
        // if no req_doc_id is set skip loop
        if (count($matches[$patternPositions['doc_id']]) == 0) {
            continue;
        }
        foreach ($matches[$patternPositions['complete_string']] as $key => $matched_string) {
            $matched = array();
            $matched['tproj'] = '';
            $matched['anchor'] = '';
            $matched['version'] = '';
            // only look for attributes if any found
            if ($matches[$patternPositions['attributes']][$key] != '') {
                foreach ($items2search[$accessKey] as $item) {
                    $matched_item = array();
                    preg_match('/' . $item . '=([\\w]+)/', $matched_string, $matched_item);
                    $matched[$item] = isset($matched_item[$itemPositions['item_value']]) ? $matched_item[$itemPositions['item_value']] : '';
                }
            }
            // set tproj to current project if tproj is not specified in attributes
            if (!isset($matched['tproj']) || $matched['tproj'] == '') {
                $matched['tproj'] = $prefix;
            }
            // get all reqs / req specs with the specified doc_id
            $sql = $sql2exec[$accessKey] . "'{$matches[$patternPositions['doc_id']][$key]}'";
            $rs = $dbHandler->get_recordset($sql);
            if (count($rs) > 0) {
                foreach ($rs as $key => $value) {
                    // get root of linked node and check
                    $real_root = $tree_mgr->getTreeRoot($value['id']);
                    $matched_root_info = $tproject_mgr->get_by_prefix($matched['tproj']);
                    // do only continue if project with the specified project exists and
                    // if the requirement really belongs to the specified project (requirements
                    // with the same doc_id may exist within different projects)
                    if ($real_root == $matched_root_info['id']) {
                        if ($accessKey == 'req') {
                            // add version to link title if set
                            $version = '';
                            $req_version_id = 'null';
                            if ($matched['version'] != '') {
                                // get requirement version_id of the specified version
                                $req_version = $req_mgr->get_by_id($value['id'], null, $matched['version']);
                                // if version is not set or wrong version was set
                                // -> show latest version by setting version_id to null
                                $req_version_id = isset($req_version[0]['version_id']) ? $req_version[0]['version_id'] : 'null';
                                // if req_version_id exists set the version to show on hyperlink text
                                if ($req_version_id != 'null') {
                                    $version = sprintf($l18n['version'], $matched['version']);
                                }
                            }
                            $urlString = sprintf($string2replace[$accessKey], $value['id'], $req_version_id, $matched['anchor'], $title[$accessKey], $value['doc_id'], $version);
                        } else {
                            // build urlString for req specs which do not have a version
                            $urlString = sprintf($string2replace[$accessKey], $value['id'], $matched['anchor'], $title[$accessKey], $value['doc_id']);
                        }
                        $scope = str_replace($matched_string, $urlString, $scope);
                    }
                }
            }
        }
    }
    return $scope;
}
Ejemplo n.º 4
0
/**
 * render a requirement as HTML code for printing
 * 
 * @author Andreas Simon
 * 
 * @param resource $db
 * @param array $node the node to be printed
 * @param array $options
 *				displayDates: true display creation and last edit date (including hh:mm:ss)
 *
 * @param string $tocPrefix Prefix to be printed in TOC before title of node
 * @param int $level
 * @param int $tprojectID
 * 
 * @return string $output HTML Code
 *
 * @internal revisions
 *
 */
function renderReqForPrinting(&$db, $node, &$options, $tocPrefix, $level, $tprojectID)
{
    static $tableColspan;
    static $firstColWidth;
    static $labels;
    static $title_separator;
    static $req_mgr;
    static $tplan_mgr;
    static $req_cfg;
    static $req_spec_cfg;
    static $decodeReq;
    static $force = null;
    if (!$req_mgr) {
        $req_cfg = config_get('req_cfg');
        $req_spec_cfg = config_get('req_spec_cfg');
        $firstColWidth = '20%';
        $tableColspan = 2;
        $labels = array('requirement' => 'requirement', 'status' => 'status', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'not_aplicable' => 'not_aplicable', 'coverage' => 'coverage', 'last_edit' => 'last_edit', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs', 'version' => 'version', 'revision' => 'revision');
        $labels = init_labels($labels);
        $decodeReq = array();
        $decodeReq['status'] = init_labels($req_cfg->status_labels);
        $decodeReq['type'] = init_labels($req_cfg->type_labels);
        $force['displayVersion'] = isset($options['displayVersion']) ? $options['displayVersion'] : false;
        $force['displayLastEdit'] = isset($options['displayLastEdit']) ? $options['displayLastEdit'] : false;
        $title_separator = config_get('gui_title_separator_1');
        $req_mgr = new requirement_mgr($db);
        $tplan_mgr = new testplan($db);
    }
    $versionID = isset($node['version_id']) ? intval($node['version_id']) : requirement_mgr::LATEST_VERSION;
    $revision = isset($node['revision']) ? intval($node['revision']) : null;
    if (is_null($revision)) {
        // will get last revision of requested req version
        $dummy = $req_mgr->get_by_id($node['id'], $versionID);
    } else {
        $dummy = $req_mgr->get_version_revision($versionID, array('number' => $revision));
        if (!is_null($dummy)) {
            // do this way instead of using SQL alias on get_version_revision(), in order
            // to avoid issues (potential not confirmed)on different DBMS.
            $dummy[0]['id'] = $dummy[0]['req_id'];
        }
    }
    $req = $dummy[0];
    // update with values got from req, this is needed if user did not provide it
    $versionID = $req['version_id'];
    $revision = $req['revision'];
    $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']);
    $table_style = "";
    if (isset($options['docType']) && $options['docType'] == SINGLE_REQ) {
        $table_style = "style=\"margin-left: 0;\"";
    }
    $output = "<table class=\"req\" {$table_style}><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n";
    if ($force['displayVersion']) {
        foreach (array('version', 'revision') as $key) {
            $output .= '<tr><td valign="top">' . '<span class="label">' . $labels[$key] . ':</span></td>' . '<td>' . $req[$key] . "</td></tr>\n";
        }
    }
    if ($options['toc']) {
        $options['tocCode'] .= '<p style="padding-left: ' . 15 * $level . 'px;"><a href="#' . prefixToHTMLID('req' . $node['id']) . '">' . $name . '</a></p>';
        $output .= '<a name="' . prefixToHTMLID('req' . $node['id']) . '"></a>';
    }
    if ($options['req_author']) {
        $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['author'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['author_id']));
        if (isset($options['displayDates']) && $options['displayDates']) {
            $dummy = null;
            $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['creation_ts']);
        }
        $output .= "</td></tr>\n";
        if ($req['modifier_id'] > 0) {
            // add updater if available and differs from author OR forced
            if ($force['displayLastEdit'] || $req['modifier_id'] != $req['modifier_id']) {
                $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['last_edit'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['modifier_id']));
                if (isset($options['displayDates']) && $options['displayDates']) {
                    $dummy = null;
                    $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['modification_ts']);
                }
                $output .= "</td></tr>\n";
            }
        }
    }
    foreach (array('status', 'type') as $key) {
        if ($options['req_' . $key]) {
            $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels[$key] . "</span></td>" . "<td>" . $decodeReq[$key][$req[$key]] . "</td></tr>";
        }
    }
    if ($options['req_coverage']) {
        $current = count($req_mgr->get_coverage($req['id']));
        $expected = $req['expected_coverage'];
        $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['coverage'] . "</span></td>" . "<td>{$coverage}</td></tr>";
    }
    if ($options['req_scope']) {
        $output .= "<tr><td colspan=\"{$tableColspan}\"> <br/>" . $req['scope'] . "</td></tr>";
    }
    if ($options['req_relations']) {
        $relations = $req_mgr->get_relations($req['id']);
        if ($relations['num_relations']) {
            $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['relations'] . "</span></td><td>";
            $filler = str_repeat('&nbsp;', 5);
            // MAGIC allowed
            foreach ($relations['relations'] as $rel) {
                $output .= "{$rel['type_localized']}: <br/>{$filler}" . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . "{$filler}{$labels['status']}: " . "{$decodeReq['status'][$rel['related_req']['status']]} <br/>";
                if ($req_cfg->relations->interproject_linking) {
                    $output .= "{$filler}{$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>";
                }
            }
            $output .= "</td></tr>";
        }
    }
    if ($options['req_linked_tcs']) {
        $req_coverage = $req_mgr->get_coverage($req['id']);
        if (count($req_coverage)) {
            $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['related_tcs'] . "</span></td>" . "<td>";
            foreach ($req_coverage as $tc) {
                $output .= htmlspecialchars($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>";
            }
            $output .= "</td></tr>";
        }
    }
    if ($options['req_cf']) {
        $childID = is_null($revision) || $req['revision_id'] < 0 ? $req['version_id'] : $req['revision_id'];
        $linked_cf = $req_mgr->get_linked_cfields($req['id'], $childID);
        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/>";
    return $output;
}
Ejemplo n.º 5
0
/**
 * process_req
 *
 * @internal revisions:
 * 20110601 - asimon - add a new (valid) direct link to output if a nonexistent version of a valid req is requested
 * 20110530 - asimon - BUGID 4298: refactored this function to be able to operate with specific versions
 */
function process_req(&$dbHandler, $docID, $tprojectID, $tprojectPrefix, $version)
{
    $ret = array('url' => null, 'msg' => null);
    // First step: get this requirement's database ID by its Doc-ID (only if this Doc-ID exists).
    $req_mgr = new requirement_mgr($dbHandler);
    $req = $req_mgr->getByDocID($docID, $tprojectID);
    $req = is_null($req) ? null : current($req);
    $req_id = is_null($req) ? null : $req['id'];
    $version_id = null;
    if (is_null($req_id)) {
        $ret['msg'] = sprintf(lang_get('req_not_found'), $docID, $tprojectPrefix);
    }
    // Second step: If the requirement exists and a version was given, we have to check here if this specific version exists, too.
    if (!is_null($req_id) && !is_null($version) && is_numeric($version)) {
        $req = $req_mgr->get_by_id($req_id, null, $version);
        $req = is_null($req) ? null : current($req);
        // does this requirement really have the correct version number?
        $version_id = !is_null($req) && $req['version'] == $version ? $req['version_id'] : null;
        if (is_null($version_id)) {
            // add direct link to current version to output
            $req_url = $_SESSION['basehref'] . 'linkto.php?load&tprojectPrefix=' . urlencode($tprojectPrefix) . '&item=req&id=' . urlencode($docID);
            $ret['msg'] = sprintf(lang_get('req_version_not_found'), $version, $docID, $tprojectPrefix);
            $ret['msg'] .= sprintf(" <a href=\"{$req_url}\">%s</a>", lang_get('direct_link_on_wrong_version'));
            $req_id = null;
        }
    }
    // Third and last step: set cookie and build the link (only if the requested item really was found).
    if (!is_null($req_id)) {
        if (!is_null($version_id)) {
            // link to open in requirement frame must include version
            $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req_id}&req_version_id={$version_id}";
        } else {
            // link to open in requirement frame does not include a version, it was not requested
            $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req_id}";
        }
        $cookie = buildCookie($dbHandler, $req_id, $tprojectID, 'ys-requirement_spec');
        setcookie($cookie['value'], $cookie['path'], TL_COOKIE_KEEPTIME, '/');
    }
    return $ret;
}
Ejemplo n.º 6
0
 * Compares selected requirements versions with each other.
 *
 * @internal Revisions:
 * 20100831 - Julian - added requirement title to page heading
 */
require_once "../../config.inc.php";
require_once "common.php";
require '../../third_party/diff/diff.php';
$templateCfg = templateConfiguration();
testlinkInitPage($db);
$smarty = new TLSmarty();
$differ = new diff();
$args = init_args();
$gui = new stdClass();
$reqMgr = new requirement_mgr($db);
$reqSet = $reqMgr->get_by_id($args->req_id);
$gui->req_versions = $reqSet;
$gui->req_id = $args->req_id;
$gui->compare_selected_versions = $args->compare_selected_versions;
$gui->context = $args->context;
$gui->version_short = lang_get('version_short');
$labels = array();
$labels["num_changes"] = lang_get("num_changes");
$labels["no_changes"] = lang_get("no_changes");
//if already two versions are selected, display diff
//else display template with versions to select
if ($args->compare_selected_versions) {
    $diff_array = array("scope" => array());
    foreach ($reqSet as $req) {
        if ($req['version'] == $args->version_left) {
            $left = $req;
Ejemplo n.º 7
0
}
$eval_status_map = $code_status_map;
$eval_status_map['partially_passed'] = array('label' => lang_get('partially_passed'), 'long_label' => lang_get('partially_passed_reqs'), 'css_class' => 'not_run_text');
$eval_status_map['uncovered'] = array('label' => lang_get('uncovered'), 'long_label' => lang_get('uncovered_reqs'), 'css_class' => 'not_run_text');
$args = init_args($tproject_mgr);
$gui = init_gui($args);
$req_ids = $tproject_mgr->get_all_requirement_ids($args->tproject_id);
$req_spec_map = array();
$tc_ids = array();
$testcases = array();
// first step: get the requirements and linked testcases with which we have to work,
// order them into $req_spec_map by spec
if (count($req_ids)) {
    foreach ($req_ids as $id) {
        // get the information for this requirement
        $req = $req_mgr->get_by_id($id, requirement_mgr::LATEST_VERSION);
        $req_info = $req[0];
        $spec_id = $req_info['srs_id'];
        // if req is "usable" (either finished status or all requested) add it
        if (!$args->show_only_finished || $req_info['status'] == TL_REQ_STATUS_FINISH) {
            // coverage data
            $linked_tcs = (array) $req_mgr->get_coverage($id);
            $req_info['linked_testcases'] = $linked_tcs;
            if (!isset($req_spec_map[$spec_id])) {
                $spec_info = $req_spec_mgr->get_by_id($spec_id);
                $req_spec_map[$spec_id] = $spec_info;
                $req_spec_map[$spec_id]['requirements'] = array();
            }
            $req_spec_map[$spec_id]['requirements'][$id] = $req_info;
            foreach ($linked_tcs as $tc) {
                $tc_ids[] = $tc['id'];
Ejemplo n.º 8
0
$coverage_enabled = $req_cfg->expected_coverage_management;
$relations_enabled = $req_cfg->relations->enable;
$gui->reqIDs = $tproject_mgr->get_all_requirement_ids($args->tproject_id);
if (count($gui->reqIDs) > 0) {
    // get type and status labels
    $type_labels = init_labels($req_cfg->type_labels);
    $status_labels = init_labels($req_cfg->status_labels);
    $labels2get = array('no' => 'No', 'yes' => 'Yes', 'not_aplicable' => null, 'req_spec_short' => null, 'title' => null, 'version' => null, 'th_coverage' => null, 'frozen' => null, 'type' => null, 'status' => null, 'th_relations' => null, 'requirements' => null, 'number_of_reqs' => null, 'number_of_versions' => null);
    $labels = init_labels($labels2get);
    $gui->cfields4req = (array) $cfield_mgr->get_linked_cfields_at_design($args->tproject_id, 1, null, 'requirement', null, 'name');
    $version_option = $args->all_versions ? requirement_mgr::ALL_VERSIONS : requirement_mgr::LATEST_VERSION;
    // array to gather table data row per row
    $rows = array();
    foreach ($gui->reqIDs as $id) {
        // now get the rest of information for this requirement
        $req = $req_mgr->get_by_id($id, $version_option);
        // coverage data
        $tc_coverage = count($req_mgr->get_coverage($id));
        // number of relations, if feature is enabled
        if ($relations_enabled) {
            $relations = $req_mgr->count_relations($id);
            $relations = "<!-- " . sprintf("%010d", $relations) . " -->" . $relations;
        }
        // create the link to display
        $title = htmlentities($req[0]['req_doc_id'], ENT_QUOTES, $charset) . $glue_char . htmlentities($req[0]['title'], ENT_QUOTES, $charset);
        // add html comment with title for easier sorting
        $linked_title = '<!-- ' . $title . ' -->' . '<a href="javascript:openLinkedReqWindow(' . $id . ')">' . $title . '</a>';
        // reqspec-"path" to requirement
        $path = $req_mgr->tree_mgr->get_path($req[0]['srs_id']);
        foreach ($path as $key => $p) {
            $path[$key] = $p['name'];
 $imgSet = $smarty->getImages();
 $gui->warning_msg = '';
 // get type and status labels
 $type_labels = init_labels($cfg->req->type_labels);
 $status_labels = init_labels($cfg->req->status_labels);
 $labels2get = array('no' => 'No', 'yes' => 'Yes', 'not_aplicable' => null, 'never' => null, 'req_spec_short' => null, 'title' => null, 'version' => null, 'th_coverage' => null, 'frozen' => null, 'type' => null, 'status' => null, 'th_relations' => null, 'requirements' => null, 'number_of_reqs' => null, 'number_of_versions' => null, 'requirement' => null, 'version_revision_tag' => null, 'week_short' => 'calendar_week_short');
 $labels = init_labels($labels2get);
 $gui->cfields4req = (array) $cfield_mgr->get_linked_cfields_at_design($args->tproject_id, 1, null, 'requirement', null, 'name');
 $gui->processCF = count($gui->cfields4req) > 0;
 $coverageSet = null;
 $relationCounters = null;
 $version_option = $args->all_versions ? requirement_mgr::ALL_VERSIONS : requirement_mgr::LATEST_VERSION;
 if ($version_option == requirement_mgr::LATEST_VERSION) {
     $reqSet = $req_mgr->getByIDBulkLatestVersionRevision($gui->reqIDs, array('outputFormat' => 'mapOfArray'));
 } else {
     $reqSet = $req_mgr->get_by_id($gui->reqIDs, $version_option, null, array('output_format' => 'mapOfArray'));
     // new dBug($reqSet);
 }
 if ($cfg->req->expected_coverage_management) {
     $coverageSet = $req_mgr->getCoverageCounterSet($gui->reqIDs);
 }
 if ($cfg->req->relations->enable) {
     $relationCounters = $req_mgr->getRelationsCounters($gui->reqIDs);
 }
 // array to gather table data row per row
 $rows = array();
 foreach ($gui->reqIDs as $id) {
     // now get the rest of information for this requirement
     //if( $version_option == requirement_mgr::ALL_VERSIONS )
     //{
     //  // This need to be refactored in future to improve performance
Ejemplo n.º 10
0
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj)
{
    $tproject_mgr = new testproject($dbHandler);
    $req_mgr = new requirement_mgr($dbHandler);
    $commandMgr = new reqCommands($dbHandler);
    $gui = $commandMgr->initGuiBean();
    $gui->refreshTree = $argsObj->refreshTree;
    $gui->req_cfg = config_get('req_cfg');
    $gui->tproject_id = $argsObj->tproject_id;
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = $argsObj->user->hasRight($dbHandler, "mgt_modify_req", $argsObj->tproject_id);
    // IMPORTANT NOTICE
    // We can arrive here after following operation
    // 1. user click on left pane tree on REQ SPEC NODE
    // 2. on right pane screen user click on CREATE button on Requirements Operations
    // 3. on new screen user CLICK CANCEL
    // In this situation $argsObj->req_id is 0 OR EMPTY
    $gui->req_id = $argsObj->req_id;
    if ($gui->req_id <= 0) {
        // Quick Exit
        // is not too clear why do not need to add lib/requirements/ on target
        $target = "reqSpecView.php?tproject_id={$gui->tproject_id}" . "&req_spec_id={$argsObj->req_spec_id}";
        header("Location: {$target}");
        exit;
    }
    // everything is fine - standard processing
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->glueChar = config_get('testcase_cfg')->glue_character;
    $gui->pieceSep = config_get('gui_title_separator_1');
    /* if wanted, show only the given version */
    $gui->version_option = $argsObj->req_version_id ? $argsObj->req_version_id : requirement_mgr::ALL_VERSIONS;
    $gui->req_versions = $req_mgr->get_by_id($gui->req_id, $gui->version_option);
    $gui->req_has_history = count($req_mgr->get_history($gui->req_id, array('output' => 'array'))) > 1;
    $gui->req = current($gui->req_versions);
    $gui->req_coverage = $req_mgr->get_coverage($gui->req_id);
    // This seems weird but is done to adapt template than can display multiple
    // requirements. This logic has been borrowed from test case versions management
    $gui->current_version[0] = array($gui->req);
    $gui->cfields_current_version[0] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $gui->req['version_id'], $argsObj->tproject_id);
    // Now CF for other Versions
    $gui->other_versions[0] = null;
    $gui->cfields_other_versions[] = null;
    if (count($gui->req_versions) > 1) {
        $gui->other_versions[0] = array_slice($gui->req_versions, 1);
        $loop2do = count($gui->other_versions[0]);
        for ($qdx = 0; $qdx < $loop2do; $qdx++) {
            $target_version = $gui->other_versions[0][$qdx]['version_id'];
            $gui->cfields_other_versions[0][$qdx] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $target_version, $argsObj->tproject_id);
        }
    }
    $gui->show_title = false;
    $gui->main_descr = lang_get('req') . $gui->pieceSep . $gui->req['title'];
    $gui->showReqSpecTitle = $argsObj->showReqSpecTitle;
    if ($gui->showReqSpecTitle) {
        $gui->parent_descr = lang_get('req_spec_short') . $gui->pieceSep . $gui->req['req_spec_title'];
    }
    $gui->attachments[$gui->req_id] = $req_mgr->getAttachmentInfos($gui->req_id);
    $gui->attachmentTableName = $req_mgr->getAttachmentTableName();
    $gui->reqStatus = init_labels($gui->req_cfg->status_labels);
    $gui->reqTypeDomain = init_labels($gui->req_cfg->type_labels);
    // added req relations for BUGID 1748
    $gui->req_relations = FALSE;
    $gui->req_relation_select = FALSE;
    $gui->testproject_select = FALSE;
    $gui->req_add_result_msg = isset($argsObj->relation_add_result_msg) ? $argsObj->relation_add_result_msg : "";
    if ($gui->req_cfg->relations->enable) {
        $gui->req_relations = $req_mgr->get_relations($gui->req_id);
        $gui->req_relation_select = $req_mgr->init_relation_type_select();
        if ($gui->req_cfg->relations->interproject_linking) {
            $gui->testproject_select = initTestprojectSelect($argsObj->userID, $argsObj->tproject_id, $tproject_mgr);
        }
    }
    return $gui;
}
Ejemplo n.º 11
0
/**
 * render a requirement 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 renderRequirementNodeForPrinting(&$db, $node, &$printingOptions, $tocPrefix, $level, $tprojectID)
{
    static $tableColspan;
    static $firstColWidth;
    static $labels;
    static $title_separator;
    static $req_mgr;
    static $tplan_mgr;
    static $req_cfg;
    static $req_spec_cfg;
    static $reqStatusLabels;
    static $reqTypeLabels;
    if (!$req_mgr) {
        $req_cfg = config_get('req_cfg');
        $req_spec_cfg = config_get('req_spec_cfg');
        $firstColWidth = '20%';
        $tableColspan = 2;
        $labels = array('requirement' => 'requirement', 'status' => 'status', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'coverage' => 'coverage', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs');
        $labels = init_labels($labels);
        $reqStatusLabels = init_labels($req_cfg->status_labels);
        $reqTypeLabels = init_labels($req_cfg->type_labels);
        $title_separator = config_get('gui_title_separator_1');
        $req_mgr = new requirement_mgr($db);
        $tplan_mgr = new testplan($db);
    }
    $arrReq = $req_mgr->get_by_id($node['id']);
    $req = $arrReq[0];
    $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']);
    $output = "<table class=\"req\"><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n";
    if ($printingOptions['toc']) {
        $printingOptions['tocCode'] .= '<p style="padding-left: ' . 15 * $level . 'px;"><a href="#' . prefixToHTMLID('req' . $node['id']) . '">' . $name . '</a></p>';
        $output .= '<a name="' . prefixToHTMLID('req' . $node['id']) . '"></a>';
    }
    if ($printingOptions['req_author']) {
        $author = tlUser::getById($db, $req['author_id']);
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['author'] . "</span></td><td> " . htmlspecialchars($author->getDisplayName()) . "</td></tr>\n";
    }
    if ($printingOptions['req_status']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['status'] . "</span></td>" . "<td>" . $reqStatusLabels[$req['status']] . "</td></tr>";
    }
    if ($printingOptions['req_type']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['type'] . "</span></td>" . "<td>" . $reqTypeLabels[$req['type']] . "</td></tr>";
    }
    if ($printingOptions['req_coverage']) {
        $current = count($req_mgr->get_coverage($req['id']));
        $expected = $req['expected_coverage'];
        $coverage = lang_get('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['coverage'] . "</span></td>" . "<td>{$coverage}</td></tr>";
    }
    if ($printingOptions['req_scope']) {
        $output .= "<tr><td colspan=\"{$tableColspan}\"><span class=\"label\">" . $labels['scope'] . "</span><br/>" . $req['scope'] . "</td></tr>";
    }
    if ($printingOptions['req_relations']) {
        $relations = $req_mgr->get_relations($req['id']);
        if ($relations['num_relations']) {
            $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['relations'] . "</span></td>" . "<td>";
            foreach ($relations['relations'] as $rel) {
                $output .= "{$rel['type_localized']}: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$labels['status']}: " . "{$reqStatusLabels[$rel['related_req']['status']]} <br/>";
                if ($req_cfg->relations->interproject_linking) {
                    $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>";
                }
            }
            $output .= "</td></tr>";
        }
    }
    if ($printingOptions['req_linked_tcs']) {
        $req_coverage = $req_mgr->get_coverage($req['id']);
        if (count($req_coverage)) {
            $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['related_tcs'] . "</span></td>" . "<td>";
            foreach ($req_coverage as $tc) {
                $output .= htmlentities($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>";
            }
            $output .= "</td></tr>";
        }
    }
    if ($printingOptions['req_cf']) {
        //BUGID 2877 - Custom Fields linked to Req versions
        $linked_cf = $req_mgr->get_linked_cfields($req['id'], $req['version_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/>";
    return $output;
}
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj, &$tproject_mgr)
{
    $req_mgr = new requirement_mgr($dbHandler);
    $commandMgr = new reqCommands($dbHandler);
    $gui = $commandMgr->initGuiBean();
    $gui->req_cfg = config_get('req_cfg');
    $gui->glueChar = config_get('testcase_cfg')->glue_character;
    $gui->pieceSep = config_get('gui_title_separator_1');
    $gui->refreshTree = $argsObj->refreshTree;
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->req_id = $argsObj->req_id;
    /* if wanted, show only the given version */
    $gui->version_option = $argsObj->req_version_id ? $argsObj->req_version_id : requirement_mgr::ALL_VERSIONS;
    $gui->req_versions = $req_mgr->get_by_id($gui->req_id, $gui->version_option, 1, array('renderImageInline' => true));
    $gui->reqHasBeenDeleted = false;
    if (is_null($gui->req_versions)) {
        // this means that requirement does not exist anymore.
        // We have to give just that info to user
        $gui->reqHasBeenDeleted = true;
        $gui->main_descr = lang_get('req_does_not_exist');
        unset($gui->show_match_count);
        return $gui;
        // >>>----> Bye!
    }
    $tproject_id = $req_mgr->getTestProjectID($argsObj->requirement_id);
    $target_id = $argsObj->tproject_id;
    if ($isAlien = $tproject_id != $argsObj->tproject_id) {
        $target_id = $tproject_id;
    }
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = $argsObj->user->hasRight($dbHandler, "mgt_modify_req", $target_id);
    $gui->grants->unfreeze_req = $argsObj->user->hasRight($dbHandler, "mgt_unfreeze_req", $target_id);
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->req = current($gui->req_versions);
    $gui->req_coverage = $req_mgr->get_coverage($gui->req_id);
    $gui->direct_link = $_SESSION['basehref'] . 'linkto.php?tprojectPrefix=' . urlencode($gui->tcasePrefix) . '&item=req&id=' . urlencode($gui->req['req_doc_id']);
    $gui->fileUploadURL = $_SESSION['basehref'] . $req_mgr->getFileUploadRelativeURL($gui->req_id, $argsObj);
    $gui->delAttachmentURL = $_SESSION['basehref'] . $req_mgr->getDeleteAttachmentRelativeURL($gui->req_id);
    $gui->fileUploadMsg = '';
    $gui->import_limit = TL_REPOSITORY_MAXFILESIZE;
    $gui->log_target = null;
    $loop2do = count($gui->req_versions);
    for ($rqx = 0; $rqx < $loop2do; $rqx++) {
        $gui->log_target[] = $gui->req_versions[$rqx]['revision_id'] > 0 ? $gui->req_versions[$rqx]['revision_id'] : $gui->req_versions[$rqx]['version_id'];
    }
    $gui->req_has_history = count($req_mgr->get_history($gui->req_id, array('output' => 'array'))) > 1;
    // This seems weird but is done to adapt template than can display multiple
    // requirements. This logic has been borrowed from test case versions management
    $gui->current_version[0] = array($gui->req);
    $gui->cfields_current_version[0] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $gui->req['version_id'], $argsObj->tproject_id);
    // Now CF for other Versions
    $gui->other_versions[0] = null;
    $gui->cfields_other_versions[] = null;
    if (count($gui->req_versions) > 1) {
        $gui->other_versions[0] = array_slice($gui->req_versions, 1);
        $loop2do = count($gui->other_versions[0]);
        for ($qdx = 0; $qdx < $loop2do; $qdx++) {
            $target_version = $gui->other_versions[0][$qdx]['version_id'];
            $gui->cfields_other_versions[0][$qdx] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $target_version, $argsObj->tproject_id);
        }
    }
    $gui->show_title = false;
    $gui->main_descr = lang_get('req') . $gui->pieceSep . $gui->req['title'];
    $gui->showReqSpecTitle = $argsObj->showReqSpecTitle;
    if ($gui->showReqSpecTitle) {
        $gui->parent_descr = lang_get('req_spec_short') . $gui->pieceSep . $gui->req['req_spec_title'];
    }
    $gui->attachments[$gui->req_id] = getAttachmentInfosFrom($req_mgr, $gui->req_id);
    $gui->attachmentTableName = $req_mgr->getAttachmentTableName();
    $gui->reqStatus = init_labels($gui->req_cfg->status_labels);
    $gui->reqTypeDomain = init_labels($gui->req_cfg->type_labels);
    $gui->req_relations = FALSE;
    $gui->req_relation_select = FALSE;
    $gui->testproject_select = FALSE;
    $gui->req_add_result_msg = isset($argsObj->relation_add_result_msg) ? $argsObj->relation_add_result_msg : "";
    if ($gui->req_cfg->relations->enable) {
        $gui->req_relations = $req_mgr->get_relations($gui->req_id);
        $gui->req_relations['rw'] = !$isAlien;
        $gui->req_relation_select = $req_mgr->init_relation_type_select();
        if ($gui->req_cfg->relations->interproject_linking) {
            $gui->testproject_select = initTestprojectSelect($argsObj->userID, $argsObj->tproject_id, $tproject_mgr);
        }
    }
    $gui->user_feedback = $argsObj->user_feedback;
    return $gui;
}