/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreateRatingRequest $request, $id)
 {
     $restaurant = Restaurant::findOrFail($id);
     $rating = new Rating();
     $rating->fill($request->input());
     $rating->restaurant()->associate($restaurant);
     $rating->save();
     return $restaurant;
 }
 public function storeRating()
 {
     if (Request::ajax()) {
         $input = Request::all();
         $rating = new Rating($input);
         $rating->ip = Request::getClientIp();
         $rating->save();
         return response(200);
     }
 }
Exemple #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, RentalUnit $rental, User $user)
 {
     $rating = $rental->ratings()->where('from_user', $user->id)->first();
     if ($rating == null) {
         $rating = new Rating();
     }
     $rating->fill(Input::all());
     $rating->save();
     //        $rating->avgRating = $rental->ratings()->avg('rating_points');
     return Response::json($rating);
 }
 public function rate(Request $request, $courseSlug, $lessonSlug)
 {
     $this->validate($request, ['rating' => 'required|numeric|between:1,5', 'comment' => 'required']);
     $course = Course::where('slug', $courseSlug)->firstOrFail();
     $lesson = Lesson::where('slug', $lessonSlug)->where('course_id', $course->id)->firstOrFail();
     $rating = new Rating();
     $rating->lesson_id = $lesson->id;
     $rating->user_id = Auth::user()->id;
     $rating->rating = $request->rating;
     $rating->comment = $request->comment;
     $rating->save();
     return redirect(action('LessonController@show', [$courseSlug, $lessonSlug]));
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getCreate($dishId, $rating)
 {
     $data = ['dish' => $dishId, 'rating' => $rating];
     if (Rating::where('dish_id', '=', $dishId)->where('rater_id', '=', Auth::user()->id) || 0 <= $rating || $rating <= 5) {
         $ratingObject = new Rating();
         $ratingObject->rating = $rating;
         $ratingObject->dish_id = $dishId;
         $ratingObject->rater_id = Auth::user()->id;
         $ratingObject->save();
         return redirect()->back()->withSuccess('you have rated this dish');
     } else {
         return redirect()->back()->withErrors(['something went wrong with your vote']);
     }
 }
 public function ratingFreelancer()
 {
     if (\Request::ajax()) {
         $freelancer_id = Input::get('freelancer_id');
         $comment = Input::get('comment');
         $rating_num = Input::get('rating');
         $rating_temp = new \App\Rating();
         $rating_temp->freelancer_id = $freelancer_id;
         $rating_temp->comment = $comment;
         $rating_temp->rating = $rating_num;
         $rating_temp->save();
         echo json_encode(array('succ' => 1));
     }
     //View::make('index');
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $this->generateSessionValueIfNotExists();
     $data['teams'] = [];
     $teams = Team::orderBy('name', 'asc')->get();
     foreach ($teams as $team) {
         $isFavourite = Rating::where('session', '=', $_SESSION["session"])->where('team_id', '=', $team->id)->get();
         if (count($isFavourite) > 0) {
             $team->isFavourite = true;
         } else {
             $team->isFavourite = false;
         }
         array_push($data['teams'], $team);
     }
     //$data['ratings'] = Rating::all();
     $data['ratings'] = DB::select('select count(*) as votos, t.name as equipo, t.link as enlace, u.name as usuario
                         from ratings as r
                         join teams as t on r.team_id = t.id
                         join users as u on t.user_id = u.id
                         group by r.team_id
                         order by votos desc, t.name asc');
     //dd($data);
     $data['last_teams'] = Team::orderBy('id', 'desc')->limit(5)->get();
     $data['users'] = User::all();
     return view('welcome.welcome', $data);
 }
 public function checkMinVotes($iterinary_id)
 {
     $numOfVotes = Rating::where("ratingable_type", "Iterinary")->where("ratingable_id", $iterinary_id)->get();
     if (count($numOfVotes) >= 5) {
         return true;
     }
     return false;
 }
Exemple #9
0
 public function actionDelete($id)
 {
     $user = Auth::user();
     $rating = Rating::where('user_id', '=', $user->id)->findOrFail($id);
     $rating->delete($rating);
     \Session::flash('flash_message', 'You have successfully deleted a rating.');
     return redirect('ratings');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('ratings')->delete();
     Rating::create(array('user_id' => '1', 'book_id' => '1', 'rating' => '7'));
     Rating::create(array('user_id' => '1', 'book_id' => '2', 'rating' => '8'));
     Rating::create(array('user_id' => '1', 'book_id' => '3', 'rating' => '9'));
     Rating::create(array('user_id' => '2', 'book_id' => '1', 'rating' => '9'));
     Rating::create(array('user_id' => '2', 'book_id' => '3', 'rating' => '9'));
 }
Exemple #11
0
 public function submitreview()
 {
     $pc = Request::get('pc');
     $name = Request::get('username');
     $type = Request::get('type');
     $rating = Request::get('rating');
     $review = Request::get('review');
     Rating::insert(['Postcode' => $pc, 'Type' => $type, 'Name' => $name, 'Rating' => $rating, 'Review' => $review]);
     return view('welcome');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $books = ['The Great Gatsby' => ['1'], 'A Fire in the Deep' => ['5'], 'Deepness in the Sky' => ['10']];
     foreach ($books as $title => $rating) {
         $book = \App\Book::where('title', 'like', $title)->first();
         foreach ($rating as $ratingName) {
             $rating = \App\Rating::where('rating', 'LIKE', $ratingName)->first();
             $book->ratings()->save($rating);
         }
     }
 }
 public function show(Request $request)
 {
     $result = Rating::where(['user_id_from' => $request->input('user_id_from'), 'user_id_to' => $request->input('user_id_to')])->first();
     if (!$result) {
         $result = array();
         foreach (Rating::$RATING_TYPES as $type) {
             $result[Rating::RATING_COLUMN_PREFIX . $type] = 0;
         }
     }
     return response()->json($result);
 }
Exemple #14
0
 public function ratingForUser($userId)
 {
     $rating = Rating::where('givenTo', '=', $userId)->get();
     $ratingValues = array_column($rating->toArray(), 'ratingValue');
     $sum = 0;
     foreach ($ratingValues as $ratingValue) {
         $sum += $ratingValue;
     }
     $finalRating = count($ratingValues) > 0 ? $sum / count($ratingValues) : 0;
     return $finalRating;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($team_id)
 {
     $team = Team::find($team_id);
     if (!$team) {
         abort(404);
     }
     $message = "" . $team->name . " ha dejado de ser un equipo favorito. ¿Por qué?";
     session_start();
     $registro = Rating::where('team_id', '=', $team_id)->where('session', '=', $_SESSION["session"])->get();
     $registro[0]->delete();
     return redirect()->route('welcome')->with('status', 'danger')->with('message', $message);
 }
 /**
  * @param Request $request
  * @return array
  */
 public function store(Request $request)
 {
     if (Auth::check()) {
         $request['user_id'] = Auth::id();
         if (!Rating::where('book_id', '=', $request->book_id)->where('user_id', '=', $request->user_id)->exists()) {
             Rating::create($request->all());
             return 1;
             // Added
         }
         return 2;
         // You have already voted on this Books
     } else {
         return 3;
         // You are not Logged
     }
     return $input;
 }
Exemple #17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (App::environment() === 'production') {
         exit('Do not seed in production environment');
     }
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     // disable foreign key constraints
     DB::table('ratings')->truncate();
     // Rating::create([
     //     'id'          => 1,
     //     'givenBy'     => 2,
     //     'givenTo'     => 3,
     //     'ratingValue' => 5
     // ]);
     Rating::create(['id' => 2, 'givenBy' => 2, 'givenTo' => 4, 'ratingValue' => 3]);
     Rating::create(['id' => 3, 'givenBy' => 2, 'givenTo' => 5, 'ratingValue' => 4]);
     Rating::create(['id' => 4, 'givenBy' => 6, 'givenTo' => 5, 'ratingValue' => 3]);
     Rating::create(['id' => 1, 'givenBy' => 6, 'givenTo' => 3, 'ratingValue' => 5]);
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     // enable foreign key constraints
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  film id  $id
  * @param  fl_rating $old
  * @return Response
  */
 public function betterRating($id, $old)
 {
     $numVote = Rating::where('rt_fl_id', $id)->count();
     $sumVote = Rating::where('rt_fl_id', $id)->sum('rt_vote');
     $old = round($old, 1);
     if ($numVote == 0) {
         if ($old == 0) {
             return '-';
         } else {
             return $old;
         }
     } else {
         if ($numVote > 0 && $numVote < 5) {
             if ($old == 0) {
                 return '-';
             } else {
                 return $old;
             }
         } else {
             if ($numVote > 4) {
                 return round($sumVote / $numVote, 1);
             }
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $rating = Rating::findOrFail($id);
     if ($rating['end_user_id'] !== Auth::user()->userable->id) {
         return response('Unauthorized', 401);
     }
     if ($rating['editing_expires_at'] < Carbon::now()) {
         return response('Rating editing expired', 401);
     }
     $data = $request->all();
     $validator = $this->validator($data);
     if ($validator->fails()) {
         return response(['errors' => $validator->messages()], 400);
     }
     // store
     $rating->update($data);
     // Update mastori average rating
     $mastori = Mastori::find($rating['mastori_id']);
     $mastori['avg_rating'] = $mastori->ratings()->avg('rating');
     $mastori->save();
     return $rating;
 }
 public function rate($id)
 {
     $wbbUId = \Input::get('wbbUId');
     $i = explode('_', explode(' ', \Input::get('clickedOn'))[0])[1];
     $c = Rating::where('downloadId', $id)->where('WbbUId', $wbbUId)->count();
     if ($c > 0) {
         Rating::where('downloadId', $id)->where('WbbUId', $wbbUId)->update(array('value' => $i));
     } else {
         Rating::create(array('value' => $i, 'downloadId' => $id, 'WbbUId' => $wbbUId));
     }
     return response(array('avg' => intval(round(Rating::getAvg($id)))));
 }
 public function getEachAvgRating()
 {
     return Rating::where("ratingable_type", "Iterinary")->selectRaw("ratingable_id, avg(value)")->groupBy("ratingable_id")->orderBy("avg(value)", "DESC")->get();
 }
 /**
  * Get Book Rating
  * @param $id
  * @return mixed
  */
 public function getBookRating($id)
 {
     $bookRating = round(Rating::where('book_id', '=', $id)->avg('rating'));
     return $bookRating;
 }
Exemple #23
0
 public function getProfileByUserID($userid)
 {
     $user_id = $userid;
     $userSkills = User::find($user_id)->skill;
     $user = User::find($user_id);
     $ratings = \App\Rating::where('freelancer_id', '=', $user_id)->get();
     $rating_value = \App\Rating::where('freelancer_id', '=', $user_id)->avg('rating');
     // skills
     $skill_categories = \App\SkillCategories::all();
     $user_id = \Auth::user()->id;
     $skillsByCategory = array();
     $i = 0;
     foreach ($skill_categories as $category) {
         $skillsByCategory[$i++] = Skill::where('skill_category_id', '=', $category->id)->get();
     }
     //-------------
     return View::make('profile')->with('userSkills', $userSkills)->with('user', $user)->with('ratings', $ratings)->with('skill_categories', $skill_categories)->with('userSkills', $userSkills)->with('skillsByCategory', $skillsByCategory)->with('rating_value', $rating_value);
 }
Route::controllers(['password' => 'Auth\\PasswordController']);
//Route to Confirm Login worked!
Route::get('/confirm-login-worked', function () {
    $user = Auth::user();
    if ($user) {
        echo 'You are logged in.';
        dump($user->toArray());
    } else {
        echo 'You are not logged in.';
    }
    return;
});
//setup search
Route:
get('/books/search', function () {
    $books = \App\Book::all();
    return view('books/search')->with('books', $books);
});
Route::get('/search/rating', function () {
    $books = \App\Book::all();
    $ratings = \App\Rating::all();
    return view('books/search/rating')->with('books', $books)->with('ratings', $ratings);
});
Route::resource('books', 'BookController');
Route::resource('book', 'BookController');
Route::post('/books/search', 'BookController@search');
Route::post('/books/edit/submit', 'BookController@edited');
Route::post('/books/{id}', 'BookController@comment');
//Route::post('/books/{id}', 'BookController@rating');
Route::get('/books/{id}/delete', 'BookController@delete');
Route::get('/books/{id?}/confirm_delete/', 'BookController@getConfirmDelete');
Exemple #25
0
 function updateRating(Request $request)
 {
     if (Rating::where('user_id', $request->user_id)->where('item_id', $request->item_id)->exists()) {
         Rating::where('user_id', $request->user_id)->where('item_id', $request->item_id)->update(['rating' => $request->rating]);
     } else {
         $rating_relation = new Rating();
         $rating_relation->user_id = $request->user_id;
         $rating_relation->item_id = $request->item_id;
         $rating_relation->rating = $request->rating;
         $rating_relation->save();
     }
     return redirect('/relogin');
 }
Exemple #26
0
 private function checkRatings($ratings)
 {
     $user = Auth::user();
     $currentRatings = array_filter($ratings, 'is_numeric');
     $newRatings = array_diff($ratings, $currentRatings);
     foreach ($newRatings as $newRating) {
         $rating = Rating::create(['name' => $newRating]);
         $user->ratings()->save($rating);
         $currentRatings[] = $rating->id;
     }
     return $currentRatings;
 }
 public function toggleDelete($id)
 {
     /** @var Rating $rating */
     $rating = Rating::withTrashed()->where('id', '=', $id)->first();
     if ($rating->trashed()) {
         $rating->restore();
     } else {
         $rating->delete();
     }
 }
 public function export($id)
 {
     $ratings = Rating::withTrashed()->where('lesson_id', '=', $id)->get();
     //dd($ratings);
     Excel::create('ratings', function ($excel) use($ratings) {
         $excel->sheet('Sheet 1', function ($sheet) use($ratings) {
             $sheet->fromArray($ratings);
         });
     })->export('xls');
 }
Exemple #29
0
 public function getAverageRatings()
 {
     return Rating::getAllAverageRatings($this->facebook_id);
 }