Пример #1
0
 public function post_question()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $root_cat_id = Input::get('root');
         // OK
         $child_cat_id = Input::get('child');
         // OK
         $sub_cat_id = Input::get('sub');
         // OK
         $question_content = Input::get('question_content');
         // OK
         $tags = Input::get('tags');
         // 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;
         }
         $tags_array = array();
         if (!empty($tags)) {
             foreach ($tags as $tag) {
                 array_push($tags_array, $tag);
             }
         }
         $tag_obj = new Tags();
         $get_tags_info = $tag_obj->get_tags_ids($tags_array);
         $tags_ids = array();
         if (!empty($get_tags_info)) {
             foreach ($get_tags_info as $tag_info) {
                 array_push($tags_ids, $tag_info['id']);
             }
         }
         $user = new User();
         $get_user_data = $user->get_user_profile_data();
         $user_id = $get_user_data['id'];
         $question = new Questions();
         $is_question_posted = $question->post_question($user_id, $cat_id, $question_content);
         if ($is_question_posted) {
             $question_id = $is_question_posted['id'];
         }
         $question_tag = new Question_Tag();
         $insert_question_tag_data = $question_tag->insert_question_tag_data($question_id, $tags_ids);
         if ($insert_question_tag_data) {
             return redirect("/");
         } else {
             return redirect("user/profile");
         }
     } else {
         $cat = new Category();
         $root_category = array();
         $all_tags = array();
         $root_categories = $cat->get_categories_by_parent_id(0);
         foreach ($root_categories as $category) {
             array_push($root_category, $category['title']);
         }
         $tag = new Tags();
         $get_all_tags = $tag->get_all_tags();
         if (!empty($get_all_tags)) {
             $all_tags = $get_all_tags;
         }
         return view('user/post_question')->withRootCategories($root_categories)->withTags($all_tags);
     }
 }