r821: 0 is a fine assignedto number
[bugdar.git] / includes / api_bug.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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, esverity, status, and resolution should throw a
28 * verification error, they actually set it to the default value
29 *
30 * @author Iris Studios, Inc.
31 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
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 'dateline' => array(TYPE_UINT, REQ_SET),
47 'productid' => array(TYPE_UINT, REQ_YES, ':self'),
48 'componentid' => array(TYPE_UINT, REQ_NO, ':self'),
49 'versionid' => array(TYPE_UINT, REQ_YES, ':self'),
50 'summary' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
51 'priority' => array(TYPE_UINT, REQ_NO, ':self'),
52 'severity' => array(TYPE_UINT, REQ_NO, ':self'),
53 'status' => array(TYPE_UINT, REQ_NO, ':self'),
54 'resolution' => array(TYPE_UINT, REQ_NO, ':self'),
55 'assignedto' => array(TYPE_UINT, REQ_NO, ':self', array('includes/api_user.php', 'UserAPI')),
56 'duplicateof' => array(TYPE_STR, REQ_NO),
57 'dependency' => array(TYPE_STR, REQ_NO),
58 'hidden' => array(TYPE_BOOL, REQ_NO),
59 'initialreport' => array(TYPE_UINT, REQ_NO),
60 'lastposttime' => array(TYPE_UINT, REQ_NO),
61 'lastpostby' => array(TYPE_UINT, REQ_NO),
62 'hiddenlastposttime' => array(TYPE_UINT, REQ_NO),
63 'hiddenlastpostby' => array(TYPE_UINT, REQ_NO)
64 );
65
66 /**
67 * Database table
68 * @var string
69 * @access private
70 */
71 var $table = 'bug';
72
73 /**
74 * Table prefix
75 * @var string
76 * @access private
77 */
78 var $prefix = TABLE_PREFIX;
79
80 // ###################################################################
81 /**
82 * Set field: dateline
83 *
84 * @access private
85 */
86 function set_dateline()
87 {
88 $this->set('dateline', time());
89 }
90
91 // ###################################################################
92 /**
93 * Post-insert
94 *
95 * @access private
96 */
97 function post_insert()
98 {
99 $this->registry->db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)");
100 }
101
102 // ###################################################################
103 /**
104 * Verify: productid
105 *
106 * @access private
107 */
108 function verify_productid()
109 {
110 $this->verify_nozero('productid');
111
112 if (!$this->registry->datastore['product'][ $this->values['productid'] ])
113 {
114 return false;
115 }
116 return true;
117 }
118
119 // ###################################################################
120 /**
121 * Verify: componentid
122 *
123 * @access private
124 */
125 function verify_componentid()
126 {
127 if ($this->values['componentid'] != 0)
128 {
129 $product = $this->registry->datastore['product'][ $this->values['product'] ];
130 $version = $this->registry->datastore['version'][ $this->values['version'] ];
131 if ($component['componentmother'] != $product['productid'])
132 {
133 return false;
134 }
135 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
136 {
137 return false;
138 }
139 }
140 return true;
141 }
142
143 // ###################################################################
144 /**
145 * Verify: versionid
146 *
147 * @access private
148 */
149 function verify_versionid()
150 {
151 $this->verify_nozero('versionid');
152
153 if (!$this->registry->datastore['version'][ $this->values['versionid'] ])
154 {
155 return false;
156 }
157 return true;
158 }
159
160 // ###################################################################
161 /**
162 * Verify: priority
163 *
164 * @access private
165 */
166 function verify_priority()
167 {
168 if (!$this->registry->datastore['priority'][ $this->values['priority'] ])
169 {
170 $this->set('priority', $this->registry->options['defaultpriority']);
171 }
172 return true;
173 }
174
175 // ###################################################################
176 /**
177 * Verify: severity
178 *
179 * @access private
180 */
181 function verify_severity()
182 {
183 if (!$this->registry->datastore['severity'][ $this->values['severity'] ])
184 {
185 $this->set('severity', $this->registry->options['defaultseverity']);
186 }
187 return true;
188 }
189
190 // ###################################################################
191 /**
192 * Verify: status
193 *
194 * @access private
195 */
196 function verify_status()
197 {
198 if (!$this->registry->datastore['status'][ $this->values['status'] ])
199 {
200 $this->set('status', $this->registry->options['defaultstatus']);
201 }
202 return true;
203 }
204
205 // ###################################################################
206 /**
207 * Verify: resolution
208 *
209 * @access private
210 */
211 function verify_resolution()
212 {
213 if (!$this->registry->datastore['resolution'][ $this->values['resolution'] ])
214 {
215 $this->set('resolution', $this->registry->options['defaultresolve']);
216 }
217 return true;
218 }
219
220 // ###################################################################
221 /**
222 * Verify: assignedto
223 *
224 * @access private
225 */
226 function verify_assignedto()
227 {
228 if (!$this->registry->datastore['assignto'][ $this->values['assignedto'] ] AND $this->values['assignedto'] != 0)
229 {
230 $this->set('assignedto', $this->registry->options['defaultassign']);
231 }
232 return true;
233 }
234 }
235
236 /*=====================================================================*\
237 || ###################################################################
238 || # $HeadURL$
239 || # $Id$
240 || ###################################################################
241 \*=====================================================================*/
242 ?>