* @license PHP License * @package Wombat * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * Event_Handler_User_Mail * * Send an e-mail to multiple users * * @version 0.1.0 * @package Wombat * @subpackage base */ class WBEvent_Handler_User_Mail 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 * - "uid" user id (or list of) to collect e-mail addresse(s) from * * @var array */ protected $config = array( 'rcpt' => '', 'rcptindex' => 'rcpt_email', 'from' => '', 'fromindex' => '', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email', 'gid' => '', 'uid' => '', 'uidindex' => '' ); /** * User * @var WBUser */ private $user; /** * @var WBEvent_Handler_Mail */ private $mail; /** * Send E-Mails * * Collect users by uids 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) { $uid = $this->config['uid']; if (empty($uid) && !empty($this->config['uidindex'])) { $uid = $e->get($this->config['uidindex']); } if (empty($uid)) { return true; } if (!is_array($uid)) { $uid = array($uid); } $this->mail2UserList($e, $uid); return true; } /** * Send E-Mail to List of Users * * Utilize mail hanlder to send e-mail to user * * @see mail2User() * @param WBEvent * @param array list of user ids */ protected function mail2UserList($e, $uid = array()) { if (empty($uid)) { return; } $this->user = WBClass::create('WBUser'); // 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); } } foreach ($uid as $id) { $this->mail2User($e, $id); } } /** * Send E-Mail to Single User * * @param WBEvent * @param string user id */ private function mail2User($e, $id) { if (!$this->user->load($id)) { return; } if (!$this->user->isEnabled()) { return; } $user = $this->user->getData(); $copy = array('email', 'forename', 'surname', 'lang'); foreach ($copy as $c) { $e->set('rcpt_' . $c, $user[$c]); } $this->mail->process($e); } }