/** * 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 comments for this contestant. * * @since 0.1 * * @return array of ContestComment */ public function getComments() { return ContestComment::s()->select(null, array('contestant_id' => $this->getId())); }
/** * Show the comments and a control to add additional ones. * * @since 0.1 * * @param ContestContestant $contestant */ protected function showComments(ContestContestant $contestant) { $out = $this->getOutput(); $out->addHTML(Html::element('h2', array(), wfMsg('contest-contestant-comments'))); $out->addHTML('<div class="contestant-comments">'); if ($this->getRequest()->wasPosted()) { ContestComment::s()->setReadDb(DB_MASTER); } $comments = $contestant->getComments(); ContestComment::s()->setReadDb(DB_SLAVE); foreach ($comments as $comment) { $out->addHTML($this->getCommentHTML($comment)); } $out->addHTML('</div>'); $out->addHTML('<div class="contestant-new-comment"> <textarea cols="40" rows="10" name="new-comment-text"></textarea> </div>'); $out->addHTML(Html::input('submitChanges', wfMsg('contest-contestant-submit'), 'submit')); }