本文整理汇总了PHP中Rating::check_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::check_rating方法的具体用法?PHP Rating::check_rating怎么用?PHP Rating::check_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::check_rating方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNewLike
public static function createNewLike($input)
{
$like = new Like();
$error_code = ApiResponse::OK;
$like->user_id = Session::get('user_id');
if (!empty($input['rating_id'])) {
$like->rating_id = $input['rating_id'];
$check_rating = Rating::check_rating($like->rating_id);
if ($check_rating !== false) {
if (Like::where('rating_id', $like->rating_id)->where('user_id', '=', $like->user_id)->first()) {
$error_code = ApiResponse::DUPLICATED_LIKE;
$data = ApiResponse::getErrorContent(ApiResponse::DUPLICATED_LIKE);
} else {
//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->save();
$data = $like->toArray();
}
} else {
$error_code = ApiResponse::UNAVAILABLE_RATING;
$data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
}
}
return array("code" => $error_code, "data" => $data);
}
示例2: createNewComment
public static function createNewComment($rating_id, $input)
{
$comment = new Comment();
$error_code = ApiResponse::OK;
$comment->user_id = Session::get('user_id');
if (!empty($input['content'])) {
$comment->content = $input['content'];
$comment->rating_id = $rating_id;
$check_rating = Rating::check_rating($comment->rating_id);
if ($check_rating !== false) {
//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();
}
$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();
}
$comment->save();
$profile = Profile::where('user_id', $comment->user_id)->first();
if ($profile->image != null) {
$comment->avatar_user = URL::asset($profile->image);
} else {
$comment->avatar_user = $profile->image;
}
$comment->first_name = $profile->first_name;
$comment->last_name = $profile->last_name;
$data = $comment;
} else {
$error_code = ApiResponse::UNAVAILABLE_RATING;
$data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
}
} else {
$error_code = ApiResponse::MISSING_PARAMS;
$data = $input;
}
return array("code" => $error_code, "data" => $data);
}