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); } }
/** * Query all challenge names we might need, * based on the queries conditions, and set them * to the challengeTitles field. * * @since 0.1 * * @param array $allConds */ protected function queryChallengeTitles(array $allConds) { $conds = array(); if (array_key_exists('contestant_contest_id', $allConds)) { $conds['contest_id'] = $allConds['contestant_contest_id']; } if (array_key_exists('contestant_challenge_id', $allConds)) { $conds['id'] = $allConds['contestant_challenge_id']; } foreach (ContestChallenge::s()->select(array('id', 'title'), $conds) as $challenge) { $this->challengeTitles[$challenge->getId()] = $challenge->getField('title'); } }
/** * Gets a list of contests that can be fed directly to the options field of * an HTMLForm radio input. * challenge title => challenge id * * @since 0.1 * * @param ContestContestant $contestant * * @return array */ protected function getChallengesList(ContestContestant $contestant) { $list = array(); $challenges = ContestChallenge::s()->select(array('id', 'title'), array('contest_id' => $contestant->getField('contest_id'))); foreach ($challenges as $challenge) { $list[$challenge->getField('title')] = $challenge->getId(); } return $list; }
/** * The UI keeps track of 'removed' challenges by storing them into a * hidden HTML input, pipe-separated. On submission, this method * takes this string and actually deletes them. * * @since 0.1 * * @param string $idString * * @return boolean Success indicator */ protected function removeDeletedChallenges($idString) { if ($idString == '') { return true; } if (!ContestSettings::get('contestDeletionEnabled')) { // Shouldn't get here (UI should prevent it) throw new MWException('Contest deletion is disabled', 'contestdeletiondisabled'); } return ContestChallenge::s()->delete(array('id' => explode('|', $idString))); }
/** * 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; }
/** * Gets the summary data. * Values are escaped. * * @since 0.1 * * @param ContestContestant $contestant * * @return array */ protected function getSummaryData(ContestContestant $contestant) { $stats = array(); $stats['id'] = htmlspecialchars($contestant->getField('id')); $stats['contest'] = htmlspecialchars($contestant->getContest()->getField('name')); $challengeTitles = ContestChallenge::getTitlesForIds($contestant->getField('challenge_id')); $stats['challenge'] = htmlspecialchars($challengeTitles[$contestant->getField('challenge_id')]); if ($contestant->getField('submission') === '') { $stats['submission'] = htmlspecialchars(wfMsg('contest-contestant-notsubmitted')); } else { $stats['submission'] = Html::element('a', array('href' => $contestant->getField('submission')), $contestant->getField('submission')); } $countries = ContestContestant::getCountries(); $stats['country'] = htmlspecialchars($countries[$contestant->getField('country')]); $stats['wmf'] = htmlspecialchars(wfMsg('contest-contestant-' . ($contestant->getField('wmf') ? 'yes' : 'no'))); $stats['volunteer'] = htmlspecialchars(wfMsg('contest-contestant-' . ($contestant->getField('volunteer') ? 'yes' : 'no'))); $stats['rating'] = htmlspecialchars(wfMsgExt('contest-contestant-rating', 'parsemag', $this->getLanguage()->formatNum($contestant->getField('rating') / 100), $this->getLanguage()->formatNum($contestant->getField('rating_count')))); $stats['comments'] = htmlspecialchars($this->getLanguage()->formatNum($contestant->getField('comments'))); return $stats; }
/** * Add the needed conditions to the provided array depending * on the filter options set. * * @since 0.2 * * @param array $conds */ protected function addRequestConditions(&$conds) { $req = $this->getRequest(); foreach (array('volunteer', 'wmf') as $field) { if (in_array($req->getSessionData('contestant-' . $field), array('yes', 'no'))) { $conds['contestant_' . $field] = $req->getSessionData('contestant-' . $field) == 'yes' ? 1 : 0; } } foreach (array('comments', 'rating_count') as $field) { if (in_array($req->getSessionData('contestant-' . $field), array('some', 'none'))) { if ($req->getSessionData('contestant-' . $field) == 'none') { $conds['contestant_' . $field] = 0; } else { $conds[] = 'contestant_' . $field . ' > 0'; } } } if ($req->getSessionData('contestant-challenge')) { $challenge = ContestChallenge::s()->selectRow('id', array('title' => $req->getSessionData('contestant-challenge'))); if ($challenge !== false) { $conds['contestant_challenge_id'] = $challenge->getField('id'); unset($conds['contestant_contest_id']); // Not needed because the challenge implies the context } } if (in_array($req->getSessionData('contestant-submission'), array('some', 'none'))) { if ($req->getSessionData('contestant-submission') == 'none') { $conds['contestant_submission'] = ''; } else { $conds[] = 'contestant_submission <> ""'; } } }