/
IssueStatusChangeTimelineEvent.class.php
132 lines (120 loc) · 4.05 KB
/
IssueStatusChangeTimelineEvent.class.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Timeline event class for status change of issues.
* @copyright Copyright 2014 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
* @package MantisBT
*/
/**
* Timeline event class for status change of issues.
*
* @package MantisBT
* @subpackage classes
*/
class IssueStatusChangeTimelineEvent extends TimelineEvent {
private $issue_id;
private $old_status;
private $new_status;
private $type;
/**
* Status change types to be displayed in Timeline
* IGNORED = not displayed
*/
const IGNORED = 0;
const RESOLVED = 1;
const CLOSED = 2;
const REOPENED = 3;
/**
* @param integer $p_timestamp Timestamp representing the time the event occurred.
* @param integer $p_user_id An user identifier.
* @param integer $p_issue_id A issue identifier.
* @param integer $p_old_status Old status value of issue.
* @param integer $p_new_status New status value of issue.
*/
public function __construct( $p_timestamp, $p_user_id, $p_issue_id, $p_old_status, $p_new_status ) {
parent::__construct( $p_timestamp, $p_user_id );
$this->issue_id = $p_issue_id;
$this->old_status = $p_old_status;
$this->new_status = $p_new_status;
$this->type = $this->change_type();
}
/**
* Return the type of status change
* @return int One of the status change constants defined above
*/
private function change_type() {
$t_resolved = config_get( 'bug_resolved_status_threshold' );
$t_closed = config_get( 'bug_closed_status_threshold' );
if( $this->old_status < $t_closed && $this->new_status >= $t_closed ) {
return IssueStatusChangeTimelineEvent::CLOSED;
} else if( $this->old_status < $t_resolved && $this->new_status >= $t_resolved ) {
return IssueStatusChangeTimelineEvent::RESOLVED;
} else if( $this->old_status >= $t_resolved && $this->new_status < $t_resolved ) {
return IssueStatusChangeTimelineEvent::REOPENED;
} else {
return IssueStatusChangeTimelineEvent::IGNORED;
}
}
/**
* Whether to skip this timeline event.
* This normally implements access checks for the event.
* @return boolean
*/
public function skip() {
return $this->type == IssueStatusChangeTimelineEvent::IGNORED;
}
/**
* Returns html string to display
* @return string
*/
public function html() {
switch( $this->type ) {
case IssueStatusChangeTimelineEvent::RESOLVED:
$t_html = $this->html_start( 'fa-thumbs-o-up' );
$t_string = sprintf(
lang_get( 'timeline_issue_resolved' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::CLOSED:
$t_html = $this->html_start( 'fa-power-off' );
$t_string = sprintf(
lang_get( 'timeline_issue_closed' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::REOPENED:
$t_html = $this->html_start( 'fa-refresh' );
$t_string = sprintf(
lang_get( 'timeline_issue_reopened' ),
user_get_name( $this->user_id ),
string_get_bug_view_link( $this->issue_id )
);
break;
case IssueStatusChangeTimelineEvent::IGNORED:
return '';
default:
# Unknown status change type
trigger_error( ERROR_GENERIC, ERROR );
return '';
}
$t_html .= '<div class="action">' . $t_string . '</div>';
$t_html .= $this->html_end();
return $t_html;
}
}