public function postRating() { // save rating $user = Auth::user(); $visualization = \App\Visualization::where('name', Session::get('visdata')->visualization)->first(); $relation = $user->visualizations()->where('visualization_id', $visualization->id)->first(); if (Input::get('isPositive')) { // check if already has rating $relation->pivot->rating = 1; $relation->pivot->save(); $relation->save(); } else { $relation->pivot->rating = 0; $relation->pivot->save(); $relation->save(); } }
private function userSharedKnowledge($vis) { $user = Auth::user(); $visualization = \App\Visualization::where('name', $vis->name)->first(); $visUser = $visualization->users()->where('user_id', $user->id)->first(); if ($visUser !== null) { $userRating = $visUser->pivot->rating; if ($userRating !== null) { if ($userRating == 1) { return 0.75; } else { if ($userRating == 0) { return 0.25; } else { return $userRating; } } } else { return $this->generateUserRating($visualization->id, 4, 4); } } else { return $this->generateUserRating($visualization->id, 4, 4); } }