Example #1
0
 /**
  * Returns the new score of the Challenge
  * @return Int
  */
 public function addVote($idUser, $typeVote)
 {
     //Upgrade owner of the Truth if necessary
     $type = $this->idTruth === null ? 'Dare' : 'Truth';
     User::userRankUpgrade($this->idUserTo, 1, $type);
     //We add the vote up or down
     if ($typeVote == 'up') {
         $this->voteUp += 1;
     } else {
         $this->voteDown += 1;
     }
     //We save
     $this->save();
     //We add the vote to the table VotingDetail
     $votingDetail = new VotingDetail();
     $votingDetail->idUser = $idUser;
     $votingDetail->idChallenge = $this->idChallenge;
     $votingDetail->voteDate = date('Y-m-d, H:i:s');
     $votingDetail->voteType = $typeVote == 'up' ? 1 : 0;
     $votingDetail->save();
     return $this->voteUp - $this->voteDown;
 }
Example #2
0
 /**
  * Returns the new score of the Truth
  * @return Int
  */
 public function addVote($idUser, $typeVote)
 {
     //Upgrade owner of the Truth if necessary
     User::userRankUpgrade($this->idUser, 1, 'Truth');
     //We add the vote up or down
     if ($typeVote == 'up') {
         $this->voteUp += 1;
     } else {
         $this->voteDown += 1;
     }
     //We save
     $this->save();
     //We add the vote to the table VotingDetail
     $votingDetail = new VotingDetail();
     $votingDetail->idUser = $idUser;
     $votingDetail->idTruth = $this->idTruth;
     $votingDetail->voteDate = date('Y-m-d, H:i:s');
     //VoteType = 1 -> + 1 / VoteType = 0 -> -1
     $votingDetail->voteType = $typeVote == 'up' ? 1 : 0;
     $votingDetail->save();
     return $this->voteUp - $this->voteDown;
 }