/
PluginEventBehavior.php
49 lines (46 loc) · 1.48 KB
/
PluginEventBehavior.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
<?php
class PluginEventBehavior extends CModelBehavior
{
public function events()
{
return array_merge(parent::events(), array(
'onBeforeSave' => 'beforeSave',
'onAfterSave' => 'afterSave',
'onBeforeDelete' => 'beforeDelete',
));
}
public function afterSave(CModelEvent $event)
{
$this->dispatchPluginModelEvent('after'.get_class($this->owner).'Save');
$this->dispatchPluginModelEvent('afterModelSave');
}
public function beforeSave(CModelEvent $event)
{
$this->dispatchPluginModelEvent('before'.get_class($this->owner).'Save');
$this->dispatchPluginModelEvent('beforeModelSave');
}
public function beforeDelete(CModelEvent $event)
{
$this->dispatchPluginModelEvent('before'.get_class($this->owner).'Delete');
$this->dispatchPluginModelEvent('beforeModelDelete');
}
/**
* method for dispatching plugin events
*
* See {@link find()} for detailed explanation about $condition and $params.
* @param string $sEventName event name to dispatch
* @param array $criteria array containing attributes, conditions and params for the filter query
* @return PluginEvent the dispatched event
*/
private function dispatchPluginModelEvent($sEventName, $criteria = null)
{
$oPluginEvent = new PluginEvent($sEventName, $this);
$oPluginEvent->set('model', $this->owner);
if (isset($criteria))
{
$oPluginEvent->set('filterCriteria', $criteria);
}
return App()->getPluginManager()->dispatchEvent($oPluginEvent);
}
}
?>