예제 #1
0
 /**
  * It will handle the save query to the mailing list table
  */
 public function action_save()
 {
     // Json Helper
     $response = new Helper_Json();
     // Make sure this is a POST
     if ($this->request->method() != 'POST') {
         throw new HTTP_Exception_500('Invalid form method');
     }
     // serialize search string and options
     if (arr::get($_POST, 'search_string') || arr::get($_POST, 'category_id') || arr::get($_POST, 'jobtype_id') || arr::get($_POST, 'telecommute')) {
         // Serialzie all the search fields into one
         $saved_search = serialize(array('search_string' => arr::get($_POST, 'search_string', null), 'jobtype_id' => arr::get($_POST, 'jobtype_id', null), 'category_id' => arr::get($_POST, 'category_id', null), 'telecommute' => arr::get($_POST, 'telecommute', null)));
         // Tries to save
         try {
             $mailing_list = ORM::factory('mailinglist');
             $mailing_list->email = arr::get($_POST, 'email');
             $mailing_list->saved_search = $saved_search;
             $mailing_list->last_checked = date("Y-m-d h:i:s", strtotime("now"));
             $mailing_list->frequency = arr::get($_POST, 'frequency');
             $mailing_list->save();
             $response->valid = true;
             $response->message = 'Query Saved';
         } catch (ORM_Validation_Exception $e) {
             $response->valid = false;
             $response->message = 'Query Saved';
             $reponse->errors = $e->errors();
         }
     } else {
         $response->valid = true;
         $response->message = 'Not a valid search string. Please search for something';
         $reponse->errors = $e->errors();
     }
     header('Content-Type: applications/json');
     echo $response->output();
     die;
 }