/** * action_get() * * Loads the next job items based on the from filter and pagination * page */ public function action_get() { $this->auto_render = FALSE; // Make sure this is a POST request if ($this->request->method() != 'POST') { throw new HTTP_Exception_500('Invalid form method'); } // Search for ads $response_data = $this->search($_POST); // Set content type and enconde the array into a json string $response = new Helper_Json($response_data); // Creates a cookie to save the filter, ttl = 1month $this->create_cookie_filter($_POST); header('Content-Type: applications/json'); echo strip_tags($response->__set('valid', TRUE)->output()); }
/** * 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; }