acct)) $this->acct = $event->acct; elseif ($this->acct != $event->acct) throw new Kohana_Exception('Events are for multiple accounts, unable to handle this.'); } // Save our events $this->events = $events; } public function trigger() { $ao = ORM::factory('account',array('siteid'=>$this->acct)); if (! $ao->loaded()) throw new Kohana_Exception('No site configuration for :siteid?',array(':siteid'=>$this->acct)); if (! $ao->model->model) throw new Kohana_Exception('No configured Alarm Model for Alarm ID :id',array(':id'=>$ao->model->id)); $ac = sprintf('Panel_%s',$ao->model->model); if (! class_exists($ac)) throw new Kohana_Exception('Unable to handle events for Alarm :model',array(':model'=>$ao->model->model)); $panel = new $ac($this->events); foreach ($panel->trigger() as $event) { $to = $ao->trigger->trigger($event['alarm']); if (! $to->loaded()) continue; // We need to email this event if ($to->email) { $e = Email::connect(); $sm = Swift_Message::newInstance(); $sm->setSubject('Notice from your alarm'); $sm->setBody(sprintf('Alarm: %s. Received: %s',$event['desc'],date('d-m-Y h:i:s',$event['date'])),'text/plain'); $sm->setTo($to->contact->email); $sm->setFrom('noreply@leenooks.net'); $e->send($sm); } // We need to sms this event if ($to->sms) { printf('Alarm: %s, SMS: %s, Email: %s, To: %s (%s)', $alo->description, $to->sms, $to->email, $to->contact->email,$to->contact->phone); echo "\n"; } } } } ?>