当前位置: 首页>>代码示例>>PHP>>正文


PHP Rating::whereIn方法代码示例

本文整理汇总了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);
 }
开发者ID:anht37,项目名称:winelover_server,代码行数:57,代码来源:Rating.php

示例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));
 }
开发者ID:anht37,项目名称:winelover_server,代码行数:54,代码来源:TimelineTest.php


注:本文中的Rating::whereIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。