/
csv_api.php
377 lines (337 loc) · 9.47 KB
/
csv_api.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
# Mantis - a php based bugtracking system
# Mantis 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.
#
# Mantis 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 Mantis. If not, see <http://www.gnu.org/licenses/>.
/**
* CSV API
* Names for formatting functions are csv_format_*, where * corresponds to the
* field name as return get csv_get_columns() and by the filter api.
*
* @package CoreAPI
* @subpackage CSVAPI
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2008 Mantis Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
/**
* get the csv file new line, can be moved to config in the future
* @return string containing new line character
* @access public
*/
function csv_get_newline() {
return "\r\n";
}
/**
* get the csv file separator, can be moved to config in the future
* @return string
* @access public
*/
function csv_get_separator() {
return config_get( 'csv_separator' );
}
/**
* if all projects selected, default to <username>.csv, otherwise default to
* <projectname>.csv.
* @return string filename
* @access public
*/
function csv_get_default_filename() {
$t_current_project_id = helper_get_current_project();
if( ALL_PROJECTS == $t_current_project_id ) {
$t_filename = user_get_name( auth_get_current_user_id() );
} else {
$t_filename = project_get_field( $t_current_project_id, 'name' );
}
return $t_filename . '.csv';
}
/**
* escape a string before writing it to csv file.
* @param type $todo TODO
* @return TODO
* @access public
*/
function csv_escape_string( $p_str ) {
# enclose strings with separators with quotaiton marks
if( strpos( $p_str, csv_get_separator() ) !== false ) {
$p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
}
# enclose multi-line strings with quotaiton marks
if( strpos( $p_str, "\n" ) !== false ) {
$p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
}
return $p_str;
}
/**
* An array of column names that are used to identify fields to include and in which order.
* @param type $todo TODO
* @return TODO
* @access public
*/
function csv_get_columns() {
$t_columns = helper_get_columns_to_view( COLUMNS_TARGET_CSV_PAGE );
return $t_columns;
}
/**
* format bug id
* @param int $p_bug_id bug id
* @return string csv formatted bug
* @access public
*/
function csv_format_id( $p_bug_id ) {
return bug_format_id( $p_bug_id );
}
/**
* returns the project name corresponding to the supplied project id.
* @param int $p_project_id project id
* @return string csv formatted project name
* @access public
*/
function csv_format_project_id( $p_project_id ) {
return csv_escape_string( project_get_name( $p_project_id ) );
}
/**
* returns the reporter name corresponding to the supplied id.
* @param int $p_reporter_id user id
* @return string formatted user name
* @access public
*/
function csv_format_reporter_id( $p_reporter_id ) {
return csv_escape_string( user_get_name( $p_reporter_id ) );
}
/**
* returns the handler name corresponding to the supplied id
* @param int $p_handler_id user id
* @return string formatted user name
* @access public
*/
function csv_format_handler_id( $p_handler_id ) {
if( $p_handler_id > 0 ) {
return csv_escape_string( user_get_name( $p_handler_id ) );
}
}
/**
* return the priority string
* @param int $p_priority
* @return string formatted priority string
* @access public
*/
function csv_format_priority( $p_priority ) {
return csv_escape_string( get_enum_element( 'priority', $p_priority ) );
}
/**
* return the severity string
* @param int $p_severity
* @return string formatted severity string
* @access public
*/
function csv_format_severity( $p_severity ) {
return csv_escape_string( get_enum_element( 'severity', $p_severity ) );
}
/**
* return the reproducability string
* @param int $p_reproducibility
* @return string formatted reproducibility string
* @access public
*/
function csv_format_reproducibility( $p_reproducibility ) {
return csv_escape_string( get_enum_element( 'reproducibility', $p_reproducibility ) );
}
/**
* return the version
* @param string $p_version version string
* @return string formatted version string
* @access public
*/
function csv_format_version( $p_version ) {
return csv_escape_string( $p_version );
}
/**
* return the fixed_in_version
* @param string $p_fixed_in_version fixed in version string
* @return string formatted fixed in version string
* @access public
*/
function csv_format_fixed_in_version( $p_fixed_in_version ) {
return csv_escape_string( $p_fixed_in_version );
}
/**
* return the target_version
* @param string $p_target_version target version string
* @return string formatted target version string
* @access public
*/
function csv_format_target_version( $p_target_version ) {
return csv_escape_string( $p_target_version );
}
/**
* return the projection
* @param int $p_projection
* @return string formatted projection string
* @access public
*/
function csv_format_projection( $p_projection ) {
return csv_escape_string( get_enum_element( 'projection', $p_projection ) );
}
/**
* return the category
* @param int $p_category_id
* @return string formatted category string
* @access public
*/
function csv_format_category_id( $p_category_id ) {
return csv_escape_string( category_full_name( $p_category_id, false ) );
}
/**
* return the date submitted
* @param string $p_date_submitted
* @return string formatted date
* @access public
*/
function csv_format_date_submitted( $p_date_submitted ) {
return date( config_get( 'short_date_format' ), $p_date_submitted );
}
/**
* return the eta
* @param int $p_eta eta
* @return string formatted eta
* @access public
*/
function csv_format_eta( $p_eta ) {
return csv_escape_string( get_enum_element( 'eta', $p_eta ) );
}
/**
* return the operating system
* @param string $p_os operating system
* @return string formatted operating system
* @access public
*/
function csv_format_os( $p_os ) {
return csv_escape_string( $p_os );
}
/**
* return the os build (os version)
* @param string $p_os_build operating system build
* @return string formatted operating system build
* @access public
*/
function csv_format_os_build( $p_os_build ) {
return csv_escape_string( $p_os_build );
}
/**
* return the build
* @param string $p_build
* @return string formatted build
* @access public
*/
function csv_format_build( $p_build ) {
return csv_escape_string( $p_build );
}
/**
* return the platform
* @param string $p_platform platform
* @return string formatted platform
* @access public
*/
function csv_format_platform( $p_platform ) {
return csv_escape_string( $p_platform );
}
/**
* return the view state (eg: private / public)
* @param int $p_view_state view state
* @return string formatted view state
* @access public
*/
function csv_format_view_state( $p_view_state ) {
return csv_escape_string( get_enum_element( 'view_state', $p_view_state ) );
}
/**
* return the last updated date
* @param string $p_last_updated last updated
* @return string formated last updated string
* @access public
*/
function csv_format_last_updated( $p_last_updated ) {
return date( config_get( 'short_date_format' ), $p_last_updated );
}
/**
* return the summary
* @param string $p_summary summary
* @return string formatted summary
* @access public
*/
function csv_format_summary( $p_summary ) {
return csv_escape_string( $p_summary );
}
/**
* return the description
* @param string $p_description description
* @return string formatted description
* @access public
*/
function csv_format_description( $p_description ) {
return csv_escape_string( $p_description );
}
/**
* return the steps to reproduce
* @param string $p_steps_to_reproduce steps to reproduce
* @return string formatted steps to reproduce
* @access public
*/
function csv_format_steps_to_reproduce( $p_steps_to_reproduce ) {
return csv_escape_string( $p_steps_to_reproduce );
}
/**
* return the additional information
* @param string $p_additional_information
* @return string formatted additional information
* @access public
*/
function csv_format_additional_information( $p_additional_information ) {
return csv_escape_string( $p_additional_information );
}
/**
* return the status string
* @param string $p_status status
* @return string formatted status
* @access public
*/
function csv_format_status( $p_status ) {
return csv_escape_string( get_enum_element( 'status', $p_status ) );
}
/**
* return the resolution string
* @param int $p_resolution resolution
* @return string formatted resolution string
* @access public
*/
function csv_format_resolution( $p_resolution ) {
return csv_escape_string( get_enum_element( 'resolution', $p_resolution ) );
}
/**
* return the duplicate bug id
* @param int $p_duplicate_id
* @return string formatted bug id
* @access public
*/
function csv_format_duplicate_id( $p_duplicate_id ) {
return bug_format_id( $p_duplicate_id );
}
/**
* return the selection
* @param int $p_duplicate_id
* @return string
* @access public
*/
function csv_format_selection( $p_duplicate_id ) {
return csv_escape_string( '' );
}