Guest User

Untitled

a guest
Jul 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. //if a review is added, then we need to re-calculate avg rating
  2. function add($user_id = null, $movie_id = null, $id = null){
  3. //make sure the user is logged on or is an admin
  4. //if($this->checkUserSession($user_id) || $this->checkAdminSession()){
  5. if($this->checkUserSession($user_id)){
  6. //make sure the user didn't already review this movie TODO
  7. if (!empty($this->data)){
  8. //make sure the user is allowed to rate/write review (check age vs. mpaa rating)
  9. if(($review['Movie']['mpaa_rating'] == "NC-17" && $review['User']['Age'] >= 18) ||
  10. ($review['Movie']['mpaa_rating'] == "R" && $review['User']['Age'] >= 17) ||
  11. ($review['Movie']['mpaa_rating'] == "PG-13" && $review['User']['Age'] >= 13) ||
  12. ($review['Movie']['mpaa_rating'] == "PG" && $review['User']['Age'] >= 10) ||
  13. ($review['Movie']['mpaa_rating'] == "G")) {
  14. $this->Review->create();
  15. if ($this->Review->save($this->data)) {
  16. $this->Session->setFlash(__('Your review has been saved.', true));
  17. //update the ratings
  18. $var = "UPDATE movies SET num_ratings = num_ratings + 1";
  19. mysql_query($var);
  20. $var1 = "UPDATE movies SET avg_ratings = sum_ratings/num_ratings";
  21. mysql_query($var1);
  22. $this->redirect(array('action' => 'index'));
  23. } else {
  24. $this->Session->setFlash(__('Your review could not be saved. Please, try again.', true));
  25. }
  26. } else {
  27. $this->Session->setFlash(__('You are not old enough to review/rate this movie.', true));
  28. }
  29. }
  30. }
  31. $movies = $this->Review->Movie->find('list');
  32. $users = $this->Review->User->find('list');
  33. $this->set(compact('movies', 'users'));
  34. }
Add Comment
Please, Sign In to add comment