Example #1
0
require_api('authentication_api.php');
require_api('compress_api.php');
require_api('config_api.php');
require_api('graphviz_api.php');
require_api('workflow_api.php');
auth_ensure_user_authenticated();
if (!config_get('relationship_graph_enable')) {
    access_denied();
}
compress_enable();
$t_status_arr = MantisEnum::getAssocArrayIndexedByValues(config_get('status_enum_string'));
$t_graph_fontname = config_get('relationship_graph_fontname');
$t_graph_fontsize = config_get('relationship_graph_fontsize');
$t_graph_fontpath = get_font_path();
$t_dot_tool = config_get('dot_tool');
$t_graph_attributes = array();
if (!empty($t_graph_fontpath)) {
    $t_graph_attributes['fontpath'] = $t_graph_fontpath;
}
$t_graph = new Graph('workflow', $t_graph_attributes, $t_dot_tool);
$t_graph->set_default_node_attr(array('fontname' => $t_graph_fontname, 'fontsize' => $t_graph_fontsize, 'shape' => 'record', 'style' => 'filled', 'height' => '0.2', 'width' => '0.4'));
$t_graph->set_default_edge_attr(array('style' => 'solid', 'color' => '#0000C0', 'dir' => 'forward'));
foreach ($t_status_arr as $t_from_status => $t_from_label) {
    $t_enum_status = MantisEnum::getAssocArrayIndexedByValues(config_get('status_enum_string'));
    foreach ($t_enum_status as $t_to_status_id => $t_to_status_label) {
        if (workflow_transition_edge_exists($t_from_status, $t_to_status_id)) {
            $t_graph->add_edge(string_no_break(MantisEnum::getLabel(lang_get('status_enum_string'), $t_from_status)), string_no_break(MantisEnum::getLabel(lang_get('status_enum_string'), $t_to_status_id)), array());
        }
    }
}
$t_graph->output('png', true);
function relgraph_generate_rel_graph($p_bug_id, $p_bug = null)
{
    # List of visited issues and their data.
    $v_bug_list = array();
    $v_rel_list = array();
    # Queue for breadth-first
    $v_queue = array();
    # Now we visit all related issues.
    $t_max_depth = config_get('relationship_graph_max_depth');
    # Put the first element into queue.
    array_push($v_queue, array(0, $p_bug_id));
    # And now we proccess it
    while (!empty($v_queue)) {
        list($t_depth, $t_id) = array_shift($v_queue);
        if (isset($v_bug_list[$t_id])) {
            continue;
        }
        if (!bug_exists($t_id)) {
            continue;
        }
        if (!access_has_bug_level(VIEWER, $t_id)) {
            continue;
        }
        $v_bug_list[$t_id] = bug_get($t_id, false);
        $t_relationships = relationship_get_all_src($t_id);
        foreach ($t_relationships as $t_relationship) {
            $t_dst = $t_relationship->dest_bug_id;
            if (BUG_DEPENDANT == $t_relationship->type) {
                $v_rel_list[$t_id][$t_dst] = BUG_DEPENDANT;
                $v_rel_list[$t_dst][$t_id] = BUG_BLOCKS;
            } else {
                $v_rel_list[$t_id][$t_dst] = $t_relationship->type;
                $v_rel_list[$t_dst][$t_id] = $t_relationship->type;
            }
            if ($t_depth < $t_max_depth) {
                array_push($v_queue, array($t_depth + 1, $t_dst));
            }
        }
        $t_relationships = relationship_get_all_dest($t_id);
        foreach ($t_relationships as $t_relationship) {
            $t_dst = $t_relationship->src_bug_id;
            if (BUG_DEPENDANT == $t_relationship->type) {
                $v_rel_list[$t_id][$t_dst] = BUG_BLOCKS;
                $v_rel_list[$t_dst][$t_id] = BUG_DEPENDANT;
            } else {
                $v_rel_list[$t_id][$t_dst] = $t_relationship->type;
                $v_rel_list[$t_dst][$t_id] = $t_relationship->type;
            }
            if ($t_depth < $t_max_depth) {
                array_push($v_queue, array($t_depth + 1, $t_dst));
            }
        }
    }
    # We have already collected all the information we need to generate
    # the graph. Now it is the matter to create a Digraph object and
    # store the information there, along with graph formatting attributes.
    $t_id_string = relgraph_bug_format_id($p_bug_id);
    $t_graph_fontname = config_get('relationship_graph_fontname');
    $t_graph_fontsize = config_get('relationship_graph_fontsize');
    $t_graph_fontpath = get_font_path();
    $t_view_on_click = config_get('relationship_graph_view_on_click');
    $t_neato_tool = config_get('neato_tool');
    $t_graph_attributes = array();
    if (!empty($t_graph_fontpath)) {
        $t_graph_attributes['fontpath'] = $t_graph_fontpath;
    }
    $t_graph = new Graph($t_id_string, $t_graph_attributes, $t_neato_tool);
    $t_graph->set_default_node_attr(array('fontname' => $t_graph_fontname, 'fontsize' => $t_graph_fontsize, 'shape' => 'record', 'style' => 'filled', 'height' => '0.2', 'width' => '0.4'));
    $t_graph->set_default_edge_attr(array('style' => 'solid', 'color' => '#0000C0', 'dir' => 'none'));
    # Add all issue nodes and edges to the graph.
    ksort($v_bug_list);
    foreach ($v_bug_list as $t_id => $t_bug) {
        $t_id_string = relgraph_bug_format_id($t_id);
        if ($t_view_on_click) {
            $t_url = string_get_bug_view_url($t_id);
        } else {
            $t_url = "bug_relationship_graph.php?bug_id={$t_id}&graph=relation";
        }
        relgraph_add_bug_to_graph($t_graph, $t_id_string, $t_bug, $t_url, $t_id == $p_bug_id);
        # Now add all relationship edges to the graph.
        if (isset($v_rel_list[$t_id])) {
            foreach ($v_rel_list[$t_id] as $t_dst => $t_relation) {
                # Do not create edges for unvisited bugs.
                if (!isset($v_bug_list[$t_dst])) {
                    continue;
                }
                # avoid double links
                if ($t_dst < $t_id) {
                    continue;
                }
                $t_related_id = relgraph_bug_format_id($t_dst);
                global $g_relationships;
                if (isset($g_relationships[$t_relation]) && isset($g_relationships[$t_relation]['#edge_style'])) {
                    $t_edge_style = $g_relationships[$t_relation]['#edge_style'];
                } else {
                    $t_edge_style = array();
                }
                $t_graph->add_edge($t_id_string, $t_related_id, $t_edge_style);
            }
        }
    }
    return $t_graph;
}