forked from koala-framework/koala-framework
/
Component.php
112 lines (101 loc) · 3.74 KB
/
Component.php
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
<?php
class Kwc_Abstract_List_Component extends Kwc_Abstract
{
public static function getSettings()
{
$ret = array_merge(parent::getSettings(), array(
'componentName' => 'List',
'childModel' => 'Kwc_Abstract_List_Model',
'ownModel' => 'Kwc_Abstract_List_OwnModel',
));
$ret['generators']['child'] = array(
'class' => 'Kwc_Abstract_List_Generator',
'component' => null
);
$ret['assetsAdmin']['dep'][] = 'KwfProxyPanel';
$ret['assetsAdmin']['dep'][] = 'KwfAutoGrid';
$ret['assetsAdmin']['dep'][] = 'KwfMultiFileUploadPanel';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Abstract/List/EditButton.js';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Abstract/List/PanelWithEditButton.js';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Abstract/List/List.js';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Abstract/List/ListEditButton.js';
$ret['extConfig'] = 'Kwc_Abstract_List_ExtConfigListUpload';
$ret['hasVisible'] = true;
$ret['maxEntries'] = 100;
return $ret;
}
public static function validateSettings($settings)
{
if (isset($settings['default'])) {
throw new Kwf_Exception("Setting default doesn't exist anymore");
}
}
// For trl
public final function getSelect()
{
return $this->_getSelect();
}
//kann überschrieben werden um zB ein limit einzubauen
protected function _getSelect()
{
$select = new Kwf_Component_Select();
$select->whereGenerator('child');
return $select;
}
public function getTemplateVars()
{
$ret = parent::getTemplateVars();
$children = $this->getData()->getChildComponents($this->getSelect());
// children ist die alte methode, bleibt drin wegen kompatibilität
$ret['children'] = $children;
// das hier ist die neue variante und ist besser, weil man leichter mehr daten
// zurückgeben kann, bzw. in der übersetzung überschreiben kann
// zB: Breite bei übersetzung von Columns
$ret['listItems'] = array();
$i = 0;
foreach ($children as $child) {
$class = $this->_getBemClass('listItem', 'listItem').' ';
if ($i == 0) $class .= ' '.$this->_getBemClass('listItem--first', 'kwcFirst');
if ($i == count($children)-1) $class .= ' '.$this->_getBemClass('listItem--last', 'kwcLast');
if ($i % 2 == 0) {
$class .= ' '.$this->_getBemClass('listItem--even', 'kwcEven');
} else {
$class .= ' '.$this->_getBemClass('listItem--odd', 'kwcOdd');
}
$class = trim($class);
$i++;
$ret['listItems'][] = array(
'data' => $this->getItemComponent($child),
'class' => $class,
'style' => '',
);
}
return $ret;
}
// For trl
public final function getItemComponent($childComponent)
{
return $this->_getItemComponent($childComponent);
}
protected function _getItemComponent($childComponent)
{
return $childComponent;
}
public function getExportData()
{
$ret = array('list' => array());
$children = $this->getData()->getChildComponents($this->_getSelect());
foreach ($children as $child) {
$ret['list'][] = $child->getComponent()->getExportData();
}
return $ret;
}
public function hasContent()
{
$childComponents = $this->getData()->getChildComponents($this->_getSelect());
foreach ($childComponents as $c) {
if ($c->hasContent()) return true;
}
return false;
}
}