]> src.bluestatic.org Git - bugdar.git/blob - includes/api_field.php
Update api_priority.php
[bugdar.git] / includes / api_field.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 $GLOBALS['isso:callback']->load('api', null);
23
24 require_once('./includes/functions_datastore.php');
25
26 /**
27 * API: Field
28 *
29 * @author Blue Static
30 * @copyright Copyright ©2002 - 2007, Blue Static
31 * @version $Revision$
32 * @package Bugdar
33 *
34 */
35 class FieldAPI extends API
36 {
37 /**
38 * Fields
39 * @var array
40 * @access private
41 */
42 var $fields = array(
43 'fieldid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'),
44 'name' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
45 'description' => array(TYPE_STR, REQ_NO),
46 'type' => array(TYPE_STR, REQ_YES, ':self'),
47 'selects' => array(TYPE_STR, REQ_NO, ':self'),
48 'required' => array(TYPE_BOOL, REQ_NO),
49 'cansearch' => array(TYPE_BOOL, REQ_NO),
50 'regexmatch' => array(TYPE_STR, REQ_NO),
51 'defaultvalue' => array(TYPE_STR, REQ_NO),
52 'usedefault' => array(TYPE_BOOL, REQ_NO),
53 'maxlength' => array(TYPE_UINT, REQ_NO)
54 );
55
56 /**
57 * Database table
58 * @var string
59 * @access private
60 */
61 var $table = 'bugfield';
62
63 /**
64 * Table prefix
65 * @var string
66 * @access private
67 */
68 var $prefix = TABLE_PREFIX;
69
70 // ###################################################################
71 /**
72 * A static method that is used to return an array of all the allowed
73 * field types.
74 *
75 * @access public
76 *
77 * @param string Return the display name of a type if the key is passed
78 *
79 * @return array An array of all the allowed field types
80 */
81 function field_types($type = null)
82 {
83 global $lang;
84 $types = array(
85 'input_text' => T('Single-Line Text Box'),
86 'input_checkbox' => T('Checkbox Flag'),
87 'select_single' => T('Drop-Down Menu'),
88 );
89
90 if ($type == null)
91 {
92 return $types;
93 }
94 else
95 {
96 return $types["$type"];
97 }
98 }
99
100 // ###################################################################
101 /**
102 * Post-insert
103 *
104 * @access private
105 */
106 function post_insert()
107 {
108 build_user_help();
109 }
110
111 // ###################################################################
112 /**
113 * Post-update
114 *
115 * @access private
116 */
117 function post_update()
118 {
119 build_user_help();
120 }
121
122 // ###################################################################
123 /**
124 * Post-delete
125 *
126 * @access private
127 */
128 function post_delete()
129 {
130 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . $this->values['fieldid']);
131 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $this->values['fieldid']);
132 $this->registry->db->query("ALTER TABLE " . TABLE_PREFIX . "bug DROP custom" . $this->values['fieldid']);
133 $this->registry->db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug");
134
135 build_user_help();
136 }
137
138 // ###################################################################
139 /**
140 * Verify: type
141 *
142 * @access private
143 */
144 function verify_type()
145 {
146 if (!in_array($this->values['type'], array_keys(FieldAPI::field_types())))
147 {
148 return false;
149 }
150 return true;
151 }
152
153 // ###################################################################
154 /**
155 * Verify: selects
156 *
157 * @access private
158 */
159 function verify_selects()
160 {
161 static $serialized;
162 if ($this->values['type'] == 'select_single' OR $this->record['type'] == 'select_single')
163 {
164 $this->registry->debug('it works');
165 // can't use explode() here because explode() returns !empty() when splitting an empty string
166 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
167 $selects = preg_split("#\n#", trim($this->values['selects']), 0, PREG_SPLIT_NO_EMPTY);
168 array_walk($selects, 'trim');
169 if (sizeof($selects) < 1)
170 {
171 return T('You need to specify some select values.');
172 }
173 else
174 {
175 if ($serialized != serialize($selects))
176 {
177 $this->values['selects'] = $serialized = serialize($selects);
178 }
179 }
180 }
181
182 return true;
183 }
184 }
185
186 /*=====================================================================*\
187 || ###################################################################
188 || # $HeadURL$
189 || # $Id$
190 || ###################################################################
191 \*=====================================================================*/
192 ?>