r844: Removing the complex joins for bugs by caching user information on
[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 'username' => array(TYPE_STR, REQ_NO),
47 'dateline' => array(TYPE_UINT, REQ_SET),
48 'productid' => array(TYPE_UINT, REQ_YES, ':self'),
49 'componentid' => array(TYPE_UINT, REQ_NO, ':self'),
50 'versionid' => 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 * Set field: dateline
86 *
87 * @access private
88 */
89 function set_dateline()
90 {
91 $this->set('dateline', time());
92 }
93
94 // ###################################################################
95 /**
96 * Post-insert
97 *
98 * @access private
99 */
100 function post_insert()
101 {
102 $this->registry->db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES (" . $this->insertid . ", 0, 0)");
103 }
104
105 // ###################################################################
106 /**
107 * Verify: productid
108 *
109 * @access private
110 */
111 function verify_productid()
112 {
113 $this->verify_nozero('productid');
114
115 if (!$this->registry->datastore['product'][ $this->values['productid'] ])
116 {
117 return false;
118 }
119 return true;
120 }
121
122 // ###################################################################
123 /**
124 * Verify: componentid
125 *
126 * @access private
127 */
128 function verify_componentid()
129 {
130 if ($this->values['componentid'] != 0)
131 {
132 $product = $this->registry->datastore['product'][ $this->values['product'] ];
133 $version = $this->registry->datastore['version'][ $this->values['version'] ];
134 if ($component['componentmother'] != $product['productid'])
135 {
136 return false;
137 }
138 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
139 {
140 return false;
141 }
142 }
143 return true;
144 }
145
146 // ###################################################################
147 /**
148 * Verify: versionid
149 *
150 * @access private
151 */
152 function verify_versionid()
153 {
154 $this->verify_nozero('versionid');
155
156 if (!$this->registry->datastore['version'][ $this->values['versionid'] ])
157 {
158 return false;
159 }
160 return true;
161 }
162
163 // ###################################################################
164 /**
165 * Verify: priority
166 *
167 * @access private
168 */
169 function verify_priority()
170 {
171 if (!$this->registry->datastore['priority'][ $this->values['priority'] ])
172 {
173 $this->set('priority', $this->registry->options['defaultpriority']);
174 }
175 return true;
176 }
177
178 // ###################################################################
179 /**
180 * Verify: severity
181 *
182 * @access private
183 */
184 function verify_severity()
185 {
186 if (!$this->registry->datastore['severity'][ $this->values['severity'] ])
187 {
188 $this->set('severity', $this->registry->options['defaultseverity']);
189 }
190 return true;
191 }
192
193 // ###################################################################
194 /**
195 * Verify: status
196 *
197 * @access private
198 */
199 function verify_status()
200 {
201 if (!$this->registry->datastore['status'][ $this->values['status'] ])
202 {
203 $this->set('status', $this->registry->options['defaultstatus']);
204 }
205 return true;
206 }
207
208 // ###################################################################
209 /**
210 * Verify: resolution
211 *
212 * @access private
213 */
214 function verify_resolution()
215 {
216 if (!$this->registry->datastore['resolution'][ $this->values['resolution'] ])
217 {
218 $this->set('resolution', $this->registry->options['defaultresolve']);
219 }
220 return true;
221 }
222
223 // ###################################################################
224 /**
225 * Verify: assignedto
226 *
227 * @access private
228 */
229 function verify_assignedto()
230 {
231 if (!$this->registry->datastore['assignto'][ $this->values['assignedto'] ] AND $this->values['assignedto'] != 0)
232 {
233 $this->set('assignedto', $this->registry->options['defaultassign']);
234 }
235 return true;
236 }
237 }
238
239 /*=====================================================================*\
240 || ###################################################################
241 || # $HeadURL$
242 || # $Id$
243 || ###################################################################
244 \*=====================================================================*/
245 ?>