-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.php
executable file
·39 lines (34 loc) · 1.13 KB
/
Field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
class Field {
public $name;
public $label;
public $type; //text, select, image, number, checkbox, radio, select-multiple, checkbox-multiple, password, email... for HTML generation
public $defaut; //default value
public $placeholder;
public $options; //options if it's select
public $datatype = 'varchar'; //sql datatype
public $length; //contraint of length
public $required;
public $hidden;
public $sql;
public function buildSQL() {
$sql = '`'.$this->name. '` '. $this->datatype.'('.$this->length.') ';
if ($this->default !== null) {
$sql . 'NOT NULL';
}
return $sql;
}
public function __construct($name, $label, $required = false, $type = 'text', $hidden = false, $default = null, $placeholder = '', $length = 512, $options = null, $datatype = 'varchar') {
$this->name = $name;
$this->label = $label;
$this->required = $required;
$this->type = $type;
$this->default = $default;
$this->placeholder = $placeholder;
$this->option = $options;
$this->datatype = $datatype;
$this->length = $length;
$this->hidden = $hidden;
$this->sql = $this->buildSQL();
}
}