public function __construct() { //echo "constructing class"; $this->attributes = array_change_key_case(DB::MetaColumns($this->tableName()), CASE_LOWER); foreach (array_keys($this->attributes) as $att) { $this->attributevalues[$att] = array('value' => NULL, 'persistedvalue' => NULL); } foreach ($this->attributes as $att) { if ($att->has_default) { $this->att($att->name, $att->default_value); } } }
public function add_table($table_name, array $cols, &$js = '') { //TODO: add group here? $meta_table = DB::MetaColumns($table_name); $arr = array(); foreach ($cols as $k => $v) { if (is_string($k)) { if (is_array($v) && !isset($v['name'])) { $v['name'] = $k; } elseif (is_string($v)) { $v = array('name' => $k, 'label' => $v); } else { trigger_error('Invalid arguments to add_table quick form method', E_USER_ERROR); } } $name = strtoupper($v['name']); $meta =& $meta_table[$name]; if (!is_object($meta)) { $arr[] = $v; continue; } if (isset($v['rule']['message']) && isset($v['rule']['type'])) { $v['rule'] = array($v['rule']); } if (!isset($v['default']) && $meta->has_default) { $v['default'] = $meta->default_value; } $type = DB::dict()->MetaType($meta); if (!isset($v['type'])) { switch ($type) { case 'C': $v['type'] = 'text'; break; case 'X': $v['type'] = 'textarea'; break; case 'I': case 'I2': case 'I4': case 'I8': case 'F': $v['type'] = 'numeric'; break; case 'I1': $v['type'] = 'checkbox'; break; } } if (($v['type'] == 'text' || $v['type'] == 'password' || $v['type'] == 'textarea') && !isset($v['default'])) { $v['default'] = ''; } if ($meta->max_length > 0) { if (!isset($v['rule'])) { $v['rule'] = array(); } $v['rule'][] = array('message' => __('Text too long'), 'type' => 'maxlength', 'param' => $meta->max_length); if (!isset($v['param'])) { $v['param'] = array(); } if (is_string($v['param'])) { $v['param'] .= ' maxlength=\'' . $meta->max_length . '\''; } else { $v['param']['maxlength'] = $meta->max_length; } } if ($meta->not_null) { if (!isset($v['rule'])) { $v['rule'] = array(); } $v['rule'][] = array('message' => __('Field required'), 'type' => 'required'); } $arr[] = $v; } $this->add_array($arr, $js); }