コード例 #1
0
 public function control($sUserName)
 {
     switch ($sUserName) {
         case 'logout':
             return redirect('user/logout');
         case 'characters':
             return redirect('character/index');
         case 'users':
             return redirect('user/index');
         default:
             $oUser = User::where('user_name', $sUserName)->first();
             if ($oUser == null) {
                 dd("ALALALHJ!");
             } else {
                 $aLoggedInUser = null;
                 $bOwner = false;
                 $oMate = null;
                 $bLoggedInUser = Session::has('user');
                 if ($bLoggedInUser) {
                     if ($oUser->toArray()['id'] == Session::get('user')['id']) {
                         $bOwner = true;
                     }
                     $aLoggedInUser['user'] = User::where('id', Session::get('user')['id'])->first()->toArray();
                     $aLoggedInUser['current_character'] = Character::where('id', $aLoggedInUser['user']['current_character_id'])->first()->toArray();
                 }
                 $aUser['user'] = $oUser->toArray();
                 $aUser['current_character'] = Character::where('id', $aUser['user']['current_character_id'])->first()->toArray();
                 $aUser['active_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DEFAULT)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_ADMIN)->get()->toArray();
                 $aUser['inactive_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DISABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_INACTIVE)->get()->toArray();
                 $aUser['user_settings'] = UserSetting::where('user_id', $oUser->toArray()['id'])->first()->toArray();
                 $aUser['current_photo'] = Photo::where('id', $aUser['user']['photo_id'])->first()->toArray();
                 //Mates
                 $bRequestedFromLoggedInUser = false;
                 if ($bLoggedInUser) {
                     $sSql = 'SELECT * from mates where ((from_user_id = ' . $aUser['user']['id'] . ' AND to_user_id = ' . Session::get('user')['id'] . ') OR (from_user_id = ' . Session::get('user')['id'] . ' AND to_user_id = ' . $aUser['user']['id'] . ')) AND (status = ' . Mate::MATE_STATUS_ADDED_BY_USER . ' OR status <> ' . Mate::MATE_STATUS_ADDED_BY_ADMIN . ')';
                     $oMate = DB::select($sSql);
                     $oMate = Mate::where('from_user_id', $aUser['user']['id'])->orWhere('to_user_id', Session::get('user')['id'])->orWhere(function ($query) {
                         $query->where('status', Mate::MATE_STATUS_ADDED_BY_ADMIN)->where('status', Mate::MATE_STATUS_ADDED_BY_ADMIN);
                     })->orderBy('id', 'desc')->first();
                 }
                 $aUser['mate'] = is_null($oMate) || empty($oMate) ? NULL : $oMate->toArray();
                 if ($aUser['mate']['from_user_id'] == Session::get('user')['id']) {
                     $bRequestedFromLoggedInUser = true;
                 }
                 //End of mate
                 //Likes
                 $oUserUserLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aUser['user']['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
                 $aUser['user']['likers'] = $oUserUserLikers ? $oUserUserLikers->toArray() : [];
                 $aUser['user']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['user']['likers'], $aLoggedInUser['user']['id']);
                 $oCurrentCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['user']['current_character_id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
                 $aUser['current_character']['likers'] = $oCurrentCharacterLikers ? $oCurrentCharacterLikers->toArray() : [];
                 $aUser['current_character']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['current_character']['likers'], $aLoggedInUser['user']['id']);
                 for ($i = 0; $i < count($aUser['active_characters']); $i++) {
                     $aActiveCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['active_characters'][$i]['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
                     $aUser['active_characters'][$i]['likers'] = $aActiveCharacterLikers ? $aActiveCharacterLikers->toArray() : [];
                     $aUser['active_characters'][$i]['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['active_characters'][$i]['likers'], $aLoggedInUser['user']['id']);
                 }
                 for ($i = 0; $i < count($aUser['inactive_characters']); $i++) {
                     $aInActiveCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['inactive_characters'][$i]['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
                     $aUser['inactive_characters'][$i]['likers'] = $aInActiveCharacterLikers ? $aInActiveCharacterLikers->toArray() : [];
                     $aUser['inactive_characters'][$i]['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['inactive_characters'][$i]['likers'], $aLoggedInUser['user']['id']);
                 }
                 $oCurrentPhotoLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_PHOTO)->where('photo_id', $aUser['current_photo']['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
                 $aUser['current_photo']['likers'] = $oCurrentPhotoLikers ? $oCurrentPhotoLikers->toArray() : [];
                 $aUser['current_photo']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['current_photo']['likers'], $aLoggedInUser['user']['id']);
                 //dd($aUser);
                 $aFamilies = Family::where('status', Family::FAMILY_STATUS_DEFAULT)->get()->toArray();
                 $aSpecies = Specy::where('status', Specy::SPECY_STATUS_DEFAULT)->get()->toArray();
                 return view('users.users.profile')->with('aLoggedInUser', is_array($aLoggedInUser) ? $aLoggedInUser : null)->with('aUser', $aUser)->with('bOwner', $bOwner)->with('bRequestedFromLoggedInUser', $bRequestedFromLoggedInUser)->with('bLoggedInUser', $bLoggedInUser)->with('aSpecies', $aSpecies)->with('aFamilies', $aFamilies);
             }
     }
 }
コード例 #2
0
 function get_comments_by_photo_id()
 {
     $iFromType = Input::get('from_type');
     $iFromID = Input::get('from_id');
     $aLoggedInUser = User::where('id', Session::get('user')['id'])->first()->toArray();
     switch ($iFromType) {
         case Comment::COMMENT_FROM_TYPE_USER:
             $aFromItem = User::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_CHARACTER:
             $aFromItem = Character::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('character_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_FAMILY:
             $aFromItem = Family::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_FAMILY)->where('family_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('family_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_SPECY:
             $aFromItem = Specy::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_SPECY)->where('specy_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('specy_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_PHOTO:
             $aFromItem = Photo::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_PHOTO)->where('photo_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('photo_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_POST:
             $aFromItem = Post::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_POST)->where('post_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('post_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         case Comment::COMMENT_FROM_TYPE_MATE:
             $aFromItem = Mate::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_MATE)->where('mate_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('mate_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
         default:
             $aFromItem = User::where('id', $iFromID)->first()->toArray();
             $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get();
             $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : [];
             $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']);
             $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get();
             break;
     }
     $oComments = is_array($oComments->toArray()) && count($oComments->toArray() > 0) ? $oComments->toArray() : [];
     $aComments = null;
     $iFromWhereID = null;
     for ($i = 0; $i < count($oComments); $i++) {
         $aComments[$i] = $oComments[$i];
         $aComments[$i]['from_user'] = User::where('id', $oComments[$i]['from_user_id'])->first()->toArray();
         if ($oComments[$i]['comment_photo_id'] > 0) {
             $aComments[$i]['photo_comment'] = Photo::where('id', $oComments[$i]['comment_photo_id'])->first()->toArray();
         }
         $iFromType = $oComments[$i]['comment_from_type'];
         switch ($iFromType) {
             case Comment::COMMENT_FROM_TYPE_USER:
                 $iFromWhereID = "user_id";
                 $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_CHARACTER:
                 $iFromWhereID = "character_id";
                 $aComments[$i]['from'] = Character::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_FAMILY:
                 $iFromWhereID = "family_id";
                 $aComments[$i]['from'] = Family::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_SPECY:
                 $iFromWhereID = "specy_id";
                 $aComments[$i]['from'] = Specy::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_PHOTO:
                 $iFromWhereID = "photo_id";
                 $aComments[$i]['from'] = Photo::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_POST:
                 $iFromWhereID = "post_id";
                 $aComments[$i]['from'] = Post::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             case Comment::COMMENT_FROM_TYPE_MATE:
                 $iFromWhereID = "mate_id";
                 $aComments[$i]['from'] = Mate::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
             default:
                 $iFromWhereID = "user_id";
                 $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray();
                 break;
         }
     }
     $view = view('users.comments.show')->with('aComments', $aComments);
     $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType);
     if ($oComments) {
         return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]);
     } else {
         $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType);
         $view = view('users.comments.show')->with('aComments', []);
         if ($htmlFromWhatView != "") {
             return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]);
         } else {
             echo json_encode(array('status' => false, 'message' => "Something went wrong. Please try again later"));
         }
     }
     die;
 }