Init($prefix,$special);
$this->Name = getArrayValue($params,'name');
}
elseif ($params && is_string($params)) {
if (preg_match('/([^.:]*)[.]{0,1}([^:]*):(.*)/', $params, $regs)) {
$prefix = $regs[1];
$special = $regs[2];
if($prefix) $this->Init($prefix,$special);
$this->Name = $regs[3];
}
else {
trigger_error('Invalid event string '.$params.' should be prefix[.special]:OnEvent ', E_USER_ERROR);
}
}
if (isset($specificParams)) $this->specificParams = $specificParams;
}
function setEventParam($name,$value)
{
$this->specificParams[$name]=$value;
}
function getEventParam($name)
{
$args = func_get_args();
array_unshift($args, $this->specificParams);
return call_user_func_array('getArrayValue', $args); // getArrayValue($this->specificParams, $name);
}
function getPrefixSpecial($from_submit=false)
{
$separator=!$from_submit?'.':'_';
$ret=$this->Prefix.$separator.$this->Special;
return rtrim($ret,$separator);
}
/**
* Set's pseudo class that differs from
* the one specified in $Prefix
*
* @param string $appendix
* @access public
*/
function setPseudoClass($appendix)
{
$this->pseudoClass = $this->Prefix.$appendix;
}
function Init($prefix, $special = '')
{
$this->Prefix = $prefix;
$this->pseudoClass = $prefix; // default value
$this->Special = $special;
$this->Prefix_Special = rtrim($this->Prefix.'.'.$this->Special,'.');
}
/**
* Returns object used in event
*
* @access public
* @return kDBBase
*/
function &getObject($params = Array())
{
$object =& $this->Application->recallObject($this->Prefix_Special, $this->pseudoClass, $params);
return $object;
}
/**
* Calls passed event by name in current prefix/special environment
* Called event gets this event as MasterEvent,
* but its results (status and redirect* properties are copied back to current event)
*
* @param string $name EventName to call
*/
function CallSubEvent($name)
{
$child_event = new kEvent();
$child_event->MasterEvent =& $this;
$child_event->Prefix = $this->Prefix;
$child_event->Special = $this->Special;
$child_event->Prefix_Special = $this->Prefix_Special;
$child_event->redirect = $this->redirect;
$child_event->redirect_params = $this->redirect_params;
$child_event->redirect_script = $this->redirect_script;
$child_event->Name = $name;
$this->Application->HandleEvent( $child_event );
$this->status = $child_event->status;
$this->redirect = $child_event->redirect;
$this->redirect_params = $child_event->redirect_params;
$this->redirect_script = $child_event->redirect_script;
}
/**
* Set's redirect param for event
*
* @param string $name
* @param string $value
* @access public
*/
function SetRedirectParam($name, $value)
{
$this->redirect_params[$name] = $value;
}
/**
* Allows to merge passed redirect params hash with existing ones
*
* @param Array $params
* @access public
*/
function setRedirectParams($params)
{
$this->redirect_params = array_merge_recursive2($this->redirect_params, $params);
}
/**
* Returns Master event name if any
*
* @return mixed
* @access public
*/
function hasMasterEvent()
{
return is_object($this->MasterEvent) ? $this->MasterEvent->Name : false;
}
/**
* Allows to tell if this event was called some how (e.g. subevent, hook) from event requested
*
* @param string $event_key event key in format [prefix[.special]:]event_name
* @return unknown
*/
function hasAncestor($event_key)
{
$event_manager =& $this->Application->recallObject('EventManager');
if (strpos($event_key, ':') === false) {
$event_key = $this->getPrefixSpecial().':'.$event_key;
}
return $event_manager->eventRunning($event_key);
}
/**
* Returns section for current event
*
* @return string
*/
function getSection()
{
$perm_section = $this->getEventParam('PermSection');
if ($perm_section) {
return $perm_section;
}
$main_prefix = $this->Application->GetTopmostPrefix($this->Prefix);
$section = $this->Application->getUnitOption($main_prefix, 'PermSection');
if (!$section) {
trigger_error('Permission section not specified for prefix '.$main_prefix.'', E_USER_ERROR);
}
return $section;
}
}
?>