* @license PHP License * @package Wombat * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * Event_Handler_MailUserGroup * * Send an e-mail to multiple users * * @version 0.1.1 * @package Wombat * @subpackage base */ class WBEvent_Handler_MailUserGroup extends WBEvent_Handler { /** * Handler config * * Parameters * - "from" e-mail address in from header * - "fromindex" load e-mail address for from header form index * - "addrcpt" list of additional rcpts * - "lang" locale settings * - "langindex" index for locale settings * - "tmpl" template for mail body * - "gid" user group to collect e-mail addresses from * * @var array */ protected $config = array( 'from' => '', 'fromindex' => '', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email', ); /** * User * @var WBUser */ private $user; /** * User Storage * @var WBUser_Storage */ private $storage; /** * @var WBEvent_Handler_Mail */ private $mail; /** * Send E-Mails * * Collect users by group and e-mails to all addresses * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $this->user = WBClass::create('WBUser'); $this->storage = $this->user->getStorageModule(); $ids = $this->storage->getIdByGroupId($e->get('gid')); if (empty($ids)) { return true; } // pass to other event handler $this->mail = WBClass::create('WBEvent_Handler_Mail'); $this->mail->setConfig($this->config); $save = $e->get('save', array()); if (!empty($save)) { foreach ($save as $k => $v) { $e->set($k, $v); } } $copy = array('email', 'forename', 'surname', 'lang'); foreach ($ids as $id) { if (!$this->user->load($id)) { continue; } if (!$this->user->isEnabled()) { continue; } $user = $this->user->getData(); foreach ($copy as $c) { $e->set($c, $user[$c]); } $this->mail->process($e); } return true; } }