/** * Remove the contest and all it's linked data from the database. * * @since 0.1 * * @return boolean Success indicator */ public function removeAllFromDB() { if (!ContestSettings::get('contestDeletionEnabled')) { // Shouldn't get here (UI should prevent it) throw new MWException('Contest deletion is disabled', 'contestdeletiondisabled'); } $condition = array('contest_id' => $this->getId()); $success = ContestChallenge::s()->delete($condition); if ($success) { $contestantIds = array(); foreach (ContestContestant::s()->select('id', $condition) as $contestant) { $contestantIds[] = $contestant->getId(); } if (count($contestantIds) > 0) { $success = ContestComment::s()->delete(array('contestant_id' => $contestantIds)) && $success; $success = ContestVote::s()->delete(array('contestant_id' => $contestantIds)) && $success; } $success = ContestContestant::s()->delete($condition) && $success; } if ($success) { $success = parent::removeFromDB(); } return $success; }
/** * Get the votes for this contestant. * * @since 0.1 * * @return array of ContestVote */ public function getVotes() { return ContestVote::s()->select(null, array('contestant_id' => $this->getId())); }
/** * Display the current rating the judge gave if any and a control to * (re)-rate. * * @since 0.1 * * @param ContestContestant $contestant */ protected function showRating(ContestContestant $contestant) { $out = $this->getOutput(); $out->addHTML(Html::element('h2', array(), wfMsg('contest-contestant-rate'))); $vote = ContestVote::s()->selectRow(array('value', 'id'), array('user_id' => $this->getUser()->getId(), 'contestant_id' => $contestant->getId())); if ($vote === false) { $message = wfMsg('contest-contestant-not-voted'); } else { $message = wfMsgExt('contest-contestant-voted', 'parsemag', $this->getLanguage()->formatNum($vote->getField('value'))); $out->addHTML(Html::hidden('contestant-vote-id', $vote->getId())); } $out->addHTML(Html::element('p', array(), $message)); foreach (ContestSettings::get('voteValues') as $value) { $attribs = array('type' => 'radio', 'value' => $value, 'name' => 'contestant-rating', 'id' => 'contestant-rating-' . $value); if ($vote !== false && $value == $vote->getField('value')) { $attribs['checked'] = 'checked'; } $out->addHTML(Html::element('input', $attribs) . Html::element('label', array('for' => 'contestant-rating-' . $value), $this->getLanguage()->formatNum($value))); } }