public function get_child_categories_and_questions() { // $user_info = Auth::user()->toArray(); // if ($user_info['user_type'] == 2) { $parent_id = Input::get('main_category'); $category = new Category(); $categories = $category->get_categories_by_parent_id($parent_id); $child_ids_array = array(); if (!empty($categories)) { foreach ($categories as $single_categoty) { array_push($child_ids_array, $single_categoty['id']); } } else { $categories = array(); } array_push($child_ids_array, $parent_id); $question = new Questions(); $all_questions = $question->gat_category_questions_in_array($child_ids_array); $return_data = array('0' => $categories, '1' => $all_questions); return $return_data; // } // $message = "you are not admin. you can't use this method"; // return view('welcome') // ->withMessage($message); }
public function search_question_by_cat_id() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $question = new Questions(); $user = new User(); $user_data = $user->get_user_profile_data(); //id , username and user rank $root_cat_id = Input::get('root'); // OK $child_cat_id = Input::get('child'); // OK $sub_cat_id = Input::get('sub'); // OK $cat_id = $root_cat_id; if ($child_cat_id != null) { $cat_id = $child_cat_id; } if ($sub_cat_id != null) { $cat_id = $sub_cat_id; } $all_childs = $this->get_all_childs($cat_id); // gather all children (child and sub child and parent) in one array $gather_all_child = array(); array_push($gather_all_child, $cat_id); if (!empty($all_childs)) { foreach ($all_childs['child'] as $all) { array_push($gather_all_child, $all); } foreach ($all_childs['sub_child'] as $all) { array_push($gather_all_child, $all); } } $all_filtered_questions = array(); $category_questions = $question->gat_category_questions_in_array($gather_all_child); if (!empty($category_questions)) { foreach ($category_questions as $category_question) { array_push($all_filtered_questions, $category_question); } } return view('user/questions')->withUserData($user_data)->withAllQuestions($all_filtered_questions); } else { return redirect('user/profile'); } }