* @package WB * @subpackage ITS */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Mail' , 'WBITS' , 'patI18n'); /** * WBEvent_Handler_ITS_MailMaster * * Send e-mail to all ticket masters * * @version 1.0.1 * @package Wombat * @subpackage ITS */ 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 * - "scopeuseronly" Send E-Mail to users marked in scope * * @see WBEvent_Handler_Mail * @var array */ protected $config = array( 'from' => '', 'fromindex' => '', 'rcpt' => '', 'rcptindex' => 'email', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email', 'skipsame' => '1', 'group' => 'its-master', 'scopeuseronly' => 0, '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) { $data = $e->get(); $this->table = WBClass::create('WBDatasource_Table'); $pScope = $this->table->getIdentifier(WBITS::TABLE_TICKETSCOPE); $pUser = $this->table->getIdentifier('user'); $pGroup = $this->table->getIdentifier('group'); // select recipients $clause = array(); $clause[] = array( 'table' => 'group', 'field' => 'groupname', 'value' => $this->config['group'] ); $options = array( 'limit' => 100, 'join' => array( array( 'table' => 'group', 'using' => $pGroup ) ) ); if (0 < intval($this->config['scopeuseronly'])) { $clause[] = array( 'table' => WBITS::TABLE_TICKETSCOPEUSER, 'field' => $pScope, 'value' => $data[$pScope] ); $options['join'][] = array( 'table' => WBITS::TABLE_TICKETSCOPEUSER, 'using' => $pUser ); } $pager = $this->table->getPager(__CLASS__ . ':user', 'usergroup', null, $clause, $options); $info = $pager->browse(); $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[$pUser] == $r[$pUser]) { continue; } if (!$this->user->load($r[$pUser])) { 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; } }