* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_User' ); /** * Event_Handler_User_Add2Group * * Add user to group * * @version 0.1.0 * @package WB * @subpackage base */ class WBEvent_Handler_User_Add2Group extends WBEvent_Handler_User { /** * Handler config * * Parameters: * - group list of group ids to add * * @var array */ protected $config = array( 'group' => 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'])) { $this->debugPrint('Nothing to do, grouplist ist empty'); return true; } if (!is_array($this->config['group'])) { $this->config['group'] = array($this->config['group']); } // there is no user if (!$this->loadUser($e)) { $this->debugPrint('Nothing to do, could not load user'); return true; } $group = $this->user->getGroups(); if (!empty($group)) { $group = array_keys($group); } $save = false; foreach ($this->config['group'] as $g) { if (!in_array($g, $group)) { $group[] = $g; $save = true; } } if ($save) { $this->user->setGroups($group); return true; } $this->debugPrint('Nothing to do, user is already in groups'); return true; } }