class_AddonManager.inc.php
4.53 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
<?php
/**
* @file AddonManager.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 AddonManager {
private $AddonArray = array();
private $Object;
private $DB;
public function __construct(iStorable $param_Database, &$param_Object=null) {
$this->DB = $param_Database;
if(is_object($param_Object)) {
$this->Object = &$param_Object;
}
}
public function delete(){
if(is_array($this->AddonArray)) {
foreach($this->AddonArray as &$var_ClassObj) {
if(is_object($var_ClassObj)) {
$var_ClassObj->delete();
}
}
}
}
public function &getAddon(Account &$param_HostAccount, iStorable &$param_iStorable, $param_Addon, $param_Parameter=null) {
if(is_subclass_of($param_Addon, 'aBasisElementAddon')) {
$this->loadAddon($param_HostAccount, $param_iStorable, $param_Addon, $param_Parameter);
return $this->AddonArray[$param_Addon];
} else {
return false;
}
}
public function setAddon(aBasisElementAddon &$param_Addon) {
$this->AddonArray[get_class($param_Addon)] = &$param_Addon;
}
public function &getObjVar($param_ObjVar) {
$ObjVar = trim($param_ObjVar);
return $this->$ObjVar;
}
public function loadAddon(Account &$param_HostAccount, iStorable &$param_iStorable, $param_ClassName, $param_Parameter) {
if((!array_key_exists($param_ClassName, $this->AddonArray) || !is_object($this->AddonArray[$param_ClassName])) && is_subclass_of($param_ClassName, 'aBasisElementAddon')) {
$this->AddonArray[$param_ClassName] = new $param_ClassName($param_iStorable, $this->Object);
} else if(!is_object($this->AddonArray[$param_ClassName])) {
return Error::newError('DevError','NotImplementaded','Addon '.$param_ClassName.' für '. $this->Object.' existiert nicht!');
}
$this->AddonArray[$param_ClassName]->loadObject($param_HostAccount, $param_iStorable, $param_Parameter);
/**
* @if
*
* 'aBasisElementAddon' => array (
* 'Logger' => array(
* 'function' => array(
* 'addOneToVisited' => array('LoadLevel' => true),
* )
* )
* ),
*/
if(is_array($param_Parameter) and !empty($param_Parameter)) {
foreach($param_Parameter as $var_BEAKey => $var_BEAParameter) {
if($var_BEAKey == 'function' and is_array($var_BEAParameter) and !empty($var_BEAParameter)) {
foreach($var_BEAParameter as $var_fncName => $var_fncParameter) {
if(is_array($var_fncParameter) && array_key_exists('LoadLevel',$var_fncParameter) && $var_fncParameter['LoadLevel']=='Edit'){
$var_fncParameter['AuthorProfileID']=$param_HostAccount->getAuthorProfileID();
}
$this->AddonArray[$param_ClassName]->$var_fncName($var_fncParameter);
}
}
}
}
}
public function saveAddonObjects(Account &$param_HostAccount, iStorable &$param_iStorable) {
foreach($this->AddonArray as &$var_ClassObj) {
if(is_object($var_ClassObj)) {
$var_ClassObj->saveObject($param_HostAccount, $param_iStorable);
}
}
}
public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, &$param_Data) {
if(is_array($this->AddonArray)) {
foreach($this->AddonArray as &$var_ClassObj) {
if(is_object($var_ClassObj)) {
$var_ClassObj->setData($param_HostAccount, $param_iStorable, $param_Data);
}
}
}
}
public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf) {
/**
* @foreach get the aBasisElementAddon DOMElements
*/
if(!empty($this->AddonArray)) {
$var_BEADOMElement = $param_DOMDocument->createElement('BasisElementAddons');
foreach($this->AddonArray as &$var_ClassObj) {
if(is_object($var_ClassObj)) {
$var_BEADOMElement->appendChild($var_ClassObj->getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf));
}
}
return $var_BEADOMElement;
}
}
}
?>