本文整理汇总了PHP中Rating::updateRatingDetail方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::updateRatingDetail方法的具体用法?PHP Rating::updateRatingDetail怎么用?PHP Rating::updateRatingDetail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::updateRatingDetail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNewRating
public static function createNewRating($input)
{
$rating = new Rating();
$error_code = ApiResponse::OK;
$rating->user_id = Session::get('user_id');
if (!empty($input['wine_unique_id'])) {
if (Wine::where('wine_unique_id', $input['wine_unique_id'])->first()) {
$rating_old = Rating::where('wine_unique_id', $input['wine_unique_id'])->where('user_id', $rating->user_id)->first();
if ($rating_old) {
$result = Rating::updateRatingDetail($rating_old->id, $input);
return $result;
} else {
$rating->wine_unique_id = $input['wine_unique_id'];
if (!empty($input['rate'])) {
$rating->rate = $input['rate'];
}
if (!empty($input['content'])) {
$rating->content = $input['content'];
}
if (!empty($input['like_count'])) {
$rating->like_count = $input['like_count'];
}
if (!empty($input['comment_count'])) {
$rating->comment_count = $input['comment_count'];
}
if (!empty($input['is_my_wine'])) {
$rating->is_my_wine = $input['is_my_wine'];
}
// Validation and Filtering is sorely needed!!
// Seriously, I'm a bad person for leaving that out.
$check = Rating::check_validator($input);
if ($check !== false) {
$rating_profile = Profile::where('user_id', $rating->user_id)->first();
if ($rating_profile != null) {
$rating_profile->rate_count = $rating_profile->rate_count + 1;
$rating_profile->save();
}
$rating_wine = Wine::where('wine_unique_id', $rating->wine_unique_id)->first();
if ($rating_wine != null) {
$rating_rate = $rating_wine->average_rate * $rating_wine->rate_count;
$rating_wine->rate_count = $rating_wine->rate_count + 1;
$rating_wine->average_rate = ($rating_rate + $rating->rate) / $rating_wine->rate_count;
$rating_wine->save();
}
$rating->save();
$data = $rating->toArray();
} else {
$error_code = ApiResponse::UNAVAILABLE_RATING;
$data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
}
}
} else {
$error_code = ApiResponse::UNAVAILABLE_WINE;
$data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
}
} else {
$error_code = ApiResponse::MISSING_PARAMS;
$data = $input;
}
return array("code" => $error_code, "data" => $data);
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$result = Rating::updateRatingDetail($id, $this->_getInput());
return Response::json($result);
}