Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //if a review is added, then we need to re-calculate avg rating
- function add($user_id = null, $movie_id = null, $id = null){
- //make sure the user is logged on or is an admin
- //if($this->checkUserSession($user_id) || $this->checkAdminSession()){
- if($this->checkUserSession($user_id)){
- //make sure the user didn't already review this movie TODO
- if (!empty($this->data)){
- //make sure the user is allowed to rate/write review (check age vs. mpaa rating)
- if(($review['Movie']['mpaa_rating'] == "NC-17" && $review['User']['Age'] >= 18) ||
- ($review['Movie']['mpaa_rating'] == "R" && $review['User']['Age'] >= 17) ||
- ($review['Movie']['mpaa_rating'] == "PG-13" && $review['User']['Age'] >= 13) ||
- ($review['Movie']['mpaa_rating'] == "PG" && $review['User']['Age'] >= 10) ||
- ($review['Movie']['mpaa_rating'] == "G")) {
- $this->Review->create();
- if ($this->Review->save($this->data)) {
- $this->Session->setFlash(__('Your review has been saved.', true));
- //update the ratings
- $var = "UPDATE movies SET num_ratings = num_ratings + 1";
- mysql_query($var);
- $var1 = "UPDATE movies SET avg_ratings = sum_ratings/num_ratings";
- mysql_query($var1);
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('Your review could not be saved. Please, try again.', true));
- }
- } else {
- $this->Session->setFlash(__('You are not old enough to review/rate this movie.', true));
- }
- }
- }
- $movies = $this->Review->Movie->find('list');
- $users = $this->Review->User->find('list');
- $this->set(compact('movies', 'users'));
- }
Add Comment
Please, Sign In to add comment