* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Mail' , 'patI18n'); /** * WBEvent_Handler_ITS_MailMaster * * Send e-mail to all ticket masters * * @version 1.0.0 * @package Wombat * @subpackage base */ class WBEvent_Handler_ITS_MailMaster extends WBEvent_Handler_Mail { /** * Handler config * * For parameter list see parent class, additional parameter: * - "skipsame" Don't send e-mail if editing user is the same as recipient (default: 1) * - "group" usergroup to select (default: "its-master") * - "enabled" only use enabled users * * @see WBEvent_Handler_Mail * @var array */ protected $config = array( 'from' => '', 'fromindex' => '', 'rcpt' => '', 'rcptindex' => 'email', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email', 'skipsame' => '1', 'group' => 'its-master', 'enabled' => '1' ); /** * User object * * @var WBUser */ private $user; /** * Table access * * @var WBDatasource_Table */ private $table; /** * Process event * * Prepare to send e-mail to assignee. Use parent class to actually send e-mail. * Select recipients by user group * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $this->table = WBClass::create('WBDatasource_Table'); // select recipients $clause = array(); $clause[] = array( 'table' => 'group', 'field' => 'groupname', 'value' => $this->config['group'] ); $options = array( 'limit' => 100, 'join' => array( array( 'table' => 'group', 'using' => $this->table->getIdentifier('group') ) ) ); $uPrimary = $this->table->getIdentifier('user'); $pager = $this->table->getPager(__CLASS__ . ':user', 'usergroup', null, $clause, $options); $info = $pager->browse(); $data = $e->get(); $e->set('status_display', patI18n::dgettext('wombat', 'its_status_' . $data['status'])); $this->user = WBClass::create('WBUser'); for ($i = 0; $i < $info['pages']; ++$i) { $rcpts = $pager->get(); foreach ($rcpts as $r) { // don't send an e-mail if ticket was saved by myself if (!empty($this->config['skipsame']) && 0 < intval($this->config['skipsame']) && $data[$uPrimary] == $r[$uPrimary]) { continue; } if (!$this->user->load($r[$uPrimary])) { continue; } if (!empty($this->config['enabled']) && 0 < intval($this->config['enabled']) && !$this->user->isEnabled()) { continue; } $user = $this->user->getData(); $this->config['rcpt'] = $user['email']; $this->config['lang'] = $user['lang']; parent::process($e); } $pager->browse('__next'); break; } return true; } }