/** * Main method. * * @since 0.1 * * @param string $subPage */ public function execute($subPage) { $subPage = str_replace('_', ' ', $subPage); $subPage = explode('/', $subPage, 2); $challengeTitle = count($subPage) > 1 ? $subPage[1] : false; $subPage = $subPage[0]; if (!parent::execute($subPage)) { return; } $out = $this->getOutput(); /** * @var $contest Contest */ $contest = Contest::s()->selectRow(null, array('name' => $subPage)); if ($contest === false) { $out->redirect(SpecialPage::getTitleFor('Contests')->getLocalURL()); } else { $out->setPageTitle(wfMsgExt('contest-contest-title', 'parseinline', $contest->getField('name'))); $this->displayNavigation(); $this->showGeneralInfo($contest); if ($this->getUser()->isAllowed('contestadmin')) { $this->showMailFunctionality($contest); } $out->addHTML(Html::element('h3', array(), wfMsg('contest-contest-contestants'))); $this->addFilterOptionsToSession(); $this->showFilterControl($contest, $challengeTitle); $this->showContestants($contest, $challengeTitle); $out->addModules('contest.special.contest'); } }
/** * Handle requests for non-existing contests, or requests with no contest specified. * If the contest does not exist, an error is shown, unless there is only one existing * contest, in which case the user is redirected to it, which also happens when no contest * is specified. If there are multiple active contests, a list is shown. * * @since 0.2 * * @param string $subPage */ protected function showNoSuchContest($subPage) { $out = $this->getOutput(); $c = Contest::s()->select(array('name', 'status', 'end'), array('status' => Contest::STATUS_ACTIVE)); $contests = array(); // It can also be expired, but this is stored as active in the db, so matches the selection. // It'd be better to get rid of this special behaviour so this kind of code is not needed. foreach ($c as $contest) { if ($contest->getStatus() == Contest::STATUS_ACTIVE) { $contests[] = $contest; } } if (count($contests) == 1) { $out->redirect($this->getTitle($contests[0]->getField('name'))->getLocalURL()); } else { if (!is_null($subPage) && trim($subPage) !== '') { $this->showError('contest-welcome-unknown'); } if (count($contests) == 0) { $out->addWikiMsg('contest-welcome-no-contests-active'); } else { $items = array(); foreach ($contests as $contest) { $items[] = '<li>' . Html::element('a', array('href' => $this->getTitle($contest->getField('name'))->getLocalURL()), $contest->getField('name')) . '</li>'; } $out->addWikiMsg('contest-welcome-active-contests'); $out->addHTML(Html::rawElement('ul', array(), implode("\n", $items))); } } $out->returnToMain(); }
/** * Displays the contests. * * @since 0.1 */ protected function displayContests() { $contests = Contest::s()->select(array('id', 'name', 'status', 'end', 'submission_count')); if (count($contests) > 0) { $this->displayContestsTable($contests); } $this->getOutput()->addModules('ext.contest.special.contests'); }
public function execute() { global $wgUser; if (!$wgUser->isAllowed('contestadmin') || $wgUser->isBlocked()) { $this->dieUsageMsg(array('badaccess-groups')); } $params = $this->extractRequestParams(); $everythingOk = true; $contestIds = is_null($params['contestids']) ? array() : $params['contestids']; $challengeIds = is_null($params['challengeids']) ? array() : $params['challengeids']; if (!is_null($params['challengetitles'])) { $challenges = ContestChallenge::s()->select('id', array('title' => $params['challengetitles'])); if ($challenges === false) { // TODO: error } foreach ($challenges as $challenge) { $challengeIds[] = $challenge->getId(); } } if (!is_null($params['contestnames'])) { $contests = Contest::s()->select('id', array('name' => $params['contestnames'])); if ($contests === false) { // TODO: error } foreach ($contests as $contest) { $contestIds[] = $contest->getId(); } } $conditions = array(); if (count($contestIds) > 0) { $conditions['contest_id'] = $contestIds; } if (count($challengeIds) > 0) { $conditions['challenge_id'] = $challengeIds; } if (!is_null($params['ids']) && count($params['ids']) > 0) { $conditions['id'] = $params['ids']; } $contestants = ContestContestant::s()->select(array('id', 'user_id', 'contest_id', 'email'), $conditions); $contestantCount = count($contestants); if ($contestants !== false && $contestantCount > 0) { $setSize = ContestSettings::get('reminderJobSize'); $limit = count($contestants); for ($i = 0; $i <= $limit; $i += $setSize) { $this->createReminderJob(array_slice($contestants, $i, $setSize)); } } else { $everythingOk = false; } $this->getResult()->addValue(null, 'success', $everythingOk); if ($everythingOk) { $this->getResult()->addValue(null, 'contestantcount', $contestantCount); } }
/** * Show the page. * * @since 0.1 * * @param string $subPage */ protected function showPage($subPage) { $out = $this->getOutput(); $subPage = explode('/', $subPage); $contestName = $subPage[0]; $challengeId = count($subPage) > 1 ? $subPage[1] : false; $contest = Contest::s()->selectRow(null, array('name' => $contestName)); if ($contest === false) { $this->showError('contest-signup-unknown'); $out->returnToMain(); return; } switch ($contest->getStatus()) { case Contest::STATUS_ACTIVE: $this->showEnabledPage($contest, $challengeId); break; case Contest::STATUS_DRAFT: $this->showWarning('contest-signup-draft'); $out->returnToMain(); break; case Contest::STATUS_FINISHED: case Contest::STATUS_EXPIRED: $this->showWarning('contest-signup-finished'); $out->returnToMain(); break; } }
/** * Handle view requests for the page. * * @since 0.1 * * @param string $contestName */ protected function handleSubmissionView($contestName) { $out = $this->getOutput(); $contest = Contest::s()->selectRow(null, array('name' => $contestName)); if ($contest === false) { $this->showError('contest-submission-unknown'); $out->returnToMain(); } else { switch ($contest->getStatus()) { case Contest::STATUS_ACTIVE: $this->handleEnabledPage($contest); break; case Contest::STATUS_FINISHED: case Contest::STATUS_EXPIRED: $this->showWarning('contest-submission-finished'); $out->returnToMain(); break; } } }
/** * Gets the contest for this participant. * * @since 0.1 * * @param array|string|null $fields The fields to load, null for all fields. * * @return Contest */ public function getContest($fields = null) { if (!is_null($this->contest)) { return $this->contest; } $contest = Contest::s()->selectRow($fields, array('id' => $this->getField('contest_id'))); if (is_null($this->contest) && is_null($fields)) { $this->contest = $contest; } return $contest; }
/** * Process the form. At this point we know that the user passes all the criteria in * userCanExecute(), and if the data array contains 'Username', etc, then Username * resets are allowed. * * @param array $data * * @return Bool|Array */ public function onSubmit(array $data) { $fields = array(); foreach ($data as $name => $value) { $matches = array(); if (preg_match('/contest-(.+)/', $name, $matches)) { if ($matches[1] == 'end') { $value = wfTimestamp(TS_MW, strtotime($value)); } $fields[$matches[1]] = $value; } } // If no ID is set, this means it's a new contest, so set the ID to null for an insert. // However, the user can have hot the back button after creation of a new contest, // re-submitting the form. In this case, get the ID of the already existing item for an update. if (!array_key_exists('id', $fields) || $fields['id'] === '') { $contest = Contest::s()->selectRow('id', array('name' => $fields['name'])); $fields['id'] = $contest === false ? null : $contest->getField('id'); } $contest = new Contest($fields, is_null($fields['id'])); $contest->setChallenges($this->getSubmittedChallenges()); $success = $contest->writeAllToDB(); $success = $this->removeDeletedChallenges($data['delete-challenges']) && $success; if ($success) { return true; } else { return array(); // TODO } }