forked from koala-framework/koala-framework
/
Events.php
61 lines (58 loc) · 2.39 KB
/
Events.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
<?php
class Kwc_Abstract_Events extends Kwf_Component_Abstract_Events
{
public function getListeners()
{
$ret = array();
$cls = strpos($this->_class, '.') ? substr($this->_class, 0, strpos($this->_class, '.')) : $this->_class;
$m = call_user_func(array($cls, 'createOwnModel'), $this->_class);
if ($m) {
$ret[] = array(
'class' => $m,
'event' => 'Kwf_Events_Event_Row_Updated',
'callback' => 'onOwnRowUpdate'
);
$ret[] = array(
'class' => $m,
'event' => 'Kwf_Events_Event_Row_Inserted',
'callback' => 'onOwnRowUpdate'
);
}
return $ret;
}
//gets called when own row gets updated and component is visible
protected function _onOwnRowUpdate(Kwf_Component_Data $c, Kwf_Events_Event_Row_Abstract $event)
{
}
//gets called when own row gets updated, weather component is visible or not
protected function _onOwnRowUpdateNotVisible(Kwf_Component_Data $c, Kwf_Events_Event_Row_Abstract $event)
{
}
//override _onOwnRowUpdate to implement custom functionality
public final function onOwnRowUpdate(Kwf_Events_Event_Row_Abstract $event)
{
$cmps = Kwf_Component_Data_Root::getInstance()->getComponentsByDbId(
$event->row->component_id, array('ignoreVisible'=>true)
);
foreach ($cmps as $c) {
if ($c->componentClass == $this->_class) {
if ($c->isVisible()) {
$this->fireEvent(new Kwf_Component_Event_Component_ContentChanged(
$this->_class, $c
));
if (Kwc_Abstract::hasSetting($this->_class, 'throwHasContentChangedOnRowColumnsUpdate')) {
if ($event->isDirty(Kwc_Abstract::getSetting($this->_class, 'throwHasContentChangedOnRowColumnsUpdate'))) {
$this->fireEvent(new Kwf_Component_Event_Component_HasContentChanged(
$this->_class, $c
));
}
}
$this->_onOwnRowUpdate($c, $event);
$this->_onOwnRowUpdateNotVisible($c, $event);
} else {
$this->_onOwnRowUpdateNotVisible($c, $event);
}
}
}
}
}