2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 require_once ISSO
. '/Api.php';
23 require_once('./includes/functions_datastore.php');
29 * @copyright Copyright ©2002 - 2007, Blue Static
34 class FieldAPI
extends BSApi
40 protected $fields = array(
41 'fieldid' => array(TYPE_UINT
, REQ_AUTO
),
42 'name' => array(TYPE_STR
, REQ_YES
),
43 'description' => array(TYPE_STR
, REQ_NO
),
44 'type' => array(TYPE_STR
, REQ_YES
),
45 'selects' => array(TYPE_STR
, REQ_NO
),
46 'required' => array(TYPE_BOOL
, REQ_NO
),
47 'cansearch' => array(TYPE_BOOL
, REQ_NO
),
48 'regexmatch' => array(TYPE_STR
, REQ_NO
),
49 'defaultvalue' => array(TYPE_STR
, REQ_NO
),
50 'usedefault' => array(TYPE_BOOL
, REQ_NO
),
51 'maxlength' => array(TYPE_UINT
, REQ_NO
)
58 protected $table = 'bugfield';
64 protected $prefix = TABLE_PREFIX
;
67 * A static method that is used to return an array of all the allowed
70 * @param string Return the display name of a type if the key is passed
72 * @return array An array of all the allowed field types
74 public static function field_types($type = null
)
77 'input_text' => T('Single-Line Text Box'),
78 'input_checkbox' => T('Checkbox Flag'),
79 'select_single' => T('Drop-Down Menu'),
88 return $types["$type"];
95 protected function post_insert()
103 protected function post_update()
111 protected function post_delete()
113 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . $this->values
['fieldid']);
114 BSApp
::$db->query("DELETE FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = " . $this->values
['fieldid']);
115 BSApp
::$db->query("ALTER TABLE " . TABLE_PREFIX
. "bug DROP custom" . $this->values
['fieldid']);
116 BSApp
::$db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bug");
124 protected function validate_fieldid($field)
126 return $this->_verifyIsNotZero($field);
132 protected function validate_name($field)
134 return $this->_verifyIsNotEmpty($field);
140 protected function validate_type()
142 if (!in_array($this->values
['type'], array_keys(self
::field_types())))
152 protected function validate_selects()
155 if ($this->values
['type'] == 'select_single' ||
$this->record
['type'] == 'select_single')
157 BSApp
::debug('it works');
158 // can't use explode() here because explode() returns !empty() when splitting an empty string
159 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
160 $selects = preg_split("#\n#", trim($this->values
['selects']), 0, PREG_SPLIT_NO_EMPTY
);
161 array_walk($selects, 'trim');
162 if (sizeof($selects) < 1)
164 return T('You need to specify some select values.');
168 if ($serialized != serialize($selects))
170 $this->values
['selects'] = $serialized = serialize($selects);
179 /*=====================================================================*\
180 || ###################################################################
183 || ###################################################################
184 \*=====================================================================*/