Exemple #1
0
             $VoteCounts['labels'][] = $row['label'];
             $VoteCounts['datasets'][0]['data'][] = $row['value'];
         }
         Response::done(array('data' => $VoteCounts));
     } else {
         if (isset($_REQUEST['html'])) {
             Response::done(array('html' => Episodes::getSidebarVoting($Episode)));
         }
     }
     if (!Permission::sufficient('user')) {
         Response::fail();
     }
     if (!$Episode->aired) {
         Response::fail('You can only vote on this episode after it has aired.');
     }
     $UserVote = Episodes::getUserVote($Episode);
     if (!empty($UserVote)) {
         Response::fail('You already voted for this episode');
     }
     $vote = (new Input('vote', 'int', array(Input::IN_RANGE => [1, 5], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Vote value missing from request', Input::ERROR_RANGE => 'Vote value must be an integer between @min and @max (inclusive)'))))->out();
     if (!$Database->insert('episodes__votes', array('season' => $Episode->season, 'episode' => $Episode->episode, 'user' => $currentUser->id, 'vote' => $vote))) {
         Response::dbError();
     }
     $Episode->updateScore();
     Response::done(array('newhtml' => Episodes::getSidebarVoting($Episode)));
     break;
 case "videos":
     Response::done(Episodes::getVideoEmbeds($Episode));
     break;
 case "getvideos":
     $return = array('twoparter' => $Episode->twoparter, 'vidlinks' => array(), 'fullep' => array(), 'airs' => date('c', strtotime($Episode->airs)));
Exemple #2
0
 /**
  * Render episode voting HTML
  *
  * @param Episode $Episode
  *
  * @return string
  */
 static function getSidebarVoting(Episode $Episode) : string
 {
     $thing = $Episode->isMovie ? 'movie' : 'episode';
     if (!$Episode->aired) {
         return "<p>Voting will start " . Time::tag($Episode->willair) . ", after the {$thing} had aired.</p>";
     }
     global $Database, $signedIn, $currentUser;
     $HTML = '';
     if (empty($Episode->score)) {
         $Episode->updateScore();
     }
     $Score = preg_replace(new RegExp('^(\\d+)\\.0+$'), '$1', number_format($Episode->score, 1));
     $ScorePercent = round($Score / 5 * 1000) / 10;
     $HTML .= '<p>' . (!empty($Score) ? "This {$thing} is rated {$Score}/5 (<a class='detail'>Details</a>)" : 'Nopony voted yet.') . '</p>';
     if ($Score > 0) {
         $HTML .= "<img src='/muffin-rating?w={$ScorePercent}' id='muffins' alt='muffin rating svg'>";
     }
     $UserVote = Episodes::getUserVote($Episode);
     if (empty($UserVote)) {
         $HTML .= "<br><p>What did <em>you</em> think about the {$thing}?</p>";
         if ($signedIn) {
             $HTML .= "<button class='blue rate typcn typcn-star'>Cast your vote</button>";
         } else {
             $HTML .= "<p><em>Sign in above to cast your vote!</em></p>";
         }
     } else {
         $HTML .= "<p>Your rating: " . CoreUtils::makePlural('muffin', $UserVote['vote'], PREPEND_NUMBER) . '</p>';
     }
     return $HTML;
 }