class_TreeManipulator.inc.php
16.4 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?php
/**
* @file TreeManipulator.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 TreeManipulator {
/**
* @var array of the TreeManipulatorCallback objects
*/
private static $TreeManipulatorCallbackArray = array();
/**
* return the TreeManipulatorCallback object
*/
public static function &getTreeManipulatorCallback($param_TMC) {
if(!array_key_exists($param_TMC, self::$TreeManipulatorCallbackArray) || !is_object(self::$TreeManipulatorCallbackArray[$param_TMC])) {
if(is_subclass_of($param_TMC, 'iTreeManipulatorCallback')) {
self::$TreeManipulatorCallbackArray[$param_TMC] = new $param_TMC();
} else {
D::li('Fehler is_subclass_of('.$param_TMC.', iTreeManipulatorCallback)=('.is_subclass_of($param_TMC, 'iTreeManipulatorCallback').'): TreeManipulator::&getTreeManipulatorCallback('.$param_TMC.')');
return false;
}
}
return self::$TreeManipulatorCallbackArray[$param_TMC];
}
/**
* gibt das letzte (höchste) BasisClipboard/BasisElement Element welches im Array existiert zurück
*/
public static function getLastBasisClipboardFromUrlArray(array $param_UrlArray, $param_GetBasisClipboardCategory=false) {
$var_max = count($param_UrlArray)-2;
for($i=$var_max; $i>=0; $i--) {
$var_UrlTmp = CONFIG::transformStringToArray($param_UrlArray[$i],'category');
if (class_exists( $tmp=array_shift($var_UrlTmp))
//&& (is_subclass_of($param_UrlArray[$i], 'BasisClipboard') || is_subclass_of($param_UrlArray[$i], 'BasisElement'))
) {
if(!$param_GetBasisClipboardCategory) {
return $tmp;
} else {
return $param_UrlArray[$i];
}
}
}
return false;
}
public static function getLastShowSingleIDFromUrlArray(array $param_UrlArray) {
$var_max = count($param_UrlArray)-2;
for($i=$var_max; $i>=0; $i--) {
$var_UrlTmp = CONFIG::transformStringToArray($param_UrlArray[$i],'category');
if (class_exists( $tmp=array_shift($var_UrlTmp))
//&& (is_subclass_of($param_UrlArray[$i], 'BasisClipboard') || is_subclass_of($param_UrlArray[$i], 'BasisElement'))
) {
if($param_UrlArray[$i+1]=='showSingle') {
if($param_UrlArray[$i+2]=='ID') {
if($param_UrlArray[$i+3]) {
return $param_UrlArray[$i+3];
}
}
return false;
} else {
for($j=$i;$j<$var_max;$j++) {
unset($param_UrlArray[$j]);
}
return TreeManipulator::getLastShowSingleIDFromUrlArray($param_UrlArray);
}
return $param_UrlArray[$i];
}
}
return false;
}
public static function getLastHistoryActionFromUrlArray(array $param_UrlArray) {
$var_max = count($param_UrlArray)-1;
$var_HistoryConfig = CONFIG::getHistory();
//D::show($var_HistoryConfig);
//D::show($param_UrlArray, '$param_UrlArray');
for($i=$var_max; $i>=0; $i--) {
if ( class_exists($param_UrlArray[$i])
&& (is_subclass_of($param_UrlArray[$i], BasisClipboard) || is_subclass_of($param_UrlArray[$i], BasisElement))
&& $i!=$var_max
) {
return FALSE;
}
if(array_search($param_UrlArray[$i], $var_HistoryConfig['PossibleAction'])!==false) {
return $param_UrlArray[$i];
}
}
return false;
}
/**
* transformiert ein Url Array in ein Url String um
*
* vorischtig klappt nicht mit c
*/
public static function transformArrayToUrl(array $param_UrlArray, BasisElement $param_PartOf=null, $param_BasisClipboardname=null) {
// D::backtrace();
// D::show($param_UrlArray, '$param_UrlArray');
if(is_object($param_PartOf)) {
if($param_PartOf->getObjVar('PartOfID')) {
$PartOf_PartOfID = $param_PartOf->getObjVar('PartOfID');
} else if(is_object($param_PartOf->getObjVar('PartOf'))) {
$PartOf_PartOfID = $param_PartOf->getObjVar('PartOf')->getObjVar('ID');
}
/*if($PartOf_PartOfID) {
}*/
}
$var_Url = '?';
$url_index=0;
$count_UrlArray = count($param_UrlArray);
// if($param_UrlArray[0]!='start'){
// D::backtrace();
// D::show($param_UrlArray);
// }
for($i=1; $i<$count_UrlArray; $i++) {
$var_Url .= 'p['.$url_index++.']='.$param_UrlArray[$i];
if($i!=$count_UrlArray-1) {
$var_Url .= '&';
}
}
if($var_Url==='?' && $param_PartOf!==null && $param_BasisClipboardname!==null) {
$var_Url .= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOf->getObjVar('ID').'&p[3]='.$param_BasisClipboardname;
//D::ulli('if '.$var_Url.' || '.$param_PartOf.'->'.$param_BasisClipboardname);
} else {
//D::ulli('else '.$var_Url.' || '.$param_PartOf.'->'.$param_BasisClipboardname);
}
// if($PartOf_PartOfID) {
// D::show($param_UrlArray, '$param_UrlArray');
// D::ulli($PartOf_PartOfID.' -> '.$param_PartOf.'->'.$param_BasisClipboardname.' || <b>'.$var_Url.'</b> || ');
// }
//D::ulli($var_Url);
return $var_Url;
}
// @old @until 090806
// public static function transformArrayToUrl(array $param_UrlArray, BasisElement $param_PartOf=null, $param_BasisClipboardname=null) {
// $var_Url = '?';
// $url_index=0;
// $count_UrlArray = count($param_UrlArray);
// for($i=1; $i<$count_UrlArray; $i++) {
// $var_Url .= 'p['.$url_index++.']='.$param_UrlArray[$i];
// if($i!=$count_UrlArray-1) {
// $var_Url .= '&';
// }
// }
//
// if($var_Url==='?' && $param_PartOf!==null && $param_BasisClipboardname!==null) {
// $var_Url .= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOf->getObjVar('ID').'&p[3]='.$param_BasisClipboardname;
//
// }
// return $var_Url;
// }
private static function callback_ShowSingle( $param_Account, MultimediaText $param_Object, $param_CurrentObjectName, $param_BasisClipboardname, $param_url, &$param_return) {
D::li(" $param_Object -- $param_CurrentObjectName -- $param_BasisClipboardname");
D::ulli(self::transformArrayToUrl($param_url));
}
public static $count_runTreeCallback_getBasisClipboard = 0;
/**
* callback function for the TreeManipulator::@see runTree function
*
* Funktion sammelt Daten
*/
private static function runTreeCallback_getBasisClipboard( $param_Account, MultimediaText $param_Object, $param_CurrentObjectName, $param_BasisClipboardname, $param_url, &$param_return) {
TreeManipulator::$count_runTreeCallback_getBasisClipboard++;
if(!array_key_exists('result', $param_return) || !is_array($param_return['result'])) {
$param_return['result'] = array();
}
if($param_return['BasisClipboard'] == $param_BasisClipboardname) {
$param_return['result'][] = array(
'url' => $param_url,
'CurrentObjectName' => $param_CurrentObjectName,
'BasisClipboardname' => $param_BasisClipboardname,
'HostID' => $param_Object->getObjVar('ID'),
'HostSubject' => $param_Object->getObjVar('Subject'),
'HostClassname' => $param_Object->getObjVar('ThisClassName'),
'HostObject' => $param_Object,
);
}
}
public static $count_runTree=0;
/**
* durchläuft den Vererbungsbaum und die angehängten Clipboards
* führt die Callback Funktion bei jedem vererbten Klassennamen "Zustand" und jedem darangehängten BasisClipboard aus
*
* @param string param_BasisClipboardname
* @param Account param_Account (only callback parameter)
* @param BasisElement param_PartOf=null (callback parameter)
* @param int param_GET_index=0 SINNLOS
* @param Array param_url=null (callback parameter)
* @param string param_callback='fncShowSingle' callback function (definiert in der TreeManipulator Klasse oder im param_Object_test Objekt)
* @param Array & param_return Array welches in der Callback Funktion manipuliert werden kann (only callback parameter)
* @param TestOfController param_Object_test =null (callback parameter)
*
*/
public static function runTree($param_BasisClipboardname, $param_Account, $param_PartOf=null ,$param_GET_index= 0,$param_url=null,$param_callback='fncShowSingle', &$param_return, $param_Object_test =null){
TreeManipulator::$count_runTree++;
/** Make Arrays if not existant && get Data from the CONFIG class */
{
if($param_BasisClipboardname == 'start'){
$param_url = array($param_BasisClipboardname);
} else {
$param_url[] = $param_BasisClipboardname;
}
if(!$FncVar_LastBasisClipboard = TreeManipulator::getLastBasisClipboardFromUrlArray($param_url)) {
$FncVar_LastBasisClipboard = get_class($param_PartOf);
}
if($param_BasisClipboardname){
$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($param_BasisClipboardname, 'category');
$var_BasisClipboardnameArray = CONFIG::transformStringToArray($param_BasisClipboardname, 'category');
// $param_FunctionName = CONFIG::getLinkForBC($param_BasisClipboardname);
}
$FncVar_LastBasisClipboard_MtextClass = CONFIG::getBC_MultimediaText($FncVar_LastBasisClipboard);
$FncVar_BasisClipboardLink = CONFIG::getLinkForBC($param_BasisClipboardname);
}
/** Get Parent Multimediatext Classes and Clipboards */
{
if($param_BasisClipboardname == 'start' && $param_PartOf != null ){
$class_parents = class_parents($param_PartOf);
$class_parents[get_class($param_PartOf)] =get_class($param_PartOf);
unset($class_parents['BasisElement']);
unset($class_parents['MultimediaText']);
unset($class_parents['0']);
/**
* fill the $class_parents array with BasisClipboards
*/
foreach ($class_parents as $MTextname) {
$var_index =count($param_url);
$param_url[$var_index] = $MTextname;
// D::li(''.$MTextname);
if(!$param_Object_test){
self::$param_callback( $param_Account, $param_PartOf, $MTextname, '', $param_url, $param_return,$param_Object_test);
}else{
$param_Object_test->$param_callback( $param_Account, $param_PartOf, $MTextname, $tmp_Clipboard=null, $param_url, $param_return,$param_Object_test);
}
if($MTextname) {
$class_parents[$MTextname]= CONFIG::getMultimediaTextPreferencs($MTextname, 'BasisClipboards');
}
if(is_array($class_parents[$MTextname]) ){
foreach ($class_parents[$MTextname] as $Clipboard => $ClipboardInfo) {
$var_index_1 =count($param_url);
$param_url[$var_index_1] = $Clipboard;
// D::ulli($MTextname.' >=> '.$Clipboard);
if(!$param_Object_test){
self::$param_callback( $param_Account, $param_PartOf, $MTextname, $Clipboard, $param_url, $param_return,$param_Object_test);
} else {
$param_Object_test->$param_callback( $param_Account, $param_PartOf, $MTextname, $Clipboard, $param_url, $param_return,$param_Object_test);
}
unset($param_url[$var_index_1] );
}
}
unset($param_url[$var_index] );
}
}
}
}
public static $count_runDBTree=0;
/**
* durchlaufe den Objekt Datenbank Baum (mit seinen verknüpften Objekten)
*
* begin with the object param_RootArray(ID=>int) and run until param_Depth
*
* @param iBasicSql param_DB (callback parameter)
* @param int param_RequestProfileID (callback parameter)
* @param array param_RootArray array( 'ID' => int) (callback parameter)
* @param string param_BasisClipboardname=null beschränke den Objekt Datenbaum (DB->getFromClipboard parameter)
* @param array param_callback callback funktion's array('callback_fnc_name' => true)
* @param ¶m_return Array welches in der Callback Funktion manipuliert werden kann (callback parameter) Ergebnis in $param_return[callback*][result]
* @param int param_Depth=0 run tree until depth
* @param param_KindOfObj=null (DB->getFromClipboard parameter)
* @param param_State=null (DB->getFromClipboard parameter)
* @param array param_ConditionArray=null (DB->getFromClipboard parameter)
* @param boolean param_checkWrite=null (DB->getFromClipboard parameter)
*/
// public static function runDBTree(iBasicSql $param_DB, $param_RequestProfileID, array $param_RootArray, $param_BasisClipboardname=null, array $param_callback, array &$param_return, $param_Depth=0, $param_KindOfObj=null, $param_State=null, array $param_ConditionArray=null, $param_checkWrite=null, array &$param_FinishIDArray=null) {
public static function runDBTree(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_RootArray, $param_BasisClipboardname=null, array $param_callback, array &$param_return, $param_Depth=0, $param_KindOfObj=null, $param_State=null, array $param_ConditionArray=null, $param_checkWrite=null, array &$param_FinishIDArray=null) {
// D::li("TreeManipulator::runDBTree(iBasicSql $param_iStorable, $param_RequestProfileID, array param_RootArray[ID]=<b>".$param_RootArray['ID']."</b>, BC=$param_BasisClipboardname, callback=$param_callback, return=$param_return, $param_Depth=0, KindOfObj=$param_KindOfObj, State=$param_State, ConArray=$param_ConditionArray, checkWrite=$param_checkWrite=null, $param_FinishIDArray)",1,1);
TreeManipulator::$count_runDBTree++;
// @new
if(true) {
if(array_key_exists('ID', $param_RootArray) && $param_RootArray['ID'] && $param_callback) {
if(!is_array($param_FinishIDArray)) {
$param_FinishIDArray=array();
}
foreach($param_callback as $var_TreeManipulatorClass => $var_function) {
$var_TreeManipulatorObj = TreeManipulator::getTreeManipulatorCallback($var_TreeManipulatorClass);
if($var_TreeManipulatorObj) {
if(!array_key_exists($var_TreeManipulatorClass, $param_return)) {
$param_return[$var_TreeManipulatorClass] = array();
}
/**
* CallbackFunction wird auf gerufen ... definiert in der CONFIG::$MultimediaTextPreferencs[BasisElementName]['Config']['CallbackFunction']
* Funktion muss abgeleitet sein von: aTreeManipulatorCallback::callbackFunction(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_RootArray, &$param_return)
*/
$var_TreeManipulatorObj->$var_function( $param_HostAccount, $param_iStorable, $param_RootArray, $param_return[$var_TreeManipulatorClass]);
// D::show($param_return, '$param_return');
}
}
if($param_Depth>0) {
$var_ClipboardIDArray = $param_iStorable->getFromClipboard($param_HostAccount, $param_RootArray['ID'], $param_BasisClipboardname, $param_KindOfObj, $param_State, $param_ConditionArray, $param_checkWrite);
foreach($var_ClipboardIDArray as $var_ChildArray) {
if(!array_key_exists($var_ChildArray['ID'], $param_FinishIDArray) || !$param_FinishIDArray[$var_ChildArray['ID']]) {
$param_FinishIDArray[$var_ChildArray['ID']] = true;
self::runDBTree($param_HostAccount, $param_iStorable, $var_ChildArray, $param_BasisClipboardname, $param_callback, $param_return, $param_Depth-1, $param_KindOfObj, $param_State, $param_ConditionArray, $param_checkWrite, $param_FinishIDArray);
}
}
}
} else {
return false;
}
}
// @old @until 090507
if(false){
if ($param_callback) {
foreach($param_callback as $var_TreeManipulatorClass => $var_function) {
$var_TreeManipulatorObj = TreeManipulator::getTreeManipulatorCallback($var_TreeManipulatorClass);
if($var_TreeManipulatorObj) {
if(!array_key_exists($var_TreeManipulatorClass, $param_return)) {
$param_return[$var_TreeManipulatorClass] = array();
}
$var_TreeManipulatorObj->$var_function($param_HostAccount, $param_iStorable, $param_RootArray, $param_return[$var_TreeManipulatorClass]);
// D::show($param_return, '$param_return');
}
}
if($param_Depth>0) {
$var_ClipboardIDArray = $param_iStorable->getFromClipboard($param_HostAccount, $param_RootArray['ID'], $param_BasisClipboardname, $param_KindOfObj, $param_State, $param_ConditionArray, $param_checkWrite);
foreach($var_ClipboardIDArray as $var_ChildArray) {
self::runDBTree($param_HostAccount, $param_iStorable, $var_ChildArray, $param_BasisClipboardname, $param_callback, $param_return, $param_Depth-1, $param_KindOfObj, $param_State, $param_ConditionArray, $param_checkWrite);
}
}
} else {
return false;
}
}
}
}
?>