3 // quick way to build SQL based on a form design..
4 // might have uses later...
6 require_once 'Pman.php';
8 class Pman_Builder_FormToSQL extends Pman {
11 if (!HTML_FlexyFramework::get()->cli) {
19 //print_R($_SERVER['argv']);exit;
20 $file = $_SERVER['argv'][2];
21 if (!file_exists($file)) {
22 die("file $file does not exist");
24 $o = json_decode(file_get_contents($file));
32 $this->flattenProps($o);
36 foreach((array)$o as $k=>$v) {
52 function flattenProps($o) {
53 if (empty($o->items)) {
57 foreach($o->items as $oo) {
58 if (!isset($oo->{'*props'})) {
62 $o->{$oo->{'*props'}} = $oo;
71 if (empty($o->xtype) || empty($o->{'|xns'})) {
74 if ($o->{'|xns'} != 'Roo.form') {
83 $f->size = min(255,max(8, pow(2, strlen(decbin(($o->width/2)-1)))));
88 if ($o->store->xtype == 'SimpleStore') {
89 $data = json_decode($o->store->{'|data'});
92 foreach($data as $row) {
93 if (is_numeric($row[0])) {
97 $len = strlen($row[0]);
100 if ($type == 'VARCHAR') {
101 $len = min(255,max(8, pow(2, strlen(decbin(($len))))));
105 $f->name = $o->name; // hiddenname?
123 if ($o->name == 'id') {
124 $f->extra = "AUTO_INCREMENT PRIMARY KEY";