/**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     // get entry
     if (isset($_REQUEST['contestID'])) {
         $this->contestID = intval($_REQUEST['contestID']);
     }
     $this->entry = new ViewableContest($this->contestID);
     if (!$this->entry->contestID) {
         throw new IllegalLinkException();
     }
     if (isset($_REQUEST['errorField'])) {
         $this->errorField = $_REQUEST['errorField'];
     }
     if (isset($_REQUEST['action'])) {
         $this->action = $_REQUEST['action'];
     }
     if (isset($_REQUEST['commentID'])) {
         $this->commentID = intval($_REQUEST['commentID']);
     }
     if ($this->commentID != 0) {
         $this->comment = new ContestComment($this->commentID);
         if (!$this->comment->commentID || $this->comment->contestID != $this->contestID) {
             throw new IllegalLinkException();
         }
         // check permissions
         if ($this->action == 'edit' && !$this->comment->isEditable()) {
             throw new PermissionDeniedException();
         }
         // get page number
         $pagennumber = new ContestEventMixList();
         $pagennumber->sqlConditions .= 'contestID = ' . intval($this->contestID);
         $pagennumber->sqlConditions .= ' AND time < ' . intval($this->comment->time);
         $count = $pagennumber->countObjects();
         $this->pageNo = $count > $this->itemsOnLandingpage ? 1 : 0;
         $this->pageNo += ceil(($count - $this->itemsOnLandingpage) / $this->itemsPerPage);
     }
     // init eventmix list
     $this->eventmixList = new ContestEventMixList();
     $this->eventmixList->sqlConditions .= 'contestID = ' . intval($this->contestID);
     $this->eventmixList->sqlOrderBy = 'contest_eventmix.time DESC';
 }
 /**
  * @see DatabaseObject::handleData()
  */
 protected function handleData($data)
 {
     parent::handleData($data);
     $this->owner = new ContestOwner($data, $this->userID, $groupID = 0);
 }
 /**
  * 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()));
 }
 /**
  * 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 HTML for a single comment.
  *
  * @since 0.1
  *
  * @param ContestComment $comment
  *
  * @return string
  */
 protected function getCommentHTML(ContestComment $comment)
 {
     $user = User::newFromId($comment->getField('user_id'));
     $htmlId = 'c' . $comment->getId();
     $html = Html::rawElement('div', array('class' => 'contestant-comment-meta'), Html::element('a', array('href' => $this->getTitle($this->subPage)->getLocalURL() . "#{$htmlId}", 'title' => wfMsg('contest-contestant-permalink')), '#') . wfMsgHtml('contest-contestant-comment-by', Linker::userLink($comment->getField('user_id'), $user->getName()) . Linker::userToolLinks($comment->getField('user_id'), $user->getName())) . '&#160;&#160;&#160;' . htmlspecialchars($this->getLanguage()->timeanddate($comment->getField('time'), true)));
     $html .= Html::rawElement('div', array('class' => 'contestant-comment-text mw-content-' . $this->getLanguage()->getDir() . ''), $this->getOutput()->parse($comment->getField('text')));
     return Html::rawElement('div', array('class' => 'contestant-comment', 'id' => $htmlId), $html);
 }