* making the fracking paginator work
[vsc.git] / _res / _libs / models / tdoabstractfield.class.php
blob8375b0418cdb03d95f77a83e227bbbde16e2e4fc
1 <?php
2 /**
3 * @package ts_models
4 * @author Marius Orcsik <marius@habarnam.ro>
5 * @date 09.02.27
6 */
7 define ('INDEX', 1);
8 define ('PRIMARY', 2);
9 define ('UNIQUE', 4);
10 define ('FULLTEXT', 8);
12 class tdoAbstractField {
13 static public $validTypes = array (
14 'VARCHAR',
15 'INT',
16 'DATE',
17 'TEXT',
18 'FLOAT',
19 'TIMESTAMP',
20 'ENUM'
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)) ) {
35 $this->$key = $value;
37 // if ($key == 'where')
38 // var_dump($this);
40 if ( is_null ($this->type) ) {
41 $this->setType();
44 return true;
45 } else
46 return false;
49 public function __get ( $key ) {
50 // if ($key == 'value' && !$this->value)
51 // return null;
52 return $this->$key;
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];
61 return true;
63 } elseif ( preg_match( '/get_(.*)/', $method, $found ) ) {
64 if (array_key_exists( $found[1], $all)){
65 return $this->$found[1];
68 return false;
71 public function __destruct () {}
73 public function __toString () {
74 return (string)$this->value;
77 // public function inWhere () {
78 // return $this->where;
79 // }
81 static public function isValidType ($inc) {
82 if (in_array($inc, tdoAbstractField::$validTypes)){
83 return true;
85 return false;
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;
123 // TODO : enums
124 if (is_int($incValue)) {
125 $this->type = 'INT';
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';
133 else
134 $this->type = 'VARCHAR';