* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_User' ); /** * Event_Handler_User_StopOnGroup * * Stop event processing in case * * @version 1.1.0 * @package WB * @subpackage base */ class WBEvent_Handler_User_StopOnGroup extends WBEvent_Handler_User { /** * Handler config * * Parameters: * - group list of groups that must match invert group with "!" prefix * - anonymous what to do for no user: continue (default) or stop * - ignoreuser list of user ids that never stop * * @var array */ protected $config = array( 'group' => array(), 'anonymous' => 'continue', 'ignoreuser' => array() ); /** * Conditional Stop Event Processing * * Stop processing according to values. By default - if there is no "key", event will be stopped. * If there is a key, it will check event data values against configured values and stop * on match. * * @see isRecoverable() * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { // no group just go on if (empty($this->config['group'])) { return true; } if (!is_array($this->config['group'])) { $this->config['group'] = array($this->config['group']); } // there is no user if (!$this->loadUser($e)) { if ('continue' == $this->config['anonymous']) { $this->debugPrint('Continue beause of anonymous user'); return true; } $this->debugPrint('Stop beause of anonymous user'); return false; } if (!empty($this->config['ignoreuser'])) { $uid = $this->user->getId(); if (in_array($uid, $this->config['ignoreuser'])) { $this->debugPrint('Continue because current user ignored according configuration'); return true; } } foreach ($this->config['group'] as $group) { $group = trim($group); $xor = false; if ('!' == $group[0]) { $xor = true; $group = substr($group, 1); } $res = ($xor XOR $this->user->isInGroup($group)); if ($res) { if ($xor) { $this->debugPrint('Stop because user is not in group'); } else { $this->debugPrint('Stop because user is in group'); } return false; } } $this->debugPrint('Continue because no stop condition matched'); return true; } }