public function tags()
 {
     $message_to_show = "";
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $tag = new Tags();
         $tag_name = Input::get('tag_name');
         // OK
         if (!empty($tag_name)) {
             $is_tag_already_exist = $tag->check_tag($tag_name);
             if (!$is_tag_already_exist) {
                 $is_tag_inserted = $tag->insert_tag($tag_name);
                 if ($is_tag_inserted) {
                     $message_to_show = "Tag Inserted successfully";
                     return redirect("/admin/tags")->withMessage($message_to_show);
                 } else {
                     $message_to_show = "Tag Not Inserted, Try after some time";
                 }
             } else {
                 $message_to_show = "Tag already exist, insert any other tag";
             }
         } else {
             $message_to_show = "Complete info not given, please give all information";
         }
         return redirect("/admin/tags")->withMessage($message_to_show);
     } else {
         $tag = new Tags();
         $get_all_tags = $tag->get_all_tags();
         if (!empty($get_all_tags)) {
             $return_data = $get_all_tags;
         } else {
             $return_data = "No Tag Found";
         }
         return view('/admin/tags')->withTags($return_data);
     }
 }
 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);
     }
 }