2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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 (c)2004 - 2009, Blue Static
33 class FieldAPI
extends BSApi
39 protected $fields = array(
40 'fieldid' => array(TYPE_UINT
, REQ_AUTO
),
41 'name' => array(TYPE_STR
, REQ_YES
),
42 'description' => array(TYPE_STR
, REQ_NO
),
43 'type' => array(TYPE_STR
, REQ_YES
),
44 'selects' => array(TYPE_STR
, REQ_NO
),
45 'required' => array(TYPE_BOOL
, REQ_NO
),
46 'cansearch' => array(TYPE_BOOL
, REQ_NO
),
47 'regexmatch' => array(TYPE_STR
, REQ_NO
),
48 'defaultvalue' => array(TYPE_STR
, REQ_NO
),
49 'usedefault' => array(TYPE_BOOL
, REQ_NO
),
50 'maxlength' => array(TYPE_UINT
, REQ_NO
)
57 protected $table = 'bugfield';
63 protected $prefix = TABLE_PREFIX
;
66 * A static method that is used to return an array of all the allowed
69 * @param string Return the display name of a type if the key is passed
71 * @return array An array of all the allowed field types
73 public static function field_types($type = null)
76 'input_text' => T('Single-Line Text Box'),
77 'input_checkbox' => T('Checkbox Flag'),
78 'select_single' => T('Drop-Down Menu'),
87 return $types["$type"];
94 protected function post_insert()
102 protected function post_update()
110 protected function post_delete()
112 BSApp::$db->query("DELETE FROM
" . TABLE_PREFIX . "bugfield WHERE fieldid
= " . $this->values['fieldid']);
113 BSApp::$db->query("DELETE FROM
" . TABLE_PREFIX . "bugfieldpermission WHERE fieldid
= " . $this->values['fieldid']);
114 BSApp::$db->query("ALTER TABLE
" . TABLE_PREFIX . "bug DROP custom
" . $this->values['fieldid']);
115 BSApp::$db->query("OPTIMIZE TABLE
" . TABLE_PREFIX . "bug
");
123 protected function validate_fieldid($field)
125 return $this->_verifyIsNotZero($field);
131 protected function validate_name($field)
133 return $this->_verifyIsNotEmpty($field);
139 protected function validate_type()
141 if (!in_array($this->values['type'], array_keys(self::field_types())))
151 protected function validate_selects()
154 if ($this->values['type'] == 'select_single' || $this->record['type'] == 'select_single')
156 BSApp::debug('it works');
157 // can't use explode() here because explode() returns !empty() when splitting an empty string
158 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
159 $selects = preg_split("#\n#", trim($this->values['selects']), 0, PREG_SPLIT_NO_EMPTY);
160 array_walk($selects, 'trim');
161 if (sizeof($selects) < 1)
163 return T('You need to specify some select values.');
167 if ($serialized != serialize($selects))
169 $this->values
['selects'] = $serialized = serialize($selects);