array(TYPE_UINT, REQ_AUTO), 'name' => array(TYPE_STR, REQ_YES), 'description' => array(TYPE_STR, REQ_NO), 'type' => array(TYPE_STR, REQ_YES), 'selects' => array(TYPE_STR, REQ_NO), 'required' => array(TYPE_BOOL, REQ_NO), 'cansearch' => array(TYPE_BOOL, REQ_NO), 'regexmatch' => array(TYPE_STR, REQ_NO), 'defaultvalue' => array(TYPE_STR, REQ_NO), 'usedefault' => array(TYPE_BOOL, REQ_NO), 'maxlength' => array(TYPE_UINT, REQ_NO) ); /** * Database table * @var string */ protected $table = 'bugfield'; /** * Table prefix * @var string */ protected $prefix = TABLE_PREFIX; /** * A static method that is used to return an array of all the allowed * field types. * * @param string Return the display name of a type if the key is passed * * @return array An array of all the allowed field types */ public static function field_types($type = null) { $types = array( 'input_text' => T('Single-Line Text Box'), 'input_checkbox' => T('Checkbox Flag'), 'select_single' => T('Drop-Down Menu'), ); if ($type == null) { return $types; } else { return $types["$type"]; } } /** * Post-insert */ protected function post_insert() { build_user_help(); } /** * Post-update */ protected function post_update() { build_user_help(); } /** * Post-delete */ protected function post_delete() { BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . $this->values['fieldid']); BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $this->values['fieldid']); BSApp::$db->query("ALTER TABLE " . TABLE_PREFIX . "bug DROP custom" . $this->values['fieldid']); BSApp::$db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bug"); build_user_help(); } /** * Validate: fieldid */ protected function validate_fieldid($field) { return $this->_verifyIsNotZero($field); } /** * Validate: name */ protected function validate_name($field) { return $this->_verifyIsNotEmpty($field); } /** * Validate: type */ protected function validate_type() { if (!in_array($this->values['type'], array_keys(self::field_types()))) { return false; } return true; } /** * Validate: selects */ protected function validate_selects() { static $serialized; if ($this->values['type'] == 'select_single' || $this->record['type'] == 'select_single') { BSApp::debug('it works'); // can't use explode() here because explode() returns !empty() when splitting an empty string // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this $selects = preg_split("#\n#", trim($this->values['selects']), 0, PREG_SPLIT_NO_EMPTY); array_walk($selects, 'trim'); if (sizeof($selects) < 1) { return T('You need to specify some select values.'); } else { if ($serialized != serialize($selects)) { $this->values['selects'] = $serialized = serialize($selects); } } } return true; } } ?>