1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/limesurvey_ynh.git synced 2024-09-03 19:36:32 +02:00
limesurvey_ynh/sources/application/models/behaviors/PluginEventBehavior.php

59 lines
No EOL
1.7 KiB
PHP

<?php
class PluginEventBehavior extends CModelBehavior
{
public function events()
{
return array_merge(parent::events(), array(
'onAfterDelete' => 'afterDelete',
'onAfterSave' => 'afterSave',
'onBeforeDelete' => 'beforeDelete',
'onBeforeSave' => 'beforeSave',
));
}
public function afterDelete(CEvent $event)
{
$this->dispatchPluginModelEvent('after'.get_class($this->owner).'Delete');
$this->dispatchPluginModelEvent('afterModelDelete');
}
public function afterSave(CEvent $event)
{
$this->dispatchPluginModelEvent('after'.get_class($this->owner).'Save');
$this->dispatchPluginModelEvent('afterModelSave');
}
public function beforeDelete(CModelEvent $event)
{
$this->dispatchPluginModelEvent('before'.get_class($this->owner).'Delete');
$this->dispatchPluginModelEvent('beforeModelDelete');
}
public function beforeSave(CModelEvent $event)
{
$this->dispatchPluginModelEvent('before'.get_class($this->owner).'Save');
$this->dispatchPluginModelEvent('beforeModelSave');
}
/**
* 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
*/
public 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);
}
}
?>