/**
  * Sets a vote for this presentation by the current user
  *
  * @param  $vote int
  */
 public function setUserVote($vote)
 {
     $v = $this->owner->Votes()->filter('MemberID', Member::currentUserID())->first() ?: PresentationVote::create();
     $v->MemberID = Member::currentUserID();
     $v->PresentationID = $this->owner->ID;
     $v->Vote = $vote;
     $v->write();
 }
 /**
  * Gets presentations that this user has voted on
  * @return DataList 
  */
 public function getVotedPresentations()
 {
     return PresentationVote::get()->filter('MemberID', Member::currentUserID());
 }
 function SaveRating()
 {
     if (!Member::currentUserID()) {
         return Security::permissionFailure($this);
     }
     $rating = '';
     $TalkID = '';
     if (isset($_GET['rating']) && is_numeric($_GET['rating'])) {
         $rating = $_GET['rating'];
     }
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $presentationID = $_GET['id'];
     }
     $Member = member::currentUser();
     $validRatings = array(-1, 0, 1, 2, 3);
     if ($Member && isset($rating) && in_array((int) $rating, $validRatings, true) && $presentationID) {
         $previousVote = PresentationVote::get()->filter(array('PresentationID' => $presentationID, 'MemberID' => $Member->ID))->first();
         $presentation = Presentation::get()->byID($presentationID);
         $CategoryID = Session::get('CategoryID');
         if (!$previousVote) {
             $vote = new PresentationVote();
             $vote->PresentationID = $presentationID;
             $vote->Vote = $rating;
             $vote->IP = $this->ClientIP();
             $vote->MemberID = $Member->ID;
             $vote->write();
             $this->redirectBack();
         } else {
             $previousVote->Vote = $rating;
             $previousVote->IP = $this->ClientIP();
             $previousVote->write();
             $this->redirectBack();
         }
     } else {
         return 'no rating saved.';
     }
 }