当前位置: 首页>>代码示例>>PHP>>正文


PHP tree::getTreeRoot方法代码示例

本文整理汇总了PHP中tree::getTreeRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP tree::getTreeRoot方法的具体用法?PHP tree::getTreeRoot怎么用?PHP tree::getTreeRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree的用法示例。


在下文中一共展示了tree::getTreeRoot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: req_link_replace


//.........这里部分代码省略.........
                } 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;
}
开发者ID:mokal,项目名称:DCN_TestLink,代码行数:101,代码来源:requirements.inc.php

示例2: req_link_replace

/**
 * replace BBCode-link tagged links in req/reqspec scope with actual links
 *
 * @internal revisions:
 * 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)
{
    $tree_mgr = new tree($dbHandler);
    $tproject_mgr = new testproject($dbHandler);
    $prefix = $tproject_mgr->getTestCasePrefix($tprojectID);
    $tables = tlObjectWithDB::getDBTables(array('requirements', 'req_specs'));
    $cfg = config_get('internal_links');
    $string2replace = array();
    $title = 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:openLinkedReqWindow(%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#%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;
    }
    // configure link title (first part of the generated link)
    // default: use item type as name (localized name for req)
    $title['req'] = lang_get('requirement') . ": ";
    // default: use short item type as name (localized name for req spec)
    $title['req_spec'] = lang_get('req_spec_short') . ": ";
    if ($cfg->req_link_title->type == 'string' && $cfg->req_link_title->value != '') {
        $title['req'] = lang_get($cfg->req_link_title->value);
    } else {
        if ($cfg->req_link_title->type == 'none') {
            $title['req'] = '';
        }
    }
    // now for the req specs
    if ($cfg->req_spec_link_title->type == 'string' && $cfg->req_spec_link_title->value != '') {
        // use user-configured string as link title
        $title['req_spec'] = lang_get($cfg->req_spec_link_title->value);
    } else {
        if ($cfg->req_spec_link_title->type == 'none') {
            $title['req_spec'] = '';
        }
    }
    // now the actual replacing
    $patterns2search = array();
    $patterns2search['req'] = "#\\[req[\\s]*(tproj=([\\w]+))*[\\s]*(anchor=([\\w]+))*[\\s]*(tproj=([\\w]+))*\\](.*)\\[/req\\]#iU";
    $patterns2search['req_spec'] = "#\\[req_spec[\\s]*(tproj=([\\w]+))*[\\s]*(anchor=([\\w]+))*[\\s]*(tproj=([\\w]+))*\\](.*)\\[/req_spec\\]#iU";
    $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 (count($matches[7]) == 0) {
            continue;
        }
        foreach ($matches[0] as $key => $matched_string) {
            // get testproject prefix, if that was found with regex
            // if not, get prefix of current project
            if ($matches[2][$key] != '') {
                $matched_prefix = $matches[2][$key];
            } else {
                if ($matches[6][$key] != '') {
                    $matched_prefix = $matches[6][$key];
                } else {
                    $matched_prefix = $prefix;
                }
            }
            $matched_anchor = $matches[4][$key];
            $matched_doc_id = $matches[7][$key];
            $sql = $sql2exec[$accessKey] . "'{$matched_doc_id}'";
            $rs = $dbHandler->get_recordset($sql);
            if (count($rs)) {
                //20100818 - Julian - fixed error if same doc_id exists in multiple projects
                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_prefix);
                    if ($real_root == $matched_root_info['id']) {
                        $urlString = sprintf($string2replace[$accessKey], $value['id'], $matched_anchor, $title[$accessKey], $value['doc_id']);
                        $scope = str_replace($matched_string, $urlString, $scope);
                    }
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:viglesiasce,项目名称:tl_RC1,代码行数:101,代码来源:requirements.inc.php


注:本文中的tree::getTreeRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。