This repository has been archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbtoobject.php
97 lines (83 loc) · 3.04 KB
/
dbtoobject.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once('./smarty/libs/Smarty.class.php');
// list of the possible db -> see the file to choose the correct database
require_once('./config/config.inc.php');
require_once('./xmlutilities.php');
require_once('./utilities.php');
$smarty = new Smarty;
$smarty->template_dir = './templates';
$smarty->compile_dir = './smarty/demo/templates_c';
$smarty->config_dir = './smarty/demo/configs';
class MyObject{
public $fieldName;
public $fieldType;
public $fieldLenght;
public $canBeNull;
public $autoIncrement;
public $pk;
}
$selectedProject = $storegameContext;
//$selectedProject = $amandaContext;
$pojoDirectory = $selectedProject->getPojoDirectory();
$datamodelDirectory = $selectedProject->getDataModelDirectory();
//$statement = "SHOW TABLES";
//$tables = $bdd->query($statement);
$smarty->registerObject('MyObject',new MyObject(),null,false);
$d = dir($datamodelDirectory);
while($filename = $d->read()) {
$extension = FileGetExtension::method_pathinfo($filename);
if ($extension === "xml") {
$object = fileToObject($datamodelDirectory.$filename);
$table = $object->root->attributes["name"];
$smarty->assign("tableName", $table);
echo "Process ".$filename." -> ";
$field_name_array = array();
$childList = $object->root->children;
$nbChildren = count($childList);
for ($i=0; $i < $nbChildren; $i++) {
$child = $childList[$i];
$field_name = $child->attributes["name"];
$field_type = $child->attributes["type"];
$field_lenght = $child->attributes["lenght"];
$canBeNull = $child->attributes['nullable'];
$autoIncrement = $child->attributes['autoincrement'];
$pk = $child->attributes['pk'];
$fieldObject = new MyObject();
$fieldObject->fieldName = $field_name;
$fieldObject->fieldType = $field_type;
$fieldObject->fieldLenght = $field_lenght;
$fieldObject->canBeNull = $canBeNull == 'true';
$fieldObject->autoIncrement = $autoIncrement === 'true';
$fieldObject->pk = $pk === 'true';
$field_name_array[$field_name] = $fieldObject;
}
$smarty->assignByRef("fieldNameArray", $field_name_array);
$to_write = $smarty->fetch('table.tpl');
$file_name = $pojoDirectory.$table.".class";
echo "Generating ".$file_name."</BR>";
$fh = fopen($file_name, "w+b") or die("Can't open file");
fwrite($fh, $to_write);
fclose($fh);
}
}
$d->close();
$smarty = new Smarty;
$smarty->template_dir = './templates';
$smarty->compile_dir = './smarty/demo/templates_c';
$smarty->config_dir = './smarty/demo/configs';
/**echo "Generating model.php</BR>";
$to_write = $smarty->fetch('model.tpl');
$file_name = $pojoDirectory."/model.php";
$fh = fopen($file_name, "w+b") or die("Can't open file");
fwrite($fh, $to_write);
fclose($fh);*/
echo "Clearing cache</BR>";
$d = dir("./smarty/demo/templates_c");
while($filename = $d->read()) {
$extension = FileGetExtension::method_pathinfo($filename);
if ($extension === "php") {
unlink("./smarty/demo/templates_c/".$filename);
}
}
echo "Done";
?>