Getting newreport.php to work, sans notifications
[bugdar.git] / includes / api_bug.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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 2 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 require_once ISSO . '/Api.php';
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 - 2007, Blue Static
32 * @version $Revision$
33 * @package Bugdar
34 *
35 */
36 class BugAPI extends BSApi
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($field, $value, $doclean = true, $doverify = true)
89 {
90 // it's a custom field, so add it in
91 if (preg_match('#^custom#', $field) == 1 AND !isset($this->fields["$field"]))
92 {
93 $this->fields["$field"] = array(TYPE_STR, REQ_NO);
94 }
95
96 // TODO - (r1524) one day we can change this back to call_user_func_array(array($this, 'parent::set'), func_get_args())
97 parent::set($field, $value, $doclean, $doverify);
98 }
99
100 // ###################################################################
101 /**
102 * Set field: dateline
103 *
104 * @access private
105 */
106 function set_dateline()
107 {
108 $this->set('dateline', time());
109 }
110
111 // ###################################################################
112 /**
113 * Post-insert
114 *
115 * @access private
116 */
117 function post_insert()
118 {
119 BSApp::$db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)");
120 }
121
122 // ###################################################################
123 /**
124 * Post-delete
125 *
126 * @access private
127 */
128 function post_delete()
129 {
130 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "comment WHERE bugid = " . $this->values['bugid']);
131 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "favorite WHERE bugid = " . $this->values['bugid']);
132 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE bugid = " . $this->values['bugid']);
133 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "vote WHERE bugid = " . $this->values['bugid']);
134 }
135
136 // ###################################################################
137 /**
138 * Verify: product
139 *
140 * @access private
141 */
142 function verify_product()
143 {
144 if (!($nozero = $this->verify_nozero('product')))
145 {
146 return $nozero;
147 }
148
149 if (!bugdar::$datastore['product'][ $this->values['product'] ])
150 {
151 return false;
152 }
153 return true;
154 }
155
156 // ###################################################################
157 /**
158 * Verify: componentid
159 *
160 * @access private
161 */
162 function verify_component()
163 {
164 if ($this->values['component'] != 0)
165 {
166 $component = bugdar::$datastore['component'][ $this->values['component'] ];
167 $product = bugdar::$datastore['product'][ $this->values['product'] ];
168 $version = bugdar::$datastore['version'][ $this->values['version'] ];
169 if ($component['parentid'] != $product['productid'])
170 {
171 return false;
172 }
173 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
174 {
175 return false;
176 }
177 }
178 return true;
179 }
180
181 // ###################################################################
182 /**
183 * Verify: versionid
184 *
185 * @access private
186 */
187 function verify_version()
188 {
189 if (!($nozero = $this->verify_nozero('version')))
190 {
191 return $nozero;
192 }
193
194 if (!bugdar::$datastore['version'][ $this->values['version'] ])
195 {
196 return false;
197 }
198 return true;
199 }
200
201 // ###################################################################
202 /**
203 * Verify: priority
204 *
205 * @access private
206 */
207 function verify_priority()
208 {
209 if (!bugdar::$datastore['priority'][ $this->values['priority'] ])
210 {
211 $this->set('priority', bugdar::$options['defaultpriority']);
212 }
213 return true;
214 }
215
216 // ###################################################################
217 /**
218 * Verify: severity
219 *
220 * @access private
221 */
222 function verify_severity()
223 {
224 if (!bugdar::$datastore['severity'][ $this->values['severity'] ])
225 {
226 $this->set('severity', bugdar::$options['defaultseverity']);
227 }
228 return true;
229 }
230
231 // ###################################################################
232 /**
233 * Verify: status
234 *
235 * @access private
236 */
237 function verify_status()
238 {
239 if (!bugdar::$datastore['status'][ $this->values['status'] ])
240 {
241 $this->set('status', bugdar::$options['defaultstatus']);
242 }
243 return true;
244 }
245
246 // ###################################################################
247 /**
248 * Verify: resolution
249 *
250 * @access private
251 */
252 function verify_resolution()
253 {
254 if (!bugdar::$datastore['resolution'][ $this->values['resolution'] ])
255 {
256 $this->set('resolution', bugdar::$options['defaultresolve']);
257 }
258 return true;
259 }
260
261 // ###################################################################
262 /**
263 * Verify: assignedto
264 *
265 * @access private
266 */
267 function verify_assignedto()
268 {
269 if (!bugdar::$datastore['assignto'][ $this->values['assignedto'] ] AND $this->values['assignedto'] != 0)
270 {
271 $this->set('assignedto', bugdar::$options['defaultassign']);
272 }
273 return true;
274 }
275 }
276
277 /*=====================================================================*\
278 || ###################################################################
279 || # $HeadURL$
280 || # $Id$
281 || ###################################################################
282 \*=====================================================================*/
283 ?>