-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomID.php
81 lines (64 loc) · 2.35 KB
/
CustomID.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
class CustomIDPlugin extends MantisPlugin {
function register() {
$this->name = 'Custom ID Plugin'; # Proper name of plugin
$this->description = 'Allows to display the contents of a custom field instead of the issue ID'; # Short description of the plugin
$this->page = 'config_page'; # Default plugin page
$this->version = '0.2'; # Plugin version string
$this->requires = array( # Plugin dependencies, array of basename => version pairs
'MantisCore' => '1.2', # Should always depend on an appropriate version of MantisBT
);
$this->author = 'GTZ Ethiopia ICT Service - Development Team'; # Author/team name
$this->contact = 'ict-et@gtz.de'; # Author/team e-mail address
$this->url = ''; # Support webpage
}
function hooks() {
return array(
'EVENT_DISPLAY_BUG_ID' => 'display_bug_id'
);
}
function config() {
return array(
'project_id' => 0,
'field_id' => 0,
'prefix' => "",
);
}
function display_bug_id($p_event, $p_text) {
$p_bug_id = (int)$p_text;
if (!bug_exists($p_bug_id))
return $p_text;
$bug = bug_get($p_bug_id);
$project = $bug->__get("project_id");
if ($project != plugin_config_get('project_id'))
return $p_text;
$p_field_id = plugin_config_get('field_id');
$prefix = plugin_config_get('prefix');
$has_parent = false;
$t_bugs_ids = relationship_get_all_src( $p_bug_id);
foreach ($t_bugs_ids as $t_relaship){
if( $t_relaship->type == BUG_BLOCKS) {
$has_parent = true;;
break;
}
}
$t_bugs_ids = relationship_get_all_dest( $p_bug_id);
foreach ($t_bugs_ids as $t_relaship){
if( $t_relaship->type == BUG_DEPENDANT) {
$has_parent = true;;
break;
}
}
$prefix_two = plugin_config_get('prefix_two');
if ($has_parent)
$prefix = $prefix_two;
$p_def = custom_field_get_definition($p_field_id);
$t_custom_field_value = custom_field_get_value( $p_field_id, $p_bug_id );
global $g_custom_field_type_definition;
if( isset( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'] ) ) {
return $prefix.call_user_func( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'], $t_custom_field_value );
}
return $prefix.$t_custom_field_value;
}
// todo: remove jump to field for such projects!
}