本文整理汇总了PHP中Rating::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::whereIn方法的具体用法?PHP Rating::whereIn怎么用?PHP Rating::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::whereIn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: timeline
public static function timeline()
{
$user_id = Session::get('user_id');
$error_code = ApiResponse::OK;
$user_timeline = array();
$user_timeline[] = $user_id;
$user_follow = Follow::where('from_id', $user_id)->orderBy('updated_at', 'asc')->get();
if (isset($user_follow)) {
foreach ($user_follow as $user) {
$user_timeline[] = $user->to_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'];
$ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->orderBy('updated_at', 'desc')->forPage($page, $limit)->get();
if (count($ratings) == 0) {
$data = array();
} else {
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();
if ($country) {
$rating->winery->country_name = $country->country_name;
} else {
$rating->winery->country_name = null;
}
$like = Like::where('user_id', $user_id)->where('rating_id', $rating->id)->first();
if ($like) {
$rating->liked = true;
} else {
$rating->liked = false;
}
$wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $rating->wine_unique_id)->first();
if ($wishlist) {
$rating->wishlist = true;
} else {
$rating->wishlist = false;
}
$rating->wine->image_url = Wine::getImageWineFromServer($user_id, $rating->wine->wine_unique_id, $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);
}
}
$data = $ratings->toArray();
}
}
return array("code" => $error_code, "data" => $data);
}
示例2: testGetTimelineSuccess
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));
}