public function addToList() { $messages = ['required' => 'The :attribute field is required.', 'numeric' => 'The :attribute field is required.']; $input = Input::all(); $validator = Validator::make($input, ['list_id' => 'required|numeric', 'profile_id' => 'required|numeric'], $messages); if ($validator->fails()) { return ['error' => $validator->errors()->all()[0]]; } $userListProfile = UserListProfile::where('user_list_id', (int) $input['list_id'])->get(); if (Auth::user()->unlockUser() <= $userListProfile->count()) { return ['error' => 'You have reached the maximum users in a list']; } $userListProfile = $userListProfile->where('profile_id', (int) $input['profile_id'])->where('deleted_at', null)->first(); if (isset($userListProfile->id)) { return ['error' => 'This user already exists on the list!']; } $profile = Profile::where('id', (int) $input['profile_id'])->first(); $userListProfile = new UserListProfile(); $userListProfile->user_list_id = $input['list_id']; $userListProfile->profile_id = $input['profile_id']; $userListProfile->profile_name = $profile->display_name; $userListProfile->profile_description = $input['description']; if (!$userListProfile->save()) { return ['error' => 'There was an error trying to add user to list.']; } $customList = new CustomList(UserList::where('id', $input['list_id'])->first()); if ($customList->error()) { return $customList->error(); } return $customList->getCustomList(); }
private function grabFromDB() { $profile = Profile::where('profile.small_id', $this->smallId)->leftjoin('profile_ban', 'profile.id', '=', 'profile_ban.profile_id')->leftjoin('users', 'profile.small_id', '=', 'users.small_id')->first(['profile.id', 'profile.display_name', 'profile.avatar', 'profile.avatar_thumb', 'profile.small_id', 'profile.profile_created', 'profile.privacy', 'profile.alias', 'profile.created_at', 'profile_ban.vac', 'profile_ban.vac_banned_on', 'profile_ban.community', 'profile_ban.trade', 'users.site_admin', 'users.donation', 'users.beta']); /* Copied and pasted from function above */ $profileOldAlias = $profile->ProfileOldAlias()->whereProfileId($profile->id)->orderBy('id', 'desc')->get(); $gettingCount = UserListProfile::whereProfileId($profile->id)->orderBy('id', 'desc')->whereNull('deleted_at')->get(); $profileTimesAdded = ['number' => $gettingCount->count(), 'time' => isset($gettingCount[0]) ? (new DateTime($gettingCount[0]->created_at))->format("M j Y") : null]; $profileCheckCache = "profile_checked_"; $currentProfileCheck = ['number' => 0, 'time' => date("M j Y", time())]; if (Cache::has($profileCheckCache . $this->smallId)) { $currentProfileCheck = Cache::get($profileCheckCache . $this->smallId); } $newProfileCheck = ['number' => $currentProfileCheck['number'] + 1, 'time' => date("M j Y", time())]; Cache::forever($profileCheckCache . $this->smallId, $newProfileCheck); /* WOW THAT WAS SHORT!!!!! */ $steam64BitId = Steam::to64Bit($profile->small_id); $oldAliasArray = []; foreach ($profileOldAlias as $k => $oldAlias) { $oldAliasArray[] = ["newname" => $oldAlias->seen_alias, "timechanged" => $oldAlias->seen->format("M j Y")]; } $return = ['id' => $profile->id, 'display_name' => $profile->display_name, 'avatar' => $profile->avatar, 'small_id' => $profile->small_id, 'steam_64_bit' => $steam64BitId, 'steam_32_bit' => Steam::to32Bit($steam64BitId), 'profile_created' => isset($profile->profile_created) ? date("M j Y", $profile->profile_created) : "Unknown", 'privacy' => $profile->privacy, 'alias' => Steam::friendlyAlias(json_decode($profile->alias)), 'created_at' => $profile->created_at->format("M j Y"), 'vac' => $profile->vac, 'vac_banned_on' => $profile->vac_banned_on->format("M j Y"), 'community' => $profile->community, 'trade' => $profile->trade, 'site_admin' => (int) $profile->site_admin ?: 0, 'donation' => (int) $profile->donation ?: 0, 'beta' => (int) $profile->beta ?: 0, 'profile_old_alias' => $oldAliasArray, 'times_checked' => $currentProfileCheck, 'times_added' => $profileTimesAdded]; return $return; }