Esempio n. 1
0
 /**
  * The API to search for a package
  * @param string $term The term to search for in a package
  * @param string $format The return format
  * @return $format
  */
 public function search()
 {
     $term = $this->input->get('q');
     $this->load->model('spark');
     if (strlen($term) <= 2) {
         $this->output->set_output(json_encode(array('success' => FALSE, 'message' => 'You must search with at least 2 characters')));
         return;
     }
     $this->output->set_output(json_encode(array('success' => true, 'results' => Spark::search($term))));
 }
Esempio n. 2
0
 /**
  * The search page call
  */
 function index()
 {
     $this->load->helper('form');
     $this->load->library('form_validation');
     $submit = $this->input->post('submit');
     $search_results = array();
     $search_term = $this->input->get_post('term', TRUE);
     if ($submit) {
         if ($this->form_validation->run('search')) {
             $this->load->model('spark');
             $search_results = Spark::search($search_term);
         } else {
             UserHelper::setNotice('Whoops. There were some errors. Check below and re-submit!');
         }
     }
     $data['search_term'] = $search_term;
     $data['sparks'] = $search_results;
     echo json_encode($data);
 }
Esempio n. 3
0
 /**
  * Show the spark search page
  */
 function search()
 {
     $this->load->helper('form');
     $this->load->library('form_validation');
     $submit = $this->input->post('submit');
     $search_results = array();
     $search_term = $this->input->post('term');
     $data['ratings'] = array();
     if ($submit) {
         if ($this->form_validation->run('search')) {
             $this->load->model('spark');
             $this->load->model('rating');
             $search_results = Spark::search($search_term);
             $ids = array();
             foreach ($search_results as $s) {
                 $ids[] = $s->id;
             }
             $data['ratings'] = $this->rating->getRatingsFromList($ids);
         } else {
             UserHelper::setNotice('Whoops. There were some errors. Check below and re-submit!');
         }
     }
     $data['search_term'] = $search_term;
     $data['sparks'] = $search_results;
     $data['description'] = 'These are the most recently registered sparks with at least one release.';
     $this->load->view('search/listing', $data);
 }