/** * Process notices to send out * * @param array $notices * @param string $event * @return array $retval['type' => (Notification::<type>), 'email' => (string), 'template' => (string)] */ protected function processNotices($notices, $event) { if (!isset($this->eventEmailTemplates[$event])) { throw new Exception("No Email Template found for event"); } $emailTemplate = $this->eventEmailTemplates[$event]; $retval = array(); foreach ($notices as $notice) { switch ($notice->type) { case Notification::TYPE_EMAIL: switch (true) { case isset($notice->group_id) && $notice->group_id > 0: $users = Group::findUsersByRole(Group::ROLE_OWNER); foreach ($users as $user) { $retval[] = array('type' => Notification::TYPE_EMAIL, 'email' => $user->email, 'template' => $emailTemplate); } break; case isset($notice->user_id) && $notice->user_id > 0: $user = User::where('id', '=', $notice->user_id)->first(); if (!$user) { continue; } $retval[] = array('type' => Notification::TYPE_EMAIL, 'email' => $user->email, 'template' => $emailTemplate); break; default: // Admin not a group or specific user $users = User::findByRoleName(Role::ROLE_ADMIN); foreach ($users as $user) { $retval[] = array('type' => Notification::TYPE_EMAIL, 'email' => $user->email, 'template' => $emailTemplate); } break; } break; case Notification::TYPE_TEXT: break; } } return $retval; }