Beispiel #1
0
 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);
 }
 public function store()
 {
     $entry_id = Input::get('entry_id');
     $user_id = Session::get('user')['id'];
     $like_id = FELikesHelper::getId($entry_id, $user_id, false);
     if ($like_id) {
         $like = Like::find($like_id);
         $like->is_deleted = 0;
         $like->save();
         $result = $like->toArray();
         $result['status'] = 'success';
         echo json_encode($result);
     } else {
         $like = new Like();
         $like->entry_id = $entry_id;
         $like['user_id'] = $user_id;
         $like->is_deleted = 0;
         $like->save();
         $result = $like->toArray();
         $result['status'] = 'success';
         echo json_encode($result);
     }
 }