* @license PHP License * @package Wombat * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * Event_Handler_MailUserGroup * * Send an e-mail to multiple users * * @deprecated in favour of WBEvent_Handler_User_Mail_Group * @version 0.4.0 * @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 * - "replyto" e-mail address in reply-to header * - "replytoindex" load e-mail address for from header reply-toindex * - "rcpt" e-mail address of recipient * - "rcptindex" e-mail address of recipient loaded from 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( 'rcpt' => '', 'rcptindex' => 'rcpt_email', 'from' => '', 'fromindex' => '', 'replyto' => '', 'replytoindex' => '', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email', 'gid' => '' ); /** * 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. * Add users' data to event data, prefixed by "rcpt_" * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $gid = $e->get('gid'); if (!empty($this->config['gid'])) { $gid = $this->config['gid']; } $this->user = WBClass::create('WBUser'); $this->storage = $this->user->getStorageModule(); $ids = $this->storage->getIdByGroupId($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('rcpt_' . $c, $user[$c]); } $this->mail->process($e); } return true; } }