示例#1
0
 public function getIndex()
 {
     $rating = new Rating();
     $rating = Rating::where('ven_id', '=', '14')->avg('rvalue');
     echo $rating;
     //return 'Ratings';
 }
示例#2
0
 public static function deleteLike($rating_id)
 {
     $error_code = ApiResponse::OK;
     $user_id = Session::get('user_id');
     if (Rating::where('id', $rating_id)->first()) {
         $like = Like::where('rating_id', $rating_id)->where('user_id', $user_id)->first();
         if ($like) {
             //update like_count on rating
             $like_rating = Rating::where('id', $like->rating_id)->first();
             if ($like_rating != null) {
                 $like_rating->like_count = $like_rating->like_count - 1;
                 $like_rating->save();
             }
             $like->delete();
             $data = 'Like deleted';
         } else {
             $error_code = ApiResponse::NOT_EXISTED_LIKE;
             $data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
 public function testGetRatingDetailSuccess()
 {
     $this->setUpRating();
     $response = $this->call('GET', 'api/rating/1');
     $rating_infor = Rating::where('id', 1)->with('wine')->first();
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
 }
 public function testUpdateRatingSuccess()
 {
     $this->setUpRating();
     $_params = $this->_params;
     //dd(json_encode($_params));
     $response = $this->action('POST', 'RatingController@update', array('id' => 1), array('data' => json_encode($_params), '_method' => 'PUT'));
     //get created login information
     $rating_infor = Rating::where('id', 1)->first();
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
 }
示例#5
0
 /**
  * Override delete method
  * Delete topic itself and all it's comments, ratings, and view counter
  */
 public function delete()
 {
     $tid = $this->id;
     // delete view counter
     Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     Rating::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$tid, Topic::ENTITY_TYPE])->delete();
     Comment::where("[topicId] = ?", $tid)->delete();
     parent::delete();
 }
 public function deleteIssue()
 {
     if (Auth::user()->isAdmin()) {
         $issue_id = Input::get('issue_id');
         $deletedRatings = Rating::where('issue_id', '=', $issue_id)->delete();
         $deletedIssueFollows = IssueFollow::where('issue_id', '=', $issue_id)->delete();
         $issue = Issue::find($issue_id);
         $issue->delete();
     } else {
         return App::abort(404);
     }
 }
示例#7
0
 public static function getRating($type, $id)
 {
     $rating = 0;
     $ratings = Rating::where('item_id', $id)->where('item_type', $type)->get();
     $numRatings = sizeof($ratings);
     if ($numRatings) {
         for ($i = 0; $i < $numRatings; $i++) {
             $rating += $ratings[$i]['rating'];
         }
         $rating = $rating / $numRatings;
     }
     return array('rating' => $rating, 'numRatings' => $numRatings);
 }
示例#8
0
 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 function calculateRating($username)
 {
     $username1 = User::where('username', '=', $username)->get();
     if ($username1->isEmpty()) {
         return Response::json(array($username . ' not valid'));
     }
     $username2 = Rating::where('seller', '=', $username)->get();
     if ($username2->isEmpty()) {
         return Response::json(array('name' => $username, 'rating' => "There is no Rating against {$username}"));
     }
     $ratings = Rating::where('seller', '=', $username)->get();
     $sum = 0;
     $count = 0;
     foreach ($ratings as $rating) {
         $sum += $rating->rating_number;
         $count = $count + 1;
     }
     $average = $sum / $count;
     return Response::json(array('name' => $username, 'rating' => $average));
 }
示例#10
0
 public static function getProfieLastRate($user_id)
 {
     $error_code = ApiResponse::OK;
     $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'];
         if (User::where('user_id', $user_id)->first()) {
             $last_rates = Rating::where('user_id', $user_id)->orderBy('updated_at', 'desc')->with('wine')->forPage($page, $limit)->get();
             foreach ($last_rates as $last_rate) {
                 $last_rate->winery = Winery::where('id', $last_rate->wine->winery_id)->first();
                 if ($last_rate->wine->image_url != null) {
                     $last_rate->wine->image_url = URL::asset($last_rate->wine->image_url);
                 }
                 if ($last_rate->wine->wine_flag != null) {
                     $last_rate->wine->wine_flag = URL::asset($last_rate->wine->wine_flag);
                 }
             }
             $data = $last_rates->toArray();
         } else {
             $error_code = ApiResponse::UNAVAILABLE_USER;
             $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER);
         }
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#11
0
 public static function searchWinefromMywine($input)
 {
     $error_code = ApiResponse::OK;
     $wine_unique_id = array();
     $data = array();
     $user_id = Session::get('user_id');
     if (!empty($input['text'])) {
         $text = $input['text'];
         $ratings = Rating::where('user_id', $user_id)->where('is_my_wine', 1)->get();
         if ($ratings) {
             foreach ($ratings as $rating) {
                 $wine_unique_id[] = $rating->wine_unique_id;
             }
             if ($wine_unique_id != null) {
                 $wishlists = Wishlist::where('user_id', $user_id)->whereNotIn('wine_unique_id', $wine_unique_id)->get();
             } else {
                 $wishlists = Wishlist::where('user_id', $user_id)->get();
             }
             if ($wishlists) {
                 foreach ($wishlists as $wishlist) {
                     $wine_unique_id[] = $wishlist->wine_unique_id;
                 }
             }
         }
         if ($wine_unique_id != null) {
             $wines = Wine::where('name', 'LIKE', '%' . $text . '%')->whereIn('wine_unique_id', $wine_unique_id)->with('winery')->get();
             if ($wines) {
                 foreach ($wines as $wine) {
                     if ($wine->image_url != null) {
                         $wine->image_url = URL::asset($wine->image_url);
                     }
                     if ($wine->wine_flag != null) {
                         $wine->wine_flag = URL::asset($wine->wine_flag);
                     }
                     $data[] = $wine;
                 }
             }
         }
     } else {
         $error_code = ApiResponse::MISSING_PARAMS;
         $data = $input;
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#12
0
 public static function deleteComment($rating_id, $id)
 {
     $comment = Comment::where('id', '=', $id)->first();
     $error_code = ApiResponse::OK;
     if (Rating::where('id', $rating_id)->first()) {
         if ($comment) {
             $comment_profile = Profile::where('user_id', $comment->user_id)->first();
             if ($comment_profile != null) {
                 $comment_profile->comment_count = $comment_profile->comment_count - 1;
                 $comment_profile->save();
             }
             //update comment_count on rating
             $comment_rating = Rating::where('id', $comment->rating_id)->first();
             if ($comment_rating != null) {
                 $comment_rating->comment_count = $comment_rating->comment_count - 1;
                 $comment_rating->save();
                 $comment->delete();
             }
             $data = 'Comment deleted';
         } else {
             $error_code = ApiResponse::UNAVAILABLE_COMMENT;
             $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_COMMENT);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#13
0
 public static function deleteGroup(Group $group)
 {
     Rating::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     $topics = Topic::find("groupId", $group->id)->all();
     foreach ($topics as $topic) {
         $topic->delete();
     }
     GroupUser::where("[groupId] = ?", $group->id)->delete();
     $group->delete();
 }
示例#14
0
 public function testGetProfileLastRateSucess()
 {
     $this->setUpRating();
     $user_id = $this->_user_id;
     $per_page = 10;
     $page = 1;
     $response = $this->action('GET', 'ProfileController@get_profile_Last_rate', array('user_id' => $user_id));
     $last_rate = Rating::where('user_id', $user_id)->orderBy('updated_at', 'desc')->with('wine')->forPage($page, $per_page)->get();
     foreach ($last_rate as $last_rates) {
         $last_rates->winery = Winery::where('id', $last_rates->wine->winery_id)->first()->toArray();
         if ($last_rates->wine->image_url != null) {
             $last_rates->wine->image_url = URL::asset($last_rates->wine->image_url);
         }
         if ($last_rates->wine->wine_flag != null) {
             $last_rates->wine->wine_flag = URL::asset($last_rates->wine->wine_flag);
         }
     }
     $data = $last_rate;
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->toArray()), json_decode($response->getContent(), true));
 }
示例#15
0
 public function testSearchWineSuccess()
 {
     $data = array();
     $_params = $this->_params;
     $response = $this->action('POST', 'WineController@search', array(), array('data' => json_encode($_params)));
     $user_id = $this->_user_id;
     $wine = Wine::where('name', 'LIKE', '%wi%')->with('winery')->get();
     if ($wine) {
         foreach ($wine as $wines) {
             if ($wines->image_url != null) {
                 $wines->image_url = URL::asset($wines->image_url);
             }
             if ($wines->wine_flag != null) {
                 $wines->wine_flag = URL::asset($wines->wine_flag);
             }
             $ratings = Rating::where('user_id', $user_id)->where('wine_unique_id', $wines->wine_unique_id)->where('is_my_wine', 1)->first();
             if ($ratings) {
                 $data[] = $wines;
             } else {
                 $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wines->wine_unique_id)->first();
                 if ($wishlist) {
                     $data[] = $wines;
                 }
             }
         }
     }
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true));
 }
示例#16
0
 /**
  * Delete plus-rating data
  */
 public function delete()
 {
     if (isset($this->entityType) && isset($this->entityId)) {
         Rating::where("[entityId] = ? AND [entityType] = ?", [$this->entityId, $this->entityType])->delete();
         RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$this->entityId, $this->entityType])->delete();
     }
 }
示例#17
0
 /**
  * Remove the specified beer from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $ratings = Rating::where('beer_id', '=', $id)->get();
     foreach ($ratings as $rating) {
         Rating::destroy($rating->rating_id);
     }
     Beer::destroy($id);
     return Response::json(['all good' => $id]);
 }