public function getCustomList() { if ($this->error()) { return $this->error(); } $userList = $this->userList; $userListProfiles = UserList::where('user_list.id', $userList->id)->leftjoin('user_list_profile as ulp_1', 'ulp_1.user_list_id', '=', 'user_list.id')->whereNull('ulp_1.deleted_at')->leftJoin('user_list_profile as ulp_2', function ($join) { $join->on('ulp_2.profile_id', '=', 'ulp_1.profile_id')->whereNull('ulp_2.deleted_at'); })->leftjoin('profile', 'ulp_1.profile_id', '=', 'profile.id')->leftjoin('profile_ban', 'profile.id', '=', 'profile_ban.profile_id')->leftjoin('users', 'profile.small_id', '=', 'users.small_id')->leftJoin('subscription', function ($join) { $join->on('subscription.user_list_id', '=', 'user_list.id')->whereNull('subscription.deleted_at'); })->groupBy('profile.id')->orderBy('ulp_1.id', 'desc')->get(['ulp_1.profile_name', 'ulp_1.profile_description', 'profile.id', 'profile.display_name', 'profile.avatar_thumb', 'profile.small_id', 'profile_ban.vac', 'profile_ban.vac_banned_on', 'profile_ban.community', 'profile_ban.trade', 'users.site_admin', 'users.donation', 'users.beta', \DB::raw('max(ulp_1.created_at) as created_at'), \DB::raw('count(ulp_2.profile_id) as total'), \DB::raw('count(distinct subscription.id) as sub_count')]); $canSub = false; $subscription = null; if (Auth::check()) { $user = Auth::user(); $userMail = $user->UserMail; $subscription = $user->Subscription->where('user_list_id', $userList->id)->first(); if ($userMail && ($userMail->verify == "verified" || $userMail->pushbullet_verify == "verified")) { $canSub = true; } } $return = ['id' => $userList->id, 'title' => $userList->title, 'author' => $userList->user->display_name, 'my_list' => $this->myList(), 'can_sub' => $canSub, 'subscription' => $subscription, 'privacy' => $userList->privacy, 'sub_count' => isset($userListProfiles[0]) ? $userListProfiles[0]->sub_count : 0, 'list' => []]; foreach ($userListProfiles as $userListProfile) { if (is_null($userListProfile->id)) { continue; } $vacBanDate = new DateTime($userListProfile->vac_banned_on); $return['list'][] = ['id' => $userListProfile->id, 'display_name' => $userListProfile->profile_name ?: $userListProfile->display_name, 'avatar_thumb' => $userListProfile->avatar_thumb, 'small_id' => $userListProfile->small_id, 'steam_64_bit' => Steam::to64Bit($userListProfile->small_id), 'vac' => $userListProfile->vac, 'vac_banned_on' => $vacBanDate->format("M j Y"), 'community' => $userListProfile->community, 'trade' => $userListProfile->trade, 'site_admin' => (int) $userListProfile->site_admin ?: 0, 'donation' => (int) $userListProfile->donation ?: 0, 'beta' => (int) $userListProfile->beta ?: 0, 'profile_description' => $userListProfile->profile_description, 'times_added' => ['number' => $userListProfile->total, 'time' => (new DateTime($userListProfile->created_at))->format("M j Y")]]; } $multiProfile = new MultiProfile($return['list']); $return['list'] = $multiProfile->run(); return $return; }
public function subscribeIndex() { $user = Auth::User(); $userMail = $user->UserMail; $subscription = $user->Subscription()->get(['user_list_id']); $userListIds = []; foreach ($subscription as $getId) { $userListIds[] = $getId->user_list_id; } $userLists = UserList::whereIn('user_list.id', $userListIds)->leftjoin('users', 'users.id', '=', 'user_list.user_id')->whereNull('deleted_at')->get(['user_list.id', 'user_list.title', 'users.display_name', 'users.site_admin', 'users.donation', 'users.beta']); return compact('userMail', 'userLists'); }
public function deleteCustomList(UserList $userList) { if ($userList->user_id !== Auth::user()->id) { return ['error' => 'forbidden']; } $userList->UserListProfile()->delete(); if (!$userList->delete()) { return ['error' => 'There was an error trying to delete the list']; } return [true]; }
public function addManyToList() { $input = Input::all(); $search = Steam::parseSearch($input['search']); $description = isset($input['description']) && !empty($input['description']) ? $input['description'] : null; if (!is_array($search)) { return ['error' => 'Invalid Search Option']; } $validProfile = array(); $invalidProfile = array(); foreach ($search as $potentialProfile) { $steam3Id = Steam::findUser($potentialProfile); if (isset($steam3Id['error'])) { $invalidProfile[] = $potentialProfile; } else { $validProfile[] = $steam3Id['success']; } } $smallIds = Steam::toSmallId($validProfile); $profiles = Profile::whereIn('small_id', $smallIds)->get(['small_id']); $profilesParsed = []; foreach ($smallIds as $smallId) { $profile = $profiles->where('small_id', $smallId)->first(); if (is_null($profile)) { $profilesParsed[] = ['small_id' => $smallId]; continue; } } $multiProfile = new MultiProfile($profilesParsed); $multiProfile->run(); $listId = (int) $input['list_id']; $userList = UserList::where('id', $listId)->first(); $userListProfiles = UserListProfile::whereIn('profile.small_id', $smallIds)->leftjoin('profile', 'profile.id', '=', 'user_list_profile.profile_id')->where('user_list_profile.user_list_id', $listId)->where('user_list_profile.deleted_at', null)->get(['profile.small_id', 'profile.id']); $userListProfilesSmallId = []; foreach ($userListProfiles as $userListProfile) { $userListProfilesSmallId[] = $userListProfile->small_id; } $smallIds = array_diff($smallIds, $userListProfilesSmallId); $profiles = Profile::whereIn('small_id', $smallIds)->get(); $toAddtoList = []; foreach ($profiles as $k => $profile) { if (Auth::user()->unlockUser() <= $userList->UserListProfile()->count() + $k) { break; } $toAddtoList[] = new UserListProfile(["profile_id" => $profile->id, "profile_name" => $profile->display_name, "profile_description" => $description]); } $userList->UserListProfile()->saveMany($toAddtoList); $customList = new CustomList(UserList::where('id', $listId)->first()); if ($customList->error()) { return $customList->error(); } return $customList->getCustomList(); }