1 |
<? |
2 |
|
3 |
// ======================================================= |
4 |
// things done here: |
5 |
// - creating and loading new models |
6 |
// - retrieve metadata about ds-objects and their keys, ds-events, db-tables, db-columns etc. from proper "PDLModelObject" |
7 |
// - retrieve data-operations (raw "unready"-sql) |
8 |
|
9 |
class PDLEngine { |
10 |
|
11 |
// path to the pdl-files |
12 |
var $path_pdl; |
13 |
|
14 |
// a hash with references to PDLModel-objects |
15 |
var $models; |
16 |
|
17 |
var $object_model_map; |
18 |
|
19 |
|
20 |
// ---------------------------------------------------- |
21 |
// constructor |
22 |
function PDLEngine($args) { |
23 |
|
24 |
// debugging |
25 |
//slog("PDL: new PDL (" . join($args, ';') . ")"); |
26 |
|
27 |
// clear models |
28 |
$this->models = array(); |
29 |
$this->object_model_map = array(); |
30 |
|
31 |
// set pdl-path |
32 |
if ( isset($args['path_pdl']) ) { $this->path_pdl = $args['path_pdl']; } |
33 |
|
34 |
// load models |
35 |
if (isset($args['models']) && count($args['models'])) { |
36 |
while($modelname = current($args['models'])) { |
37 |
$this->_loadModel($modelname); |
38 |
next($args['models']); |
39 |
} |
40 |
$this->_object_model_map_create(); |
41 |
} |
42 |
|
43 |
} |
44 |
|
45 |
function _object_model_map_create() { |
46 |
reset($this->models); |
47 |
while($model =& current($this->models)) { |
48 |
reset($model->pdlModelObjects); |
49 |
while($pdlmodelobject =& current($model->pdlModelObjects)) { |
50 |
$this->object_model_map[$pdlmodelobject->type] = $model->name; |
51 |
next($model->pdlModelObjects); |
52 |
} |
53 |
next($this->models); |
54 |
} |
55 |
} |
56 |
|
57 |
|
58 |
// ---------------------------------------------------- |
59 |
// returns a reference to a "PDLModelObject"-object |
60 |
// function &getPDLModelObject($objecttype, $modelname = 'main') { |
61 |
function &getPDLObject($objecttype_ShortOrFull) { |
62 |
|
63 |
if (stristr($objecttype_ShortOrFull, '.')) { |
64 |
list($modelname, $objecttype) = split('\.', $objecttype_ShortOrFull); |
65 |
} else { |
66 |
$objecttype = $objecttype_ShortOrFull; |
67 |
$modelname = $this->object_model_map[$objecttype]; |
68 |
} |
69 |
|
70 |
// load model if needed |
71 |
//$this->_loadModelByObjectType($objecttype, $modelname); |
72 |
if ( !isset($this->models[$modelname]) ) { |
73 |
$this->_loadModel($modelname); |
74 |
} |
75 |
|
76 |
// return object-reference if it exists |
77 |
if ($this->models[$modelname]->existsObject($objecttype)) { |
78 |
return $this->models[$modelname]->getObject($objecttype); |
79 |
} else { |
80 |
print("<font color=\"red\">PDLEngine->getPDLObject() failed, object \"$objecttype_ShortOrFull\" was not found in model, please check pdl-file.</font><br>"); |
81 |
} |
82 |
|
83 |
} |
84 |
|
85 |
|
86 |
// ---------------------------------------------------- |
87 |
// returns a reference to a "PDLModelObject"-object |
88 |
// function &getPDLModelObject($objecttype, $modelname = 'main') { |
89 |
function &getPDLDataOperation($dataOperation_Full) { |
90 |
|
91 |
list($modelname, $operationname) = split('\.', $dataOperation_Full); |
92 |
|
93 |
// load model if needed |
94 |
//$this->_loadModelByObjectType($objecttype, $modelname); |
95 |
if ( !isset($this->models[$modelname]) ) { |
96 |
$this->_loadModel($modelname); |
97 |
} |
98 |
|
99 |
// return object-reference |
100 |
return $this->models[$modelname]->getDataOperation($operationname); |
101 |
|
102 |
} |
103 |
|
104 |
|
105 |
// ---------------------------------------------------- |
106 |
// loads a model by creating a new "PDLModel"-object and passing the absolute path to the pdl-file to the constructor |
107 |
function _loadModel($modelname) { |
108 |
|
109 |
// debugging |
110 |
slog("PDL: loadModel($modelname)"); |
111 |
|
112 |
// instantiate new "PDLModel"-object and store reference into a new hash-entry of a local classvariable |
113 |
$this->models[$modelname] =& new PDLModel($modelname, $this->path_pdl . $modelname . '.pdl'); |
114 |
|
115 |
} |
116 |
|
117 |
|
118 |
// ---------------------------------------------------- |
119 |
// returns column-metadata by given rdbms-table |
120 |
function rdbms_getColumnMetaData($tablename) { |
121 |
|
122 |
print "rdbms_getColumnMetaData($tablename)<br>"; |
123 |
|
124 |
// HACK(s): |
125 |
//$objecttype_full = 'main.' . ucfirst($tablename); |
126 |
if ($objecttype_full == 'main.Users') { $objecttype_full = 'main.User'; } |
127 |
|
128 |
$meta_attribs = $this->_getAttributeMetaData($objecttype_full); |
129 |
dumpVar('meta_attribs', $meta_attribs, 'html'); |
130 |
|
131 |
} |
132 |
|
133 |
|
134 |
// ---------------------------------------------------- |
135 |
// returns attribute-metadata by given objecttype |
136 |
function _getAttributeMetaData($objecttype_full) { |
137 |
$mo = $this->getPDLObject($objecttype_full); |
138 |
return $mo->getAttributes(); |
139 |
} |
140 |
|
141 |
|
142 |
} |
143 |
|
144 |
?> |