Ejemplo n.º 1
0
 public static function editPost($input)
 {
     $validation = Validator::make($input, Posts::$editPostRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $title = $input['title'];
         $post_id = $input['post_id'];
         $skillset = $input['skillset'];
         $post_desc = isset($input['post_desc']) ? $input['post_desc'] : "";
         $post_image = Input::file('post_image');
         $post_video = Input::file('post_video');
         $current_time = new DateTime();
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             $post_data = DB::table('posts')->select('*')->where('title', $title)->where('user_id', $user_id)->first();
             if ($post_data) {
                 if ($post_image == "") {
                     $image = "";
                 } else {
                     $image = Users::uploadPostFiles('post_image');
                 }
                 if ($post_video == "") {
                     $video = "";
                 } else {
                     $video = Users::uploadPostFiles('post_video');
                 }
                 if ($video) {
                     DB::table('posts')->where('user_id', $user_id)->where('id', $post_id)->update(['title' => $title, 'post_desc' => $post_desc, 'post_image' => $image, 'post_video' => $video]);
                 } else {
                     DB::table('posts')->where('id', $post_id)->where('user_id', $user_id)->update(['title' => $title, 'post_desc' => $post_desc, 'post_image' => $image]);
                 }
                 if ($skillset) {
                     $set = "";
                     foreach ($skillset as $key => $val) {
                         $m = str_replace(' ', '', $val);
                         $set .= '"' . $m . '",';
                     }
                     $num = rtrim($set, ', ');
                     DB::table('post_skillset')->select('*')->where('user_id', $user_id)->where('post_id', $post_id)->whereRaw('skillset_id NOT IN' . '(' . $num . ')')->delete();
                     foreach ($skillset as $key => $value) {
                         $skill[$key] = DB::table('post_skillset')->select('*')->where('post_id', $post_id)->where('user_id', $user_id)->where('skillset_id', $value)->get();
                         if (!$skill[$key]) {
                             $post_skill = DB::table('post_skillset')->insertGetId(array('user_id' => $user_id, 'post_id' => $post_id, 'skillset_id' => $value, 'created_at' => $current_time));
                         }
                     }
                 }
                 return Response::json(array('status' => '1', 'msg' => 'Post Updated'), 200);
             } else {
                 return Response::json(array('status' => '2', 'msg' => 'Post doesnot exists'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }
Ejemplo n.º 2
0
 public static function editVideo($input)
 {
     $validation = Validator::make($input, Users::$editVideoRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $profile_thumb = Input::file('profile_thumb');
         $profile_video = Input::file('profile_video');
         $current_time = new DateTime();
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             if ($profile_video == "") {
                 $video = "";
                 $thumb = "";
             } else {
                 $video = Users::uploadPostFiles('profile_video');
                 $thumb = Users::uploadPostFiles('profile_thumb');
             }
             if ($video) {
                 DB::table('users')->where('id', $user_id)->update(['profile_thumb' => $thumb, 'profile_video' => $video]);
             }
             $profile_setup_status = Users::ProfileSetupStatus($user_id);
             return Response::json(array('status' => '1', 'msg' => 'User Profile Updated', 'profile_complete_status' => $profile_setup_status), 200);
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }