class_Category.inc.php
12.6 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
<?php
/**
* @file class_Category.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 Category extends aBasisElementAddon {
protected $MText = null;
protected $BasisClipboard = null;
protected $CategoryChoiceArray;
/**
*
* @var array the Categorys which are link with the self::$MText / self::$BasisClipboard Object
*/
protected $CategoryArray =null;
public function __construct(iStorable &$param_DB, &$param_Obj) {
if(is_subclass_of($param_Obj, 'BasisElement')) {
$this->MText =& $param_Obj;
} else if(is_subclass_of($param_Obj, 'BasisClipboard')) {
$this->BasisClipboard =& $param_Obj;
}
$this->DB =& $param_DB;
$this->depth = CONFIG::getConfig('CategoryDepth');
$this->ThisClassName = get_class($this);
}
public function delete(){
$var_BEADB = &$this->DB->getBasisElementAddonDataBase($this->ThisClassName);
if($var_BEADB) {
$var_BEADB->deleteCategorysForBE($this->DB, $this->MText->getObjVar('BECategoryListID'));
}
}
private static $DefaultCategoryArray = null ;
private static function &getDefaultCategoryArray(Account &$param_HostAccount, iStorable &$param_iStorable) {
if(!Category::$DefaultCategoryArray) {
$var_CategoryBEADB = & $param_iStorable->getBasisElementAddonDataBase('Category');
/**
* @todo Achtung dadurch das RequestProfileID=null ist, wird einmal CategoryBEADB::getCategoryChoice zuviel aufgerufen, da es ansonsten gecachet werden würde ;) ...
*/
Category::$DefaultCategoryArray = $var_CategoryBEADB->getCategoryChoice($param_HostAccount, $param_iStorable);
}
return Category::$DefaultCategoryArray;
}
private static $DefaultCategoryDOMElement = null;
private static function getDefaultCategoryDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_Selected=null) {
if(!Category::$DefaultCategoryDOMElement) {
$var_DefaultCategoryArray = &Category::getDefaultCategoryArray($param_HostAccount, $param_iStorable);
Category::$DefaultCategoryDOMElement = $param_DOMDocument->createElement('DefaultCategoryList');
Category::setCategoryChoiceArrayDOMElement($param_DOMDocument, Category::$DefaultCategoryDOMElement, $var_DefaultCategoryArray, $param_Selected);
}
return Category::$DefaultCategoryDOMElement;
}
public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_Data) {
if(array_key_exists($this->ThisClassName, $param_Data)) {
$this->CategoryArray = array();
if(array_key_exists('form_newCategory', $param_Data[$this->ThisClassName]) && !empty($param_Data[$this->ThisClassName]['form_newCategory'])) {
$Cats = Form::varcharToArray($param_Data[$this->ThisClassName]['form_newCategory']);
$var_BEADB = $param_iStorable->getBasisElementAddonDataBase('Category');
$var_result = $var_BEADB->insertCategory($param_iStorable, $Cats);
foreach($var_result as $var_key => $var_value) {
if(array_key_exists('form_CategoryArray', $param_Data[$this->ThisClassName])) {
$param_Data[$this->ThisClassName]['form_CategoryArray'][] = $var_key;
}
$this->CategoryArray[$var_key] = array('BECategoryName' => $var_value, 'BECategoryID' => $var_key);
}
}
if(!array_key_exists('form_CategoryArray', $param_Data[$this->ThisClassName]) || !is_array($param_Data[$this->ThisClassName]['form_CategoryArray'])) {
$param_Data[$this->ThisClassName]['form_CategoryArray'] = array();
}
//D::show($this->CategoryArray, '2');
$var_CategoryArray = $this->CategoryArray;
$this->CategoryArray = array();
if(is_array($param_Data[$this->ThisClassName]['form_CategoryArray'])) {
foreach( $param_Data[$this->ThisClassName]['form_CategoryArray'] as $CatKey) {
if(array_key_exists($CatKey, $var_CategoryArray)) {
$this->CategoryArray[$CatKey] = $var_CategoryArray[$CatKey];
//@um vorläufige automatische setzung der hauptkategotien, muss noch generalisert werden
if($CatKey<400 && $CatKey>99){
$this->CategoryArray[] = floor($CatKey/100);
}
}
else{
$this->CategoryArray[$CatKey] = null;
}
unset($var_CategoryArray[$CatKey]);
}
foreach($var_CategoryArray as $var_key => $var_value) {
$this->CategoryArray[$var_key] = $var_value;
}
}
/*set Default Category*/
if(array_key_exists('Category',TreeConfig::$AddonPreferencs) && array_key_exists('Default',TreeConfig::$AddonPreferencs['Category'])){
foreach(TreeConfig::$AddonPreferencs['Category']['Default'] as $key => $value){
if(!array_key_exists($key,$this->CategoryArray)){
foreach($this->CategoryArray as $Catkey => $Catvalue){
if($Catkey <= $value[1] && $Catkey >= $value[0]){
$this->CategoryArray[$key] = '';
break;
}
}
}
}
}
}
}
private static $Cache_CategoryArray = array();
/**
* importiert SimpleXMLElement,
*allerdings nur "selected" Categorien
*/
public function import( $param_ImportData) {
// D::show($param_ImportData, $this);
if(get_class($param_ImportData)=='SimpleXMLElement') {
foreach($param_ImportData->children() as $var_key => $var_value) {
$var_attr=$var_value->attributes();
if(!array_key_exists((string)$var_attr['BECategoryID'], self::$Cache_CategoryArray)) {
self::$Cache_CategoryArray[(string)$var_attr['BECategoryID']] = array(
'BECategoryName' => (string)$var_attr['BECategoryName'],
'BECategoryID' => (string)$var_attr['BECategoryID'],
'BECategoryGroupID' =>'',
);
}
if((string)$var_attr['selected']){
// D::ulli($this.' ## '.$var_attr['BECategoryName'].' -- BECategoryID: '.$var_attrc['BECategoryID']);
$this->CategoryArray[(string)$var_attr['BECategoryID']] = self::$Cache_CategoryArray[(string)$var_attr['BECategoryID']];
$this->CategoryArray[(string)$var_attr['BECategoryID']]['selected']=(string)$var_attr['selected'];
// $this->CategoryArray[(string)$var_attr['BECategoryID']]=array(
// 'BECategoryName' => (string)$var_attr['BECategoryName'],
// 'BECategoryID' => (string)$var_attr['BECategoryID'],
// 'BECategoryGroupID' =>'',
// 'selected'=>(string)$var_attr['selected']
// );
//D::show($this->CategoryArray[(string)$var_attr['BECategoryID']], $var_key.' ## '.$this);
}
if(array_key_exists('Category',$var_value)){
foreach($var_value->children() as $var_ckey => $var_cvalue) {
$var_attrc=$var_cvalue->attributes();
if(!array_key_exists((string)$var_attrc['BECategoryID'], self::$Cache_CategoryArray)) {
self::$Cache_CategoryArray[(string)$var_attrc['BECategoryID']] = array(
'BECategoryName' => (string)$var_attrc['BECategoryName'],
'BECategoryID' => (string)$var_attrc['BECategoryID'],
'BECategoryGroupID' =>'',
);
}
if((string)$var_attrc['selected']){
// D::ulli($this.' ## '.$var_attrc['BECategoryName'].' -- BECategoryID: '.$var_attrc['BECategoryID']);
$this->CategoryArray[(string)$var_attrc['BECategoryID']] = self::$Cache_CategoryArray[(string)$var_attrc['BECategoryID']];
$this->CategoryArray[(string)$var_attrc['BECategoryID']]['selected']=(string)$var_attrc['selected'];
// $this->CategoryArray[(string)$var_attrc['BECategoryID']]=array(
// 'BECategoryName' => (string)$var_attrc['BECategoryName'],
// 'BECategoryID' => (string)$var_attrc['BECategoryID'],
// 'BECategoryGroupID' =>'',
// 'selected'=>(string)$var_attrc['selected']
//
// );
//D::show($this->CategoryArray[(string)$var_attrc['BECategoryID']], $var_ckey.' ## '.$this);
}
}
}
}
//D::show($this->CategoryArray, "$this ->CategoryArray") ;
return true;
} else {
D::li('IMPORT DATA nur für SimpleXMLElement implementiert');
return false;
}
}
public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {
$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente);
if(is_object($this->MText)) {
$DOMElement->setAttribute('MTextID', $this->MText->getObjVar('ID'));
}
$DOMElement->setAttribute('BasisClipboard', 'CategoryContentList');
if($param_KindOf=='form') {
$var_CategoryArray = array();
$DOMElement->appendChild(BasisElement::getElementDOMElement($param_DOMDocument, $param_label=Language::getWord('newCategory'), $param_objvar=$this->ThisClassName.'][form_newCategory', $param_value=Form::arrayToVarchar($var_CategoryArray), $param_edit=true, $param_type='varchar', $param_length='64', $param_show=true));
$DOMElement->appendChild(Category::getDefaultCategoryDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $this->CategoryArray));
}
{
{
$DOMList = $DOMElement->appendChild($param_DOMDocument->createElement('List'));
if(is_object($this->MText)) {
$DOMList->setAttribute('class', 'BasisElement');
$DOMList->setAttribute('ID', $this->MText->getObjVar('ID'));
$DOMList->setAttribute('BECategoryListID', $this->MText->getObjVar('BECategoryListID'));
} else if(is_object($this->BasisClipboard)){
$DOMList->setAttribute('class', 'BasisClipboard');
$DOMList->setAttribute('PartOfID', $this->BasisClipboard->getObjVar('PartOfID'));
}
$DOMList->setAttribute('label', Language::getWord($this->ThisClassName));
$DOMList->setAttribute('objvar', $this->ThisClassName.'][form_CategoryArray');
}
//D::show($this->CategoryChoiceArray, '$this->CategoryChoiceArray');
$tmp_CategoryArray = $this->CategoryArray;
if(is_array($this->CategoryChoiceArray)) {
if(!$tmp_CategoryArray) {
$tmp_CategoryArray=null;
}
Category::setCategoryChoiceArrayDOMElement($param_DOMDocument, $DOMList, $this->CategoryChoiceArray, $tmp_CategoryArray);
}
if(is_array($tmp_CategoryArray)) {
foreach($tmp_CategoryArray as $var_BECategoryID => $var_BECategoryArray) {
$DOMElement_Child =DOMElementHelper::getDOMElementWithParameter($param_DOMDocument, $param_ElementName='Category', $var_BECategoryArray);
$DOMList->appendChild($DOMElement_Child);
}
}
}
return $DOMElement;
}
private static function setCategoryChoiceArrayDOMElement(DOMDocument $param_DOMDocument, DOMElement &$param_DOMList, array $param_CategoryChoiceArray, &$param_CategorySelectedArray=null) {
foreach($param_CategoryChoiceArray as $var_Key => $var_Value ) {
if(is_array($param_CategorySelectedArray) && array_key_exists($var_Key, $param_CategorySelectedArray)) {
$var_Value['selected'] = 'selected';
unset($param_CategorySelectedArray[$var_Key]);
}
$DOMElement_Child =DOMElementHelper::getDOMElementWithParameter($param_DOMDocument, $param_ElementName='Category', $var_Value);
if(array_key_exists('SubCategory', $var_Value)) {
foreach($var_Value['SubCategory'] as $var_SubKey => $var_SubValue) {
if(is_array($param_CategorySelectedArray) && array_key_exists($var_SubKey, $param_CategorySelectedArray)) {
$var_SubValue['selected'] = 'selected';
unset($param_CategorySelectedArray[$var_SubKey]);
}
$DOMElement_SubChild=DOMElementHelper::getDOMElementWithParameter($param_DOMDocument, $param_ElementName='Category', $var_SubValue);
$DOMElement_Child->appendChild($DOMElement_SubChild);
}
}
$param_DOMList->appendChild($DOMElement_Child);
}
}
public static function getRequestMTextList(Account &$param_HostAccount, iStorable &$param_iStorable, $param_RequestValue, MultimediaText $param_PartOf, $param_BasisClipboardName=false, array $param_ConditionArray=null) {
$var_BEADB = $param_iStorable->getBasisElementAddonDataBase('Category');D::show($param_PartOf->getObjVar('ID'),'PartOf');
return $var_BEADB->getContList($param_HostAccount, $param_iStorable,$param_RequestValue, $param_PartOf->getObjVar('ID'), $param_Depth=null, $param_BasisClipboardName);
}
}
?>