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); } }
/** * Called when changing user email address. * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail * * Checks if there are any active contests in which the user is participating, * and if so, updates the email there as well. * * @since 0.1 * * @param User $user * @param string $email * * @return true */ public static function onUserSetEmail(User $user, &$email) { $dbr = wfGetDB(DB_SLAVE); $contestants = $dbr->select(array('contest_contestants', 'contests'), array('contestant_id'), array('contest_status' => Contest::STATUS_ACTIVE, 'contestant_user_id' => $user->getId()), __METHOD__, array(), array('contests' => array('INNER JOIN', array('contest_id=contestant_contest_id')))); $contestantIds = array(); foreach ($contestants as $contestant) { $contestantIds[] = $contestant->contestant_id; } if (count($contestantIds) > 0) { ContestContestant::s()->update(array('email' => $email), array('id' => $contestantIds)); } return true; }
/** * Handle a submission by inserting/updating the vote * and (optionally) adding the comment. * * @since 0.1 * * @param integer $contestantId * * @return boolean Success indicator */ protected function handleSubmission($contestantId) { $success = true; if (trim($this->getRequest()->getText('new-comment-text')) !== '') { $comment = new ContestComment(array('user_id' => $this->getUser()->getId(), 'contestant_id' => $contestantId, 'text' => $this->getRequest()->getText('new-comment-text'), 'time' => wfTimestampNow())); $success = $comment->writeToDB(); if ($success) { ContestContestant::s()->addToField('comments', 1); } } if ($success && !is_null($this->getRequest()->getVal('contestant-rating'))) { $attribs = array('value' => $this->getRequest()->getInt('contestant-rating'), 'contestant_id' => $contestantId, 'user_id' => $this->getUser()->getId()); if (!is_null($this->getRequest()->getVal('contestant-vote-id'))) { $attribs['id'] = $this->getRequest()->getInt('contestant-vote-id'); } $vote = new ContestVote($attribs); $success = $vote->writeToDB() && $success; } return $success; }
/** * Handle page request when the contest is enabled. * * @since 0.1 * * @param Contest $contest * @param integer|false $challengeId */ protected function showEnabledPage(Contest $contest, $challengeId) { $out = $this->getOutput(); // Check if the user is already a contestant in this contest. // If he is, reirect to submission page, else show signup form. $contestant = ContestContestant::s()->selectRow('id', array('contest_id' => $contest->getId(), 'user_id' => $this->getUser()->getId())); if ($contestant === false) { $out->setPageTitle($contest->getField('name')); $out->addWikiMsg('contest-signup-header', $contest->getField('name')); $this->showSignupForm($contest, $challengeId); } else { $out->redirect(SpecialPage::getTitleFor('MyContests', $contest->getField('name'))->getLocalURL()); } }
/** * Handle page request when the contest is enabled. * * @since 0.1 * * @param Contest $contest */ protected function handleEnabledPage(Contest $contest) { // Check if the user is already a contestant in this contest. // If he is, redirect to submission page, else show signup form. $contestant = ContestContestant::s()->selectRow(null, array('contest_id' => $contest->getId(), 'user_id' => $this->getUser()->getId())); if ($contestant === false) { $this->getOutput()->redirect(SpecialPage::getTitleFor('ContestSignup', $contest->getField('name'))->getLocalURL()); } else { $contestant->setContest($contest); $this->showSubmissionPage($contestant); } }
/** * 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; }
protected function showEnabledPage(Contest $contest) { $out = $this->getOutput(); $alreadySignedup = $this->getUser()->isLoggedIn(); if ($alreadySignedup) { // Check if the user is already a contestant in this contest. // If he is, reirect to submission page, else show signup form. $alreadySignedup = ContestContestant::s()->selectRow('id', array('contest_id' => $contest->getId(), 'user_id' => $this->getUser()->getId())) !== false; } if ($alreadySignedup) { $out->redirect(SpecialPage::getTitleFor('MyContests', $contest->getField('name'))->getLocalURL()); } else { $out->setPageTitle($contest->getField('name')); $this->showIntro($contest); $this->showChallenges($contest); $this->showOpportunities($contest); $this->showRules($contest); $out->addModules('contest.special.welcome'); } }