public function testGetRankingSuccess() { $user_id = $this->_user_id; $_params = $this->_params; $_params['user_id'] = $user_id; $response = $this->_getAuth($_params); //get created login information $page = 1; $limit = 10; $user = Profile::orderBy('rate_count', 'desc')->forPage($page, $limit)->get(); if (count($user) != 0) { foreach ($user as $users) { $follow = Follow::where('from_id', $user_id)->where('to_id', $users->user_id)->first(); if ($follow) { $users->is_follow = true; } else { if ($users->user_id != $user_id) { $users->is_follow = false; } } if ($users->image != null) { $users->image = URL::asset($users->image); } } } $this->assertNotNull($user); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $user->toArray()), json_decode($response->getContent(), true)); }
private function getViewIndexDatas() { $current_user_id = Session::get('user')['id']; $owners_id = Follow::where('follower_id', $current_user_id)->where('is_deleted', 0)->get(['followed_id'])->toArray(); array_walk($owners_id, function (&$value, $key) { $value = $value['followed_id']; }); $owners_id[] = $current_user_id; // $privacy = Privacy::where('name',"Công khai")->get()->first(); $entries = Entry::whereIn('user_id', $owners_id)->where('privacy', 1)->orWhere('user_id', $current_user_id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page); $left_albums = Album::whereIn('user_id', $owners_id)->where('privacy', 1)->orWhere('user_id', $current_user_id)->orderBy('updated_at', 'DESC')->get(); // $datas = array(); // // foreach ($entries as $index => $entry) { // if (FEUsersHelper::isCurrentUser($entry->user_id)) { // if($this->getEntry($entry->entry_id, $entry->type, null)){ // $datas[] = $this->getEntry($entry->entry_id, $entry->type, null); // } // } else{ // if($this->getEntry($entry->entry_id, $entry->type, $privacy->id)){ // $datas[] = $this->getEntry($entry->entry_id, $entry->type, $privacy->id); // } // // } // } //// $datas = $this->pagination($datas, 3, $page); $suggests = FEUsersHelper::getSuggestes(); return array('datas' => $entries, 'suggestes' => $suggests, 'left_albums' => $left_albums); }
public function testGetListFollowSuccessNoFollow() { $follow = Follow::destroy(1); $response = $this->call('GET', 'api/follow'); $follow_infor = Follow::where('from_id', $this->_user_id)->get(); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $follow_infor->toArray()), json_decode($response->getContent(), true)); }
/** * Get following user list of current user * @return array Array of following user_id */ public function getFollowingUsersId() { $result = array(); $follows = Follow::where('follower_id', $this->id)->where('is_deleted', 0)->where('followed_id', '!=', $this->id)->get(); foreach ($follows as $follow) { $result[] = $follow->followed_id; } return $result; }
public function index() { $follower_id = Input::get('follower_id'); if (!$follower_id) { $follower_id = Session::get('user')['id']; } $follows = Follow::where('follower_id', $follower_id)->where('is_deleted', 0)->get(); return View::make('frontend/follows/index')->with('follows', $follows)->with('user', User::find($follower_id)); }
/** * Display customer profile * * @param $profile * @return Response */ public function show($profile) { $p = User::where('profile_url', '=', $profile)->where('approved', '=', '0')->first(); $page = Page::where('title', '=', 'faq-customer')->first(); $follow = Follow::where('user', $p->id)->where('hub', '=', 0)->get(); $follow_hub = Follow::where('user', $p->id)->where('artist', '=', 0)->get(); $wall = new \Illuminate\Database\Eloquent\Collection(); $events = new \Illuminate\Database\Eloquent\Collection(); $comments = Comment::where('user', '=', $p->id)->orderBy('created_at', 'desc')->get(); $hidden = unserialize(Cookie::get('hide')); //dd( Cookie::get('hide') ); if (count($follow) > 0) { foreach ($follow as $f) { $s = Song::where('artist', '=', $f->artist)->where('completed', '=', '1')->get(); $e = ArtistEvent::where('artist', '=', $f->artist)->where('date', '>', \Carbon\Carbon::now())->get(); $wall = $wall->merge($s); $events = $events->merge($e); } } if (count($follow_hub) > 0) { foreach ($follow_hub as $h) { $hub = Hub::where('id', '=', $h->hub)->first(); if (!is_null($hub)) { $artists = User::where('type', '=', 'artist')->where('hub', '=', $hub->id)->get(); $artists_list = []; $songs = []; $events = []; foreach ($artists as $a) { $artists_list[] = $a->id; } if (count($artists_list) > 0) { $songs = Song::where('completed', '=', '1')->whereIn('artist', $artists_list)->orderBy('created_at', 'desc')->get(); $events = ArtistEvent::whereIn('artist', $artists_list)->get(); } $news = News::where('hub', '=', $hub->id)->take(3)->get(); $wall = $wall->merge($songs); $events = $events->merge($events); } } } $purchased = Purchase::where('customer', '=', $p->id)->get(); foreach ($purchased as $pp) { $song_purchased = Song::withTrashed()->where('id', '=', $pp->song)->get(); $download = Download::where('customer', '=', $p->id)->where('song', '=', $pp->song)->first(); $song_purchased[0]->purchased = true; if (isset($download)) { $song_purchased[0]->link = $download->url; } $wall = $wall->merge($song_purchased); } $wall->sortByDesc('created_at'); if (!isset($news)) { $news = null; } return View::make('customer.profile-new', ['profile' => $p, 'wall' => $wall, 'page' => $page, 'events' => $events, 'comments' => $comments, 'hidden' => $hidden, 'news' => $news]); }
public function testGetTimelineSuccess() { $this->setUpRating(); $this->setUpCountry(); $this->setUpWineNote(); $this->setUpProfile(); $_params = $this->_params; $_params['user_id'] = "user_id"; $response = $this->_getAuth($_params); $error_code = ApiResponse::OK; $user_timeline = array(); $user_timeline[] = $this->_user_id; $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get(); if (isset($user_follow)) { foreach ($user_follow as $user) { $user_timeline[] = $user->to_id; } } $pagination = ApiResponse::pagination(); $page = $pagination['page']; $limit = $pagination['limit']; $wine = Wine::with('winery')->forPage($page, $limit)->get(); $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get(); foreach ($ratings as $rating) { $winery = Winery::where('id', $rating->wine->winery_id)->first(); $rating->winery = $winery; $country = Country::where('id', $rating->winery->country_id)->first(); $rating->winery->country_name = $country->country_name; $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first(); if ($like) { $rating->liked = true; } else { $rating->liked = false; } $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first(); if ($wishlist) { $rating->wishlist = true; } else { $rating->wishlist = false; } if ($rating->wine->image_url != null) { $rating->wine->image_url = URL::asset($rating->wine->image_url); } if ($rating->wine->wine_flag != null) { $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag); } if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } $rating->winery = $rating->winery->toArray(); } $data = $ratings; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true)); }
public static function getSuggestes() { $user_id = User::find(Session::get('user')['id'])->id; $following = Follow::where('follower_id', $user_id)->where('is_deleted', 0)->orderBy('updated_at', 'DESC')->get(); $suggestes = array(); foreach ($following as $follow) { $suggest_d = Follow::where('follower_id', $follow->followed->id)->where('followed_id', '!=', $user_id)->where('is_deleted', 0)->orderBy('updated_at', 'DESC')->get(); if ($suggest_d->count() > 0) { foreach ($suggest_d as $suggest) { $suggestes[] = $suggest; } } } return $suggestes; }
public function follow($slug) { $hub = Hub::where('slug', '=', $slug)->first(); $user = Auth::user(); if (!is_null($hub)) { $f = Follow::where('user', '=', $user->id)->where('hub', '=', $hub->id)->first(); if (is_null($f)) { $f = new Follow(); $f->hub = $hub->id; $f->user = $user->id; $f->save(); return Redirect::to('hubs/' . $hub->slug); } else { $f->delete(); return Redirect::to('hubs/' . $hub->slug); } } else { App::abort('404'); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $member = Member::find($id); $user = Auth::user(); $isMemberProfile = false; $isFollowing = false; if (Auth::check()) { if ($member->user_id == Auth::User()->id) { $isMemberProfile = true; } if (Follow::where('artist_id', $member->id)->where('user_id', $user->id)->count()) { $isFollowing = true; } } //if not an image url from facebook if (filter_var($member->user->avatar, FILTER_VALIDATE_URL) === FALSE) { $member->user->avatar = url('uploads/images/thumbnail/' . $member->user->avatar); } return view('pages.artist', ['artist' => $member, 'isArtistProfile' => $isMemberProfile, 'isFollowing' => $isFollowing]); }
public function getNewPostsNotification($current_user_id, $last_time) { $followed_users = Follow::where('follower_id', '=', $current_user_id)->select('followed_id')->get(); $new_posts = Post::whereIn('user_id', $followed_users->fetch('followed_id')->toArray())->where('privacy', 1)->where('created_at', '>=', $last_time)->get(); return $new_posts ? $new_posts : array(); }
public function testGetFriend_FbUserSuccess() { $data = array(); $user_id = $this->_user_id; $_params = $this->_params; $_params['user_id'] = $user_id; $this->_uri = 'api/user/friend_fb'; $response = $this->_getAuth($_params['input']); $input = $_params['input']; //get created login information foreach ($input as $fb_id) { $user = User::where('fb_id', $fb_id)->with('profile')->first(); if ($user && $user->user_id != $user_id) { $follow = Follow::where('from_id', $user_id)->where('to_id', $user->user_id)->first(); if ($follow) { $user->is_follow = true; } else { $user->is_follow = false; } if ($user->image != null) { $user->image = URL::asset($users->image); } $data[] = $user->toArray(); } } $this->assertNotNull($data); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true)); }
public static function getProfileBasicUser($user_id) { $error_code = ApiResponse::OK; $user_login = Session::get('user_id'); if (User::where('user_id', $user_id)->first()) { $users = Profile::orderBy('rate_count', 'desc')->get(); $i = 0; if ($users) { foreach ($users as $key) { $i++; if ($key['user_id'] == $user_id) { break; } } } $profile = Profile::where('user_id', $user_id)->first(); if ($profile->image != null) { $profile->image = URL::asset($profile->image); } if ($profile->country_id != null) { $country = Country::where('id', $profile->country_id)->first(); $profile->country_name = $country->country_name; $profile->country_flag = URL::asset($country->flag_url); } $wishlists = Wishlist::where('user_id', $user_id)->get(); if ($wishlists) { $profile->wishlist_count = count($wishlists); } else { $profile->wishlist_count = 0; } if ($user_id != $user_login) { $follow = Follow::where('from_id', $user_login)->where('to_id', $user_id)->first(); if ($follow) { $profile->is_follow = true; } else { $profile->is_follow = false; } } $profile->user_ranking = $i; $data = $profile->toArray(); } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } return array("code" => $error_code, "data" => $data); }
public function testGetWineDetailNoWineNote() { $this->setUpRating(); $this->setUpCountry(); $this->setUpProfile(); $wine_note = Winenote::destroy(1); $response = $this->call('GET', 'api/wine/1'); $wine_infor = Wine::where('wine_id', 1)->with('winery')->first(); $wine_infor->total_like = 0; $country_name = Country::where('id', $wine_infor->winery->country_id)->first()->country_name; $wine_infor->winenote = null; $wine_infor->winery->country_id = $country_name; if ($wine_infor->wine_type != null) { $wine_infor->wine_type = Wine::getWineType($wine_infor->wine_type); } $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $wine_infor->wine_unique_id)->first(); if ($wishlist) { $wine_infor->is_wishlist = true; } else { $wine_infor->is_wishlist = false; } $all_wines_winery = Wine::where('winery_id', $wine_infor->winery_id)->whereNotIn('wine_id', [1])->take(10)->get(); $wine_infor->winery->count_wine = count($all_wines_winery) + 1; $rate_winery = $wine_infor->rate_count; if (count($all_wines_winery) !== 0) { $sum_rate_winery = $wine_infor->average_rate; foreach ($all_wines_winery as $wine_winery) { $wine_on_winery = Wine::where('wine_id', $wine_winery->wine_id)->first(); $rate_count = $wine_on_winery->rate_count; $rate_winery = $rate_winery + $rate_count; $average_rate = $wine_on_winery->average_rate; $sum_rate_winery = $sum_rate_winery + $average_rate; } $wine_infor->winery->total_rate = $rate_winery; $wine_inforine->winery->average_rate_winery = $sum_rate_winery / count($all_wines_winery); } else { $wine_infor->winery->total_rate = $rate_winery; $wine_infor->winery->average_rate_winery = $wine_infor->average_rate; } $rating_user = Rating::where('wine_unique_id', $wine_infor->wine_unique_id)->where('user_id', $this->_user_id)->with('profile')->first(); if ($rating_user->profile->image != null) { $rating_user->profile->image = URL::asset($rating_user->profile->image); } $wine_infor->total_like = $wine_infor->total_like + $rating_user->like_count; $rating = Rating::where('wine_unique_id', $wine_infor->wine_unique_id)->whereNotIn('user_id', [$this->_user_id])->with('profile')->get(); if (count($rating) == 0) { $rating = array(); } else { foreach ($rating as $ratings) { if ($ratings->profile->image != null) { $ratings->profile->image = URL::asset($ratings->profile->image); } $follow = Follow::where('from_id', $this->_user_id)->where('to_id', $ratings->user_id)->first(); if ($follow) { $ratings->is_follow = true; } else { $ratings->is_follow = false; } $wine_infor->total_like = $wine_infor->total_like + $ratings->like_count; } } if ($wine_infor->image_url != null) { $wine_infor->image_url = URL::asset($wine_infor->image_url); } if ($wine_infor->wine_flag != null) { $wine_infor->wine_flag = URL::asset($wine_infor->wine_flag); } $data = array('wine' => $wine_infor->toArray(), 'rate_user' => $rating_user->toArray(), 'rate' => $rating->toArray(), 'wine_related' => $all_wines_winery->toArray()); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true)); }
public static function getListFollowing($user_id) { $error_code = ApiResponse::OK; $data = array(); if (User::where('user_id', $user_id)) { $pagination = ApiResponse::pagination(); if ($pagination == false) { $error_code = ApiResponse::URL_NOT_EXIST; $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST); } else { $page = $pagination['page']; $limit = $pagination['limit']; $users_followers = Follow::where('from_id', $user_id)->forPage($page, $limit)->get(); if ($users_followers) { foreach ($users_followers as $user_follower) { $user = Profile::where('user_id', $user_follower->to_id)->first(); if ($user) { if ($user->image != null) { $user->image = URL::asset($user->image); } $user_follower = $user; $data[] = $user_follower; } } } } } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } return array("code" => $error_code, "data" => $data); }
public static function countFollower($id) { return Follow::where('followed_id', $id)->where('is_deleted', 0)->get()->count(); }
public static function ranking() { $user_id = Session::get('user_id'); $error_code = ApiResponse::OK; $data = array(); $pagination = ApiResponse::pagination(); if ($pagination == false) { $error_code = ApiResponse::URL_NOT_EXIST; $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST); } else { $page = $pagination['page']; $limit = $pagination['limit']; $users = Profile::orderBy('rate_count', 'desc')->forPage($page, $limit)->get(); if (count($users) != 0) { foreach ($users as $user) { $follow = Follow::where('from_id', $user_id)->where('to_id', $user->user_id)->first(); if ($follow) { $user->is_follow = true; } else { if ($user->user_id != $user_id) { $user->is_follow = false; } } if ($user->image != null) { $user->image = URL::asset($user->image); } } $data = $users->toArray(); } } return array("code" => $error_code, "data" => $data); }
public function follow($artist) { $artist = User::where('profile_url', '=', $artist)->first(); $user = Auth::user(); if (!is_null($artist)) { $f = Follow::where('user', '=', $user->id)->where('artist', '=', $artist->id)->first(); if (is_null($f)) { $f = new Follow(); $f->artist = $artist->id; $f->user = $user->id; $f->save(); return Redirect::to('artist/' . $artist->profile_url); } else { $f->delete(); return Redirect::to('artist/' . $artist->profile_url); } } else { App::abort('404'); } }
public function testGetProfileBasicSuccessOtherUser() { $user_id = $this->_user_id; $other_user = User::where('email', '*****@*****.**')->first()->user_id; $response = $this->action('GET', 'ProfileController@get_profile_basic_user', array('user_id' => $other_user)); $profile = Profile::where('user_id', $other_user)->first(); if (User::where('user_id', $other_user)->first()) { $users = Profile::orderBy('rate_count', 'desc')->get(); $i = 0; if ($users) { foreach ($users as $key) { $i++; if ($key['user_id'] == $other_user) { break; } } } } $profile->user_ranking = $i; if ($profile->image != null) { $profile->image = URL::asset($profile->image); } $wishlist = Wishlist::where('user_id', $user_id)->get(); $profile->wishlist_count = count($wishlist); $follow = Follow::where('from_id', $user_id)->where('to_id', $other_user)->first(); if ($follow) { $profile->is_follow = true; } else { $profile->is_follow = false; } $data = $profile; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->toArray()), json_decode($response->getContent(), true)); }
public function followersPages($id) { return ceil(Follow::where('follow_id', $id)->count() / 10); }
public static function getActivity() { $user_id = Session::get('user_id'); $error_code = ApiResponse::OK; $act = array(); $ratings = Rating::where('user_id', $user_id)->get(); foreach ($ratings as $rating) { $likes = Like::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get(); if ($likes) { $title = 'like'; foreach ($likes as $like) { $act[] = Rating::getProfile($like->user_id, $title, $like->id, $rating->id, $like->updated_at); } } $comments = Comment::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get(); if ($comments) { $title = 'comment'; foreach ($comments as $comment) { $act[] = Rating::getProfile($comment->user_id, $title, $comment->id, $rating->id, $comment->updated_at); } } $wishlists = Wishlist::where('wine_unique_id', $rating->wine_unique_id)->whereNotIn('user_id', [$user_id])->get(); if ($wishlists) { $title = 'wishlist'; foreach ($wishlists as $wishlist) { $act[] = Rating::getProfile($wishlist->user_id, $title, $wishlist->id, $rating->id, $wishlist->updated_at); } } } $user_follow = Follow::where('to_id', $user_id)->get(); if ($user_follow) { $title = 'follow'; foreach ($user_follow as $user) { $act[] = Rating::getProfile($user->from_id, $title, $user->id, null, $user->updated_at); } } $data = Rating::orderBy($act, 'updated_at'); return array("code" => $error_code, "data" => $data); }
public static function getWineDetail($wine_id) { $user_id = Session::get('user_id'); $wine = Wine::where('wine_id', $wine_id)->with('winery')->first(); $error_code = ApiResponse::OK; if ($wine) { if ($wine->wine_type != null) { $wine->wine_type = Wine::getWineType($wine->wine_type); } $wine->image_url = Wine::getImageWineFromServer($user_id, $wine->wine_unique_id, $wine->image_url); if ($wine->wine_flag != null) { $wine->wine_flag = URL::asset($wine->wine_flag); } $country = Country::where('id', $wine->winery->country_id)->first(); if ($country) { $wine->winery->country_id = $country->country_name; } else { $wine->winery->country_id = null; } $wine_note = Winenote::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->first(); if ($wine_note) { $wine->winenote = $wine_note->note; } else { $wine->winenote = null; } $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wine->wine_unique_id)->first(); if ($wishlist) { $wine->is_wishlist = true; } else { $wine->is_wishlist = false; } $all_wines_winery = Wine::where('winery_id', $wine->winery_id)->whereNotIn('wine_id', [$wine_id])->where('year', '>', 0)->where('average_rate', '>', 0)->orderBy('year', 'desc')->take(10)->get(); $wine->winery->count_wine = count($all_wines_winery) + 1; $rate_winery = $wine->rate_count; if (count($all_wines_winery) !== 0) { $sum_rate_winery = $wine->average_rate; foreach ($all_wines_winery as $wine_winery) { $wine_on_winery = Wine::where('wine_id', $wine_winery->wine_id)->first(); $wine_on_winery->image_url = Wine::getImageWineFromServer($user_id, $wine_on_winery->wine_unique_id, $wine_on_winery->image_url); $rate_count = $wine_on_winery->rate_count; $rate_winery = $rate_winery + $rate_count; $average_rate = $wine_on_winery->average_rate; $sum_rate_winery = $sum_rate_winery + $average_rate; } $wine->winery->total_rate = $rate_winery; $wine->winery->average_rate_winery = $sum_rate_winery / count($all_wines_winery); } else { $wine->winery->total_rate = $rate_winery; $wine->winery->average_rate_winery = $wine->average_rate; } $wine->total_like = 0; $rating_user = Rating::where('wine_unique_id', $wine->wine_unique_id)->where('user_id', $user_id)->with('profile')->first(); if (count($rating_user) == 0) { $rating_user = null; } else { if ($rating_user->profile->image != null) { $rating_user->profile->image = URL::asset($rating_user->profile->image); } $wine->total_like = $wine->total_like + $rating_user->like_count; } $ratings = Rating::where('wine_unique_id', $wine->wine_unique_id)->whereNotIn('user_id', [$user_id])->with('profile')->get(); if (count($ratings) == 0) { $ratings = array(); } else { foreach ($ratings as $rating) { if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } $follow = Follow::where('from_id', $user_id)->where('to_id', $rating->user_id)->first(); if ($follow) { $rating->is_follow = true; } else { $rating->is_follow = false; } $wine->total_like = $wine->total_like + $rating->like_count; } } $data = array('wine' => $wine, 'rate_user' => $rating_user, 'rate' => $ratings, 'wine_related' => $all_wines_winery); } else { $error_code = ApiResponse::UNAVAILABLE_WINE; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE); } return array("code" => $error_code, "data" => $data); }