4 * @author Marius Orcsik <marius@habarnam.ro>
10 define ('FULLTEXT', 8);
12 class tdoAbstractField
{
13 static public $validTypes = array (
23 protected $name, $type, $flags, $value, $table, $modifier = null, $order = null, $group = null, $where = false;
25 public function __construct ($incName, $incTable, $incType='INT', $incFlags=0) {
26 $this->name
= $incName;
27 $this->table
= $incTable;
28 $this->type
= $incType;
29 $this->flags
= $incFlags;
32 public function __set ( $key, $value ) {
33 // var_dump($key, $value);
34 if ( array_key_exists ($key, get_object_vars($this)) ) {
37 // if ($key == 'where')
40 if ( is_null ($this->type
) ) {
49 public function __get ( $key ) {
50 // if ($key == 'value' && !$this->value)
55 public function __call ( $method, $args) {
56 $all = get_object_vars($this);
58 if ( preg_match( '/set_(.*)/', $method, $found ) ) {
59 if (array_key_exists( $found[1], $all)){
60 $this->$found[1] = $args[0];
63 } elseif ( preg_match( '/get_(.*)/', $method, $found ) ) {
64 if (array_key_exists( $found[1], $all)){
65 return $this->$found[1];
71 public function __destruct () {}
73 public function __toString () {
74 return (string)$this->value
;
77 // public function inWhere () {
78 // return $this->where;
81 static public function isValidType ($inc) {
82 if (in_array($inc, tdoAbstractField
::$validTypes)){
88 public function set_modifier ($modif) {
89 // if (stristr($modif, '%'))
90 $this->modifier
= $modif;
93 public function set_value ($value) {
94 $this->value
= $value;
97 public function set_group ($true = true) {
98 $this->group
= (bool)$true;
101 public function set_order ($asc = true) {
102 $this->order
= (bool)$asc;
105 public function isIndex() {
106 return (($this->flags
& INDEX
) == INDEX
);
109 public function isPrimary() {
110 return (($this->flags
& PRIMARY
) == PRIMARY
);
113 public function isFullText() {
114 return (($this->flags
& FULLTEXT
) == FULLTEXT
);
117 public function isUnique () {
118 return (($this->flags
& UNIQUE
) == UNIQUE
);
121 public function setType () {
122 $incValue = $this->value
;
124 if (is_int($incValue)) {
126 } elseif (is_float($incValue)) {
127 $this->type
= 'FLOAT';
128 } elseif (is_string($incValue)) {
129 if (strtotime($this->value
)){
130 $this->type
= 'DATE';
131 }elseif (strlen($incValue) > 255)
132 $this->type
= 'TEXT';
134 $this->type
= 'VARCHAR';