/** * All = all fields are filled * 1 = Author field is checked * 2 = Course field is checked * 3 = Author and Course field are checked * 4 = Lesson Field is checked * 5 = Lesson and Author fields are checked * 6 = Course and lesson fields are checked * Any other input = All fields selected */ public function index($match = '-', $fields = 'all', $page = null) { $this->data['main_view12'] = ''; if ($match == "-" or $match == NULL) { $this->data['did_we_search'] = false; } else { $this->data['did_we_search'] = true; } switch ($fields) { case "author": $this->data['checkbox_checking'][1] = true; $this->data['checkbox_checking'][2] = false; $this->data['checkbox_checking'][4] = false; break; case "course": $this->data['checkbox_checking'][1] = false; $this->data['checkbox_checking'][2] = true; $this->data['checkbox_checking'][4] = false; break; case "author-course": $this->data['checkbox_checking'][1] = true; $this->data['checkbox_checking'][2] = true; $this->data['checkbox_checking'][4] = false; break; case "lesson": $this->data['checkbox_checking'][1] = false; $this->data['checkbox_checking'][2] = false; $this->data['checkbox_checking'][4] = true; break; case "author-lesson": $this->data['checkbox_checking'][1] = true; $this->data['checkbox_checking'][2] = false; $this->data['checkbox_checking'][4] = true; break; case "course-lesson": $this->data['checkbox_checking'][1] = false; $this->data['checkbox_checking'][2] = true; $this->data['checkbox_checking'][4] = true; break; default: $this->data['checkbox_checking'][1] = true; $this->data['checkbox_checking'][2] = true; $this->data['checkbox_checking'][4] = true; break; } // end of fields if ($this->input->post('search_mini_button') == true) { $filter_slug = "all"; redirect($this->data['language'] . '/user/search/index/' . seoUrl($this->input->post('search')) . '/' . $filter_slug . '/' . $page, 'refresh'); } $property = $this->input->post('checkbox_group'); //$this->data['main_view12']=$property; $total = 0; $filter_slug = ''; if ($this->input->post('search')) { $this->data['did_we_search'] = true; $match = seoUrl($this->input->post('search')); if ($property) { foreach ($property as $value) { $total += $value; } } switch ($total) { case 1: $filter_slug = "author"; break; case 2: $filter_slug = "course"; break; case 3: $filter_slug = "author-course"; break; case 4: $filter_slug = "lesson"; break; case 5: $filter_slug = "author-lesson"; break; case 6: $filter_slug = "course-lesson"; break; default: $filter_slug = "all"; break; } redirect($this->data['language'] . '/user/search/index/' . seoUrl($this->input->post('search')) . '/' . $filter_slug . '/' . $page, 'refresh'); } //-------------------- Configuring the Pagination ---------------------- $config = array(); $config["base_url"] = base_url() . $this->data['language'] . "/user/search/index/" . $match . '/' . $fields; //Defaulting the match parameter if ($match == '-') { $match = NULL; } $this->data['main_view12'] = $config["total_rows"] = $this->course_m->search_count(decodeseoUrl($match), $fields); $config['num_links'] = 3; $config["per_page"] = 10; $config["uri_segment"] = 7; // Configuring styles for pagination (Located in '/library/MY_PAgination') foreach ($this->my_pagination->set_style() as $key => $value) { $config[$key] = $value; } $this->pagination->initialize($config); $this->data["course_data"] = ' '; $page = $this->uri->segment(7) ? $this->uri->segment(7) : 0; $this->data["course_data"] = $this->course_m->search_limit($config["per_page"], $page, decodeseoUrl($match), $fields); $this->data["page_links"] = $this->pagination->create_links(); //-------------------- Configuring the Pagination ---------------------- //Search options if ($this->input->post('match') != null) { //Redirecting to display the search results $match = $this->input->post('match'); $match = seoUrl($this->input->post('match')); redirect($this->data['language'] . '/user/search/index/' . $this->data['url'] . $match . '/' . $fields, 'refresh'); } $this->data['main_view12'] = decodeseoURL($match); $this->data['main_view'] = 'en/3-user/components/views/search/main_search_window'; $this->load->view('en/3-user/layout/_layout_notification', $this->data); }
public function search_count($keyword, $field) { $keyword = decodeseoURL($keyword); if ($keyword != null) { $this->db->select("category.category_name, category.image, courses.course_id, courses.c_slug, courses.author_id, courses.title, lessons.lesson_id, lessons.lesson_name, lessons.lesson_slug, users.username"); switch ($field) { case "author": $this->db->or_like('users.username', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; case "course": $this->db->like('courses.title', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; case "author-course": $this->db->like('courses.title', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); $this->db->or_like('users.username', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; case "lesson": $this->db->or_like('lessons.lesson_name', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; case "author-lesson": $this->db->or_like('users.username', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); $this->db->or_like('lessons.lesson_name', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; case "course-lesson": $this->db->like('courses.title', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); $this->db->or_like('lessons.lesson_name', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; default: $this->db->like('courses.title', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); $this->db->or_like('users.username', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); $this->db->or_like('lessons.lesson_name', $keyword); $this->db->like('courses.approved', 1, 'none'); $this->db->like('lessons.approved', 1, 'none'); $this->db->like('category.approved', 1, 'none'); break; } $this->db->from('courses'); $this->db->join('lessons', 'courses.course_id = lessons.course_id', 'left'); $this->db->join('category', 'courses.category_id = category.category_id', 'left'); $this->db->join('users', 'courses.author_id = users.id', 'left'); return $this->db->count_all_results(); } else { return null; } }