forked from koala-framework/koala-framework
/
Component.php
121 lines (112 loc) · 4.86 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
113
114
115
116
117
118
119
120
121
<?php
abstract class Kwc_Directories_List_Component extends Kwc_Abstract_Composite_Component
{
private $_itemDirectory = false;
public static function getSettings()
{
$ret = parent::getSettings();
$ret['generators']['child']['component']['view'] = 'Kwc_Directories_List_ViewPage_Component';
$ret['useDirectorySelect'] = true;
$ret['generatorJoins'] = false;
return $ret;
}
final public function getItemDirectory()
{
if ($this->_itemDirectory === false) {
$this->_itemDirectory = $this->_getItemDirectory();
if (!$this->_itemDirectory) return $this->_itemDirectory;
$isData = call_user_func(array(get_class($this), 'getItemDirectoryIsData'), $this->getData()->componentClass);
if (is_string($this->_itemDirectory)) {
if ($isData) {
throw new Kwf_Exception("_getItemDirectory returns string, so getItemDirectoryIsData must return false; componentClass is ".get_class($this));
}
$c = $this->_itemDirectory;
} else {
if (!$isData) {
throw new Kwf_Exception("_getItemDirectory returns data, so getItemDirectoryIsData must return true; componentClass is ".get_class($this));
}
$c = $this->_itemDirectory->componentClass;
}
if (!is_instance_of($c, 'Kwc_Directories_Item_DirectoryNoAdmin_Component')) {
throw new Kwf_Exception("_getItemDirectory must return an Kwc_Directories_Item_DirectoryNoAdmin_Component data object or class-name, '{$c}' given; componentClass is ".get_class($this));
}
}
return $this->_itemDirectory;
}
final protected function _getItemDirectoryClass()
{
$ret = $this->getItemDirectory();
if (is_object($ret)) $ret = $ret->componentClass;
return $ret;
}
final protected function _getItemDirectorySetting($setting)
{
return Kwc_Abstract::getSetting($this->_getItemDirectoryClass(), $setting);
}
public static function getItemDirectoryIsData($directoryClass)
{
return true;
}
abstract protected function _getItemDirectory();
abstract public static function getItemDirectoryClasses($componentClass);
protected static function _getParentItemDirectoryClasses($componentClass, $steps = null)
{
$ret = array();
foreach (Kwc_Abstract::getComponentClasses() as $class) {
foreach (Kwc_Abstract::getChildComponentClasses($class) as $childClass) {
if ($childClass == $componentClass) {
if ($steps === 0) {
$ret[] = $class;
} else if (is_null($steps)) {
if (is_instance_of($class, 'Kwc_Directories_Item_Directory_Component')) {
$ret[] = $class;
}
} else {
$ret = array_merge(
$ret,
self::_getParentItemDirectoryClasses($class, $steps - 1)
);
}
}
}
}
return $ret;
}
public function getSelect()
{
$itemDirectory = $this->getItemDirectory();
if (!$itemDirectory) return null;
if (is_string($itemDirectory)) {
if ($this->_getSetting('useDirectorySelect')) {
throw new Kwf_Exception("If itemDirectory is a ComponentClass you can't use 'useDirectorySelect' setting");
}
$c = Kwc_Abstract::getComponentClassByParentClass($itemDirectory);
$ret = Kwf_Component_Generator_Abstract::getInstance($c, 'detail')
->select(null);
} else {
if ($this->_getSetting('useDirectorySelect')) {
$ret = $itemDirectory->getComponent()->getSelect();
} else {
$ret = $itemDirectory->getGenerator('detail')
->select($this->getItemDirectory());
}
}
if (Kwc_Abstract::hasSetting($this->getData()->componentClass, 'order')) {
throw new Kwf_Exception("Setting 'order' (".get_class($this).") doesn't exist anymore - overwrite getSelect for a custom order");
}
return $ret;
}
public final function callModifyItemData(Kwf_Component_Data $item)
{
foreach (Kwc_Abstract::getChildComponentClasses($this->getData()->componentClass) as $c) {
if (Kwc_Abstract::hasSetting($c, 'hasModifyItemData')
&& Kwc_Abstract::getSetting($c, 'hasModifyItemData')) {
call_user_func(array(strpos($c, '.') ? substr($c, 0, strpos($c, '.')) : $c, 'modifyItemData'), $item, $c);
}
}
}
public static function getViewCacheLifetimeForView()
{
return null;
}
}