r1398: Removing the print_r() from BugAPI
[bugdar.git] / includes / api_bug.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $GLOBALS['isso:callback']->load('api', null);
23
24 /**
25 * API: Bug
26 *
27 * Note: When priority, severity, status, and resolution should throw a
28 * verification error, they actually set it to the default value
29 *
30 * @author Blue Static
31 * @copyright Copyright ©2002 - [#]year[#], Blue Static
32 * @version $Revision$
33 * @package Bugdar
34 *
35 */
36 class BugAPI extends API
37 {
38 /**
39 * Database fields
40 * @var array
41 * @access private
42 */
43 var $fields = array(
44 'bugid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'),
45 'userid' => array(TYPE_UINT, REQ_NO),
46 'username' => array(TYPE_STR, REQ_NO),
47 'dateline' => array(TYPE_UINT, REQ_SET),
48 'product' => array(TYPE_UINT, REQ_YES, ':self'),
49 'component' => array(TYPE_UINT, REQ_NO, ':self'),
50 'version' => array(TYPE_UINT, REQ_YES, ':self'),
51 'summary' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
52 'priority' => array(TYPE_UINT, REQ_NO, ':self'),
53 'severity' => array(TYPE_UINT, REQ_NO, ':self'),
54 'status' => array(TYPE_UINT, REQ_NO, ':self'),
55 'resolution' => array(TYPE_UINT, REQ_NO, ':self'),
56 'assignedto' => array(TYPE_UINT, REQ_NO, ':self', array('includes/api_user.php', 'UserAPI')),
57 'duplicateof' => array(TYPE_STR, REQ_NO),
58 'dependency' => array(TYPE_STR, REQ_NO),
59 'hidden' => array(TYPE_BOOL, REQ_NO),
60 'initialreport' => array(TYPE_UINT, REQ_NO),
61 'lastposttime' => array(TYPE_UINT, REQ_NO),
62 'lastpostby' => array(TYPE_UINT, REQ_NO),
63 'lastpostbyname' => array(TYPE_STR, REQ_NO),
64 'hiddenlastposttime' => array(TYPE_UINT, REQ_NO),
65 'hiddenlastpostby' => array(TYPE_UINT, REQ_NO),
66 'hiddenlastpostbyname' => array(TYPE_STR, REQ_NO)
67 );
68
69 /**
70 * Database table
71 * @var string
72 * @access private
73 */
74 var $table = 'bug';
75
76 /**
77 * Table prefix
78 * @var string
79 * @access private
80 */
81 var $prefix = TABLE_PREFIX;
82
83 // ###################################################################
84 /**
85 * Subclassed set() that will intercept any custom fields and handle
86 * them appropriately, but everyting else will be passed to the parent.
87 */
88 function set()
89 {
90 $args = func_get_args();
91
92 // it's a custom field, so add it in
93 if (preg_match('#^custom#', $args[0]) == 1 AND !isset($this->fields["$args[0]"]))
94 {
95 $this->fields["$args[0]"] = array(TYPE_STR, REQ_NO);
96 }
97
98 call_user_func_array(array($this, 'parent::set'), $args);
99 }
100
101 // ###################################################################
102 /**
103 * Set field: dateline
104 *
105 * @access private
106 */
107 function set_dateline()
108 {
109 $this->set('dateline', time());
110 }
111
112 // ###################################################################
113 /**
114 * Post-insert
115 *
116 * @access private
117 */
118 function post_insert()
119 {
120 $this->registry->db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)");
121 }
122
123 // ###################################################################
124 /**
125 * Post-delete
126 *
127 * @access private
128 */
129 function post_delete()
130 {
131 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "comment WHERE bugid = " . $this->values['bugid']);
132 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE bugid = " . $this->values['bugid']);
133 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE bugid = " . $this->values['bugid']);
134 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "vote WHERE bugid = " . $this->values['bugid']);
135 }
136
137 // ###################################################################
138 /**
139 * Verify: product
140 *
141 * @access private
142 */
143 function verify_product()
144 {
145 if (!($nozero = $this->verify_nozero('product')))
146 {
147 return $nozero;
148 }
149
150 if (!$this->registry->datastore['product'][ $this->values['product'] ])
151 {
152 return false;
153 }
154 return true;
155 }
156
157 // ###################################################################
158 /**
159 * Verify: componentid
160 *
161 * @access private
162 */
163 function verify_component()
164 {
165 if ($this->values['component'] != 0)
166 {
167 $component = $this->registry->datastore['component'][ $this->values['component'] ];
168 $product = $this->registry->datastore['product'][ $this->values['product'] ];
169 $version = $this->registry->datastore['version'][ $this->values['version'] ];
170 if ($component['parentid'] != $product['productid'])
171 {
172 return false;
173 }
174 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
175 {
176 return false;
177 }
178 }
179 return true;
180 }
181
182 // ###################################################################
183 /**
184 * Verify: versionid
185 *
186 * @access private
187 */
188 function verify_version()
189 {
190 if (!($nozero = $this->verify_nozero('version')))
191 {
192 return $nozero;
193 }
194
195 if (!$this->registry->datastore['version'][ $this->values['version'] ])
196 {
197 return false;
198 }
199 return true;
200 }
201
202 // ###################################################################
203 /**
204 * Verify: priority
205 *
206 * @access private
207 */
208 function verify_priority()
209 {
210 if (!$this->registry->datastore['priority'][ $this->values['priority'] ])
211 {
212 $this->set('priority', $this->registry->options['defaultpriority']);
213 }
214 return true;
215 }
216
217 // ###################################################################
218 /**
219 * Verify: severity
220 *
221 * @access private
222 */
223 function verify_severity()
224 {
225 if (!$this->registry->datastore['severity'][ $this->values['severity'] ])
226 {
227 $this->set('severity', $this->registry->options['defaultseverity']);
228 }
229 return true;
230 }
231
232 // ###################################################################
233 /**
234 * Verify: status
235 *
236 * @access private
237 */
238 function verify_status()
239 {
240 if (!$this->registry->datastore['status'][ $this->values['status'] ])
241 {
242 $this->set('status', $this->registry->options['defaultstatus']);
243 }
244 return true;
245 }
246
247 // ###################################################################
248 /**
249 * Verify: resolution
250 *
251 * @access private
252 */
253 function verify_resolution()
254 {
255 if (!$this->registry->datastore['resolution'][ $this->values['resolution'] ])
256 {
257 $this->set('resolution', $this->registry->options['defaultresolve']);
258 }
259 return true;
260 }
261
262 // ###################################################################
263 /**
264 * Verify: assignedto
265 *
266 * @access private
267 */
268 function verify_assignedto()
269 {
270 if (!$this->registry->datastore['assignto'][ $this->values['assignedto'] ] AND $this->values['assignedto'] != 0)
271 {
272 $this->set('assignedto', $this->registry->options['defaultassign']);
273 }
274 return true;
275 }
276 }
277
278 /*=====================================================================*\
279 || ###################################################################
280 || # $HeadURL$
281 || # $Id$
282 || ###################################################################
283 \*=====================================================================*/
284 ?>