name = isset($options[$c = self::NAME]) ? (string)$options[$c] : ''; $this->real_name = isset($options[$c = self::REAL_NAME]) ? $options[$c] : null; $this->type = isset($options[$c = self::TYPE]) ? (int)$options[$c] : ''; $this->real_type = isset($options[$c = self::REAL_TYPE]) ? (int)$options[$c] : ''; $this->length = isset($options[$c = self::LENGTH]) ? $options[$c] : null; $this->null = isset($options[$c = self::NULL]) ? boolval($options[$c]) : ''; $this->auto_increment = isset($options[$c = self::AUTO_INCREMENT]) ? boolval($options[$c]) : ''; $this->primary = isset($options[$c = self::PRIMARY]) ? boolval($options[$c]) : ''; $this->col_default = isset($options[$c = self::COL_DEFAULT]) ? (string)$options[$c] : null; $this->default = isset($options[$c = self::DEFAULT]) ? (string)$options[$c] : null; $this->unique = isset($options[$c = self::UNIQUE]) ? boolval($options[$c]) : null; $this->th = isset($options[$c = self::TH]) ? $options[$c] : null; $this->func_value = isset($options[$c = self::FUNC_VALUE]) ? $options[$c] : null; $this->func_value_data = isset($options[$c = self::FUNC_VALUE_DATA]) ? $options[$c] : null; $this->hidden = isset($options[$c = self::HIDDEN]) ? boolval($options[$c]) : null; $this->is_sort = isset($options[$c = self::NO_SORT]) ? !boolval($options[$c]) : false; $this->filter_input = isset($options[$c = self::FILTER_INPUT]) ? $options[$c] : 'default'; $this->filter_columns = isset($options[$c = self::FILTER_COLUMNS]) ? $options[$c] : []; $this->func_filter_query = isset($options[$c = self::FUNC_FILTER_QUERY]) ? $options[$c] : null; $this->td_class = isset($options[$c = self::TD_CLASS]) ? $options[$c] : null; $this->th_class = isset($options[$c = self::TH_CLASS]) ? $options[$c] : null; $this->func_td_input = isset($options[$c = self::FUNC_TD_INPUT]) ? $options[$c] : null; $this->total_function = isset($options[$c = self::TOTAL_FUNCTION]) ? $options[$c] : null; $this->filter_type = isset($options[$c = self::FILTER_TYPE]) ? $options[$c] : null; $this->func_filter_select_options = isset($options[$c = self::FUNC_FILTER_SELECT_OPTIONS]) ? $options[$c] : null; $this->func_export_data = isset($options[$c = self::FUNC_EXPORT_DATA]) ? $options[$c] : null; $this->export = isset($options[$c = self::EXPORT]) ? $options[$c] : true; //$this->to_table_filter = isset($options[$c = self::TO_TABLE_FILTER]) ? $options[$c] : null; $this->options = $options; if(isset($options[$c = self::VAR_NAME])) { $this->setName( (string)$options[$c] ); } } public function getValue($object=null){ if($this->func_value!=null){ $x = $this->func_value; return $x($object); } else { return (h( isset($object[$this->name]) ? $object[$this->name] : '' ));} } public function getValueData($object=null){ if($this->func_value_data!=null){ $x = $this->func_value_data; return $x($object); } else { return (( isset($object[$this->name]) ? $object[$this->name] : '' ));} } public function getExportData($object=null){ if($this->func_export_data!=null){ $x = $this->func_export_data; return $x($object); } else { return $this->getValueData($object); } } public function getFilterSelectOptions(){ if(get_class($this->func_filter_select_options)=="Closure"){ $x = $this->func_filter_select_options; $res = $x(); } else { $res = []; } return $res; } public function getFilterType(){return $this->filter_type;} public function getType(){return $this->type;} public function getName(){return $this->name;} public function getRealName(){ $res = $this->name; if(get_class($this->real_name)=="Closure"){ $x = $this->real_name; $res = $x(); } else if ($c = $this->real_name){ $res = $c; } return $res; } public function getRealType(){return ($c = $this->real_type)?$c:$this->type;} public function getFuctInput(){return ($c = $this->filter_input)?$c:$this->filter_input;} public function getTableFilter(){return ($c = $this->to_table_filter)?$c:$this->to_table_filter;} public function getTdClass(){return ($c = $this->td_class)?$c:'';} public function getThClass(){return ($c = $this->th_class)?$c:'';} public function getTh(){ if ($c = $this->th) { if(get_class($this->th)=="Closure"){ $x = $this->th; return $x(); } else { return $this->th; } } else return $this->getName(); } public function isHidden(){return $this->hidden;} public function setName(string $name){ $this->options[self::VAR_NAME] = $name; $this->name = $name; } public function getPrimary(){return $this->primary;} public function getDefault(){return $this->default;} public function getUnique(){return $this->unique;} public function isSort(){return boolval($this->is_sort);} public function isNull(){return boolval($this->null);} public function getTdInput($v) { if (!$this->func_td_input) return null; $x = $this->func_td_input; return $x($v); } public function getFilterQuery($query) { if (!$this->func_filter_query) return null; $x = $this->func_filter_query; return $x($query); } public function getFilterInputData(){ if(!$this->filter_input) return null; else return $this->filter_input; } public function getFilterInput($value){ if(!$this->filter_input) return null; if($this->filter_input=='default'){ $x = $this->filter_columns; $cols = 'data-columns="'.($x!=null?implode(",",$x($value)):'').'"'; switch ($this->getRealType()){ case eColumnType::DOUBLE: case eColumnType::INT: case eColumnType::TEXT: case eColumnType::VARCHAR: return ''; case eColumnType::DATE: // pickadate $vv = explode("-",$value); $value2 = $value; if(count($vv)==2){ $value = $vv[0]; $value2 = $vv[1]; } return ''. ''; } } else { $x = $this->filter_input; return $x($value); } return null; } function toStringForCreateTable(){ $types = eColumnType::getInfo(); $type = $types[$this->type]['name']; switch ($this->type) { case eColumnType::DOUBLE: if($this->length!=null) { $type .= '(' . $this->length . ')'; } break; case eColumnType::INT: case eColumnType::VARCHAR: case eColumnType::TINYINT: if($this->length===null) { $this->length = $types[$this->type]['default_length']; } $type .= '('.$this->length.')'; break; default:; } return "`".$this->name."` ". $type." ". ($this->null ? '' : ' NOT ')." NULL ". ($this->auto_increment ? ' AUTO_INCREMENT ':''). ($this->col_default !== null ? "DEFAULT '".(string)$this->col_default."'" : '') ; } }