class_DataTransformator.inc.php
9.79 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/**
* @file DataTransformator.inc.php
* @category freeSN
* @mailto code [at] netz.coop
* @version 0.4.200901
* @link http://netz.coop
*
* @copyright Copyright by netz.coop e.G. 2015
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* class DataTransformator
*
* Klasse die die Umwandlung der Datenbanktabellen in Objekte voll zieht
* @version 0.2.0803
* @author dev [at] mensch [dot] coop
*/
class DataTransformator {
/****************************************************************************************
* *
* Schnittstellenfunktionen zwischen diese Klasse und der DB Klasse (bzw Datenbank) *
* *
****************************************************************************************/
/**
* Schnittstellenfunktion zwischen Klasse Profile und der Datenbank
* - wandelt die Profil Daten aus der Tabelle in eine ProfileBCe um
* - könnte evt. auch in die Datenbank Klasse oder in BasisElement
*
*
* @return Object List
*/
public static function &transformDBTableToObjectList(Account &$param_HostAccount, iStorable &$param_iStorable, $tablerow, $KindOf=null, $PartOf=null, array &$out_ObjecCloakArray = null){
if(!is_array($out_ObjecCloakArray)) {
$out_ObjecCloakArray = array();
}
$List = array();
for($i=0; $i<count($tablerow); $i++) {
if(is_array($tablerow[$i])) {
$out_ObjecCloakArray[$i] =& self::transformDBTableRowToObject($param_HostAccount, $param_iStorable,$tablerow[$i]);
$List[$i] = & $out_ObjecCloakArray[$i]->getObject();
} else {
D::backtrace('Array existierte nicht');
return false;
}
}
return $List;
}
private static function &transformDBTableRowToMTextObject(Account &$param_HostAccount, iStorable &$param_iStorable, array $tablerow, BasisElement &$Object=null) {
if(is_subclass_of($Object, "BasisElement")) {
$tablerow["Author_NickName"] = Profile::IDToNickName($param_iStorable, $tablerow["Author_ProfileID"]);
$tablerow["Author_Avatar"] = Profile::IDToAvatar($param_iStorable, $tablerow["Author_ProfileID"]);
$tablerow["Author_Signature"] = Profile::IDToSignature($param_iStorable, $tablerow["Author_ProfileID"]);
$tablerow["AuthorProfile"]=null;
$tablerow["ReadPrivate"] = $tablerow["AuthReadListID"];
$tablerow["WritePrivate"] = $tablerow["AuthWriteListID"];
//if($tablerow['ID']=='2355') {
// D::show($tablerow['@write'], '------- '.__FUNCTION__.$param_BEID,1,1);
//}
if(is_array($tablerow['@write']) && !empty($tablerow['@write'])) {
$Object->getObjVar('RightManagement')->setWriteRightProfiles($tablerow['@write']);
// $tablerow['WriteRight'] = false;
// foreach($tablerow['@write'] as $var_PID => $var_PID_states) {
// if(array_key_exists('WriteRight', $var_PID_states)) {
// $tablerow['WriteRight'] = $var_PID_states['WriteRight'];
// break;
// } else if($var_PID == 'profilecollection') {
// foreach($var_PID_states as $var_PCID => $var_PCID_states) {
// if(array_key_exists('WriteRight', $var_PCID_states)) {
// $tablerow['WriteRight'] = $var_PCID_states['WriteRight'];
// break;
// }
// }
// }
// }
$tablerow['WriteRight'] = $Object->getObjVar('RightManagement')->isWriteAble($param_HostAccount);
// D::li(,1,1);
}
if(is_array($tablerow['@read']) && !empty($tablerow['@read'])) {
$Object->getObjVar('RightManagement')->setReadRightProfiles($tablerow['@read']);
$tablerow['ReadRight'] = true;
}
$Object->setRequestProfileID($param_HostAccount->getActiveProfileID());
$Object->setData($param_HostAccount, $param_iStorable, $tablerow);
$Object->getObjVar('RightManagement')->setAuthorisationList(AuthorisationList::load($param_HostAccount, $param_iStorable, $tablerow["AuthReadListID"], $tablerow["AuthWriteListID"]));
$Object->getObjVar('RightManagement')->loadObject($param_HostAccount, $param_iStorable);
} else if($tablerow['losp_object']) {
$Object = &$tablerow['losp_object'];
} else D::h1("FEHLER warum passiert das");
if(array_key_exists('PartOfID', $tablerow) && $tablerow['PartOfID']) {
$var_PartOfArray = array('PartOfID'=>$tablerow['PartOfID']);
if(array_key_exists('PartOfObjVar', $tablerow)) {
$var_PartOfArray['PartOfObjVar'] = $tablerow['PartOfObjVar'];
$var_PartOfArray['AttachID'] = $tablerow['AttachID'];
}
if(array_key_exists('CDate', $tablerow)) {
$var_PartOfArray['CDate'] = $tablerow['CDate'];
}
if(array_key_exists('PartOfObjVarID', $tablerow)) {
$var_PartOfArray['PartOfObjVarID'] = $tablerow['PartOfObjVarID'];
} else {
$var_PartOfArray['PartOfObjVarID'] = BasisClipboard::PartObjVarToID($param_iStorable,$var_PartOfArray['PartOfObjVar']);
}
$var_PartOfArray['AttachStateID'] = $tablerow['AttachStateID'];
$var_PartOfArray['LinkerProfileID'] = $tablerow['LinkerProfileID'];
if(array_key_exists('CategoryID', $tablerow)) {
$var_PartOfArray['CategoryID'] = $tablerow['CategoryID'];
$var_PartOfArray['CategoryName'] = $tablerow['CategoryName'];
}
$Object->addToPartOfDataArray($tablerow['PartOfID'], $var_PartOfArray);
$var_CloakObject = &CloakObject::createCloakObject($Object);
$var_CloakObject->setObjVar('PartOfID', $tablerow['PartOfID']);
} else {
$var_CloakObject = &CloakObject::createCloakObject($Object);
}
return $var_CloakObject;
}
/**
* @todo wozu gibt es den $Object Parameter !!!! ? 100318 @f
*
* Schnittstellenfunktion zwischen Klasse Profile und Klasse DB (bzw der Datenbank)
* - wandelt die Profil Daten aus der TabelleZeile in ein Profil um
* - könnte evt. auch in die Datenbank Klasse
*
* @return an CloakObject Object (inside is the real Object)
*/
public static function &transformDBTableRowToObject(Account &$param_HostAccount, iStorable &$param_iStorable, array $tablerow, &$Object=null){
$var_Data = array();
if(is_array($tablerow)) {
if( array_key_exists('losp_object', $tablerow) && is_object($tablerow['losp_object'])) {
if(is_subclass_of($tablerow['losp_object'], 'BasisElement')) {
$var_CloakObject = &self::transformDBTableRowToMTextObject($param_HostAccount, $param_iStorable, $tablerow);
return $var_CloakObject;
} else {
D::li('Fehler');
return false;
}
} else {
if(!$Object) {
if((!array_key_exists('losp_classname', $tablerow) || !$tablerow['losp_classname'] ) && array_key_exists('ClassID', $tablerow)) {
$tablerow['losp_classname'] = $param_iStorable->getClassName($tablerow['ClassID']);
}
if(array_key_exists('losp_classname', $tablerow)) {
if(is_subclass_of($tablerow['losp_classname'],"BasisElement")){
if(array_key_exists('PartOfID', $tablerow)) {
$var_PartOf =& MultimediaText::loadElement($param_HostAccount, $param_iStorable, $param_MultimediaTextClassName='*', $tablerow['PartOfID']);
} else {
$var_PartOf = null;
}
$Object = BasisElement::createNewInstance($param_iStorable, $tablerow['losp_classname'], $tablerow['ID'], $var_PartOf);
} else if(is_subclass_of($tablerow['losp_classname'],"Authorisation")) {
$Object = new $tablerow['losp_classname']($param_iStorable, 0, 0, 0, 0);
} else if($tablerow['losp_classname']=='') {
D::h1('darf nie mals nie vorkommen');
return false;
}
} else {
D::h1('darf nie mals nie vorkommen: losp_classname muss vorkommen (sql:select Befehl ist falsch)');
return false;
}
}
/*** Account */
if($Object->ThisClassName=='Account') {
$Object->setData($param_HostAccount, $param_iStorable, $tablerow);
$var_CloakObject = &CloakObject::createCloakObject($Object);
return $var_CloakObject;
/*** Clipboard */
} else if(is_subclass_of($Object, 'BasisClipboard')) {
$CloakObjectArray = array();
self::transformDBTableToObjectList($param_HostAccount, $param_iStorable, $tablerow, CONFIG::getBC_MultimediaText(get_class($Object).'::'.$Object->getObjVar('CategoryName')), $Object, $CloakObjectArray);
foreach($CloakObjectArray as $CloakObject) {
$Object->addToAttachIDList($CloakObject->getObject()->getObjVar("ID"), $CloakObject->getObjVar('PartOfID'), $CloakObject->getObject()->getPartOfDataArray($CloakObject->getObjVar('PartOfID')));
}
$var_CloakObject = &CloakObject::createCloakObject($Object);
return $var_CloakObject;
/*** ReadAuthorisation / WriteAuthorisation*/
} else if($Object->ThisClassName=="ReadAuthorisation" || $Object->ThisClassName=="WriteAuthorisation") {
$Object->setListID($tablerow["ListID"]);
$Object->setProfileID($tablerow["ProfileID"]);
$Object->setProfileNickName($tablerow["NickName"]);
$var_CloakObject = &CloakObject::createCloakObject($Object);
return $var_CloakObject;
} else if(is_subclass_of($Object, 'BasisElement')) {
$var_CloakObject = &self::transformDBTableRowToMTextObject($param_HostAccount, $param_iStorable, $tablerow, $Object);
MultimediaText::addMTextToArray($Object);
if(is_subclass_of($Object, 'BasisElement') ) {
BasisElement::loadObjectLevel($param_HostAccount, $param_iStorable, $Object, 'Always' );
}
return $var_CloakObject;
} else {
D::h1('nichts passiert, für diesen fall ist noch nichts implementiert');
return false;
}
}
}
return FALSE;
}
}
?>