/** * Tests Alert_Model->validate() * * @test * @dataProvider providerValidate * @param array $data Input data to be validated * @param boolean $save Toggles the saving of the alert data */ public function testValidate($data, $save) { // Create instance for the Alert_Model class $model = new Alert_Model(); // Check if the validation succeeded $this->assertEquals(TRUE, $model->validate($data, $save)); }
/** * Tests where no subscriber email address or phone no. has been specified * * @dataProvider providerValidateSubscriber */ public function test_validate_no_subscriber($data) { // Create an instance for the Alert_Model class $alert = new Alert_Model(); //Check if validation succeeded $this->assertFalse($alert->validate($data), 'Neither Alert Email address or Alert Mobile phone number has been specified'); }
/** * This handles sms alerts subscription via phone * * @param string $message_from Subscriber MSISDN (mobile phone number) * @param string $message_description Message content * @return bool */ public static function mobile_alerts_register($message_from, $message_description) { // Preliminary validation if (empty($message_from) or empty($message_description)) { // Log the error Kohana::log('info', 'Insufficient data to proceed with subscription via mobile phone'); // Return return FALSE; } //Get the message details (location, category, distance) $message_details = explode(" ", $message_description); $message = $message_details[1] . "," . Kohana::config('settings.default_country'); $geocoder = map::geocode($message); // Generate alert code $alert_code = text::random('distinct', 8); // POST variable with items to save $post = array('alert_type' => self::MOBILE_ALERT, 'alert_mobile' => $message_from, 'alert_code' => $alert_code, 'alert_lon' => $geocoder['lon'], 'alert_lat' => $geocoder['lat'], 'alert_radius' => '20', 'alert_confirmed' => '1'); // Create ORM object for the alert and validate $alert_orm = new Alert_Model(); if ($alert_orm->validate($post)) { return self::_send_mobile_alert($post, $alert_orm); } return FALSE; }
public function index() { // First, are we allowed to subscribe for alerts via web? if (!Kohana::config('settings.allow_alerts')) { url::redirect(url::site() . 'main'); } $this->template->header->this_page = $this->themes->this_page = 'alerts'; $this->template->content = new View('alerts/main'); // Load the alert radius map view $alert_radius_view = new View('alerts/radius'); $alert_radius_view->show_usage_info = TRUE; $alert_radius_view->enable_find_location = TRUE; $this->template->content->alert_radius_view = $alert_radius_view; // Display Mobile Option? $this->template->content->show_mobile = TRUE; if (!Kohana::config("settings.sms_provider")) { // Hide Mobile $this->template->content->show_mobile = FALSE; } // Retrieve default country, latitude, longitude $default_country = Kohana::config('settings.default_country'); // Retrieve Country Cities $this->template->content->cities = $this->_get_cities($default_country); // Populate this for backwards compat $this->template->content->categories = array(); // Setup and initialize form field names $form = array('alert_mobile' => '', 'alert_mobile_yes' => '', 'alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '', 'alert_radius' => '', 'alert_country' => '', 'alert_confirmed' => ''); if ($this->user) { $form['alert_email'] = $this->user->email; } // Get Countries $countries = array(); foreach (ORM::factory('country')->orderby('country')->find_all() as $country) { // Create a list of all countries $this_country = $country->country; if (strlen($this_country) > 35) { $this_country = substr($this_country, 0, 35) . "..."; } $countries[$country->id] = $this_country; } //Initialize default value for Alert confirmed hidden value $this->template->content->countries = $countries; // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; // If there is a post and $_POST is not empty if ($post = $this->input->post()) { $alert_orm = new Alert_Model(); // HT: created new model and post for mobile alert $alert_orm1 = new Alert_Model(); $post1 = $this->input->post(); if ($alert_orm->validate($post)) { // Yes! everything is valid // Save alert and send out confirmation code if (!empty($post->alert_mobile)) { // HT: setting value of post1 to alert_orm1 $alert_orm1->validate($post1); alert::_send_mobile_alert($post1, $alert_orm1); $this->session->set('alert_mobile', $post->alert_mobile); } if (!empty($post->alert_email)) { alert::_send_email_alert($post, $alert_orm); $this->session->set('alert_email', $post->alert_email); } url::redirect('alerts/confirm'); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('alerts')); if (array_key_exists('alert_recipient', $post->errors('alerts'))) { $errors = array_merge($errors, $post->errors('alerts')); } $form_error = TRUE; } } else { $form['alert_lat'] = Kohana::config('settings.default_lat'); $form['alert_lon'] = Kohana::config('settings.default_lon'); $form['alert_radius'] = 20; $form['alert_category'] = array(); } $this->template->content->form_error = $form_error; // Initialize Default Value for Hidden Field Country Name, just incase Reverse Geo coding yields no result $form['alert_country'] = $countries[$default_country]; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_saved = $form_saved; // Javascript Header $this->themes->map_enabled = TRUE; $this->themes->js = new View('alerts/alerts_js'); $this->themes->treeview_enabled = TRUE; $this->themes->slider_enabled = TRUE; $this->themes->js->latitude = $form['alert_lat']; $this->themes->js->longitude = $form['alert_lon']; }