/** * Assigns variables to the template engine. */ public function assignVariables() { // call assignVariables event EventHandler::fireAction($this, 'assignVariables'); // assign variables WCF::getTPL()->assign(array('isRegistered' => WCF::getUser()->userID > 0, 'canAddContest' => WCF::getUser()->getPermission('user.contest.canAddContest'), 'availableClasses' => $this->classList ? $this->classList->getObjects() : array(), 'availableJurys' => $this->juryList ? $this->juryList->getObjects() : array(), 'availableParticipants' => $this->participantList ? $this->participantList->getObjects() : array(), 'availableSponsors' => $this->sponsorList ? $this->sponsorList->getObjects() : array(), 'availablePrices' => $this->priceList ? $this->priceList->getObjects() : array(), 'availableTags' => MODULE_TAGGING ? $this->tagList->getObjects() : array(), 'latestEntries' => $this->latestEntryList ? $this->latestEntryList->getObjects() : array(), 'latestSolutions' => $this->latestSolutionList ? $this->latestSolutionList->getObjects() : array(), 'advertiseParticipant' => $this->advertiseParticipant, 'advertiseSponsor' => $this->advertiseSponsor, 'advertiseJury' => $this->advertiseJury)); }
/** * finish the contest */ public function close() { if (!($this->contest->state == 'scheduled' && $this->contest->untilTime < time())) { throw new Exception('contest needs to be scheduled, and time has to be over.'); } // make a jury instance from the contst owner $jury = ContestJury::find($this->contest->contestID, $this->contest->userID, $this->contest->groupID); if ($jury === null) { $jury = ContestJuryEditor::create($this->contest->contestID, $this->contest->userID, $this->contest->groupID, $state = 'accepted'); } $userID = $this->contest->userID; if ($userID == 0 && $this->contest->groupID > 0) { $sql = "SELECT userID\n\t\t\t\tFROM wcf" . WCF_N . "_user_to_groups\n\t\t\t\tWHERE groupID = " . intval($this->contest->groupID); $row = WCF::getDB()->getFirstRow($sql); $userID = $row['userID']; } if (!$userID) { throw new Exception('cannot determine a user from which the ratings will be added.'); } $classIDs = array_keys($this->contest->getClasses()); $ratingoptionIDs = array_keys(ContestRatingoption::getByClassIDs($classIDs)); if (empty($ratingoptionIDs)) { throw new Exception('cannot determine a ratingoption from classes [' . implode(',', $classIDs) . '] needed for contest ratings to be added.'); } // get interactions $interactionList = new ContestInteractionList($this->contest); $interactionList->sqlLimit = 0; $interactionList->readObjects(); $owners = $interactionList->getObjects(); foreach ($owners as $owner) { $this->sum += $owner->c; } // get prices $priceList = new ContestPriceList(); $priceList->sqlConditions .= 'contest_price.state = "accepted" AND contest_price.contestID = ' . intval($this->contest->contestID); $priceList->sqlLimit = 0; $priceList->readObjects(); $score = 5 + $priceList->countObjects(); foreach ($priceList->getObjects() as $price) { // choose a winner $owner = $this->chooseWinner($price, $owners); // error, there are more prices than participants if (!$owner) { throw new Exception('there are more prices than participants.'); } $lang = 'wcf.contest.interaction.tickets.solution'; $message = WCF::getLanguage()->getDynamicVariable($lang, array('tickets' => $owner->c)); // create pseudo solution $solution = ContestSolutionEditor::create($this->contest->contestID, $owner->participantID, $message, $state = 'accepted'); foreach ($ratingoptionIDs as $ratingOptionID) { // create pseudo rating $rating = ContestSolutionRatingEditor::create($solution->solutionID, $ratingOptionID, $score, $userID); } // decrease score $score--; } // close contest state $this->contest->getEditor()->updateState('closed'); }
/** * @see Form::assignVariables() */ public function assignVariables() { parent::assignVariables(); if ($this->success) { $l = 'wcf.contest.price.' . StringUtil::encodeHTML($this->success) . '.success'; WCF::getTPL()->append('userMessages', '<p class="success">' . WCF::getLanguage()->get($l) . '</p>'); } // display branding require_once WCF_DIR . 'lib/util/ContestUtil.class.php'; ContestUtil::assignVariablesBranding(); // save price position if ($this->entry->isOwner()) { require_once WCF_DIR . 'lib/form/ContestPricePositionForm.class.php'; new ContestPricePositionForm($this->entry); } // init form if ($this->action == 'edit') { require_once WCF_DIR . 'lib/form/ContestPriceEditForm.class.php'; new ContestPriceEditForm($this->entry); } else { if ($this->entry->isPriceable()) { require_once WCF_DIR . 'lib/form/ContestPriceAddForm.class.php'; new ContestPriceAddForm($this->entry); } } // become sponsor if ($this->entry->enableSponsorCheck && !$this->entry->isSponsor() && $this->entry->isSponsorable(false)) { WCF::getTPL()->append('additionalContentBecomeSponsor', '<p class="info">' . WCF::getLanguage()->get('wcf.contest.enableSponsorCheck.info') . '</p>'); } // if contest is finished, show todo list // who is able to pick the prices $isWinner = false; if ($this->entry->state == 'closed') { // need winners require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionList.class.php'; $solutionList = new ContestSolutionList(); $solutionList->sqlConditions .= 'contest_solution.contestID = ' . intval($this->contestID); $solutionList->sqlLimit = $this->countItems(); $solutionList->readObjects(); $winners = array(); foreach ($solutionList->getObjects() as $solution) { $winners[] = $solution->participantID; $isWinner = $isWinner || $solution->isOwner(); } if (count($winners)) { // init todo list require_once WCF_DIR . 'lib/data/contest/price/todo/ContestPriceTodoList.class.php'; $this->todoList = new ContestPriceTodoList(); $this->todoList->sqlConditions .= ' contest_solution.participantID IN (' . implode(',', $winners) . ') AND contest_solution.contestID = ' . intval($this->contestID); $this->todoList->sqlOrderBy = 'FIND_IN_SET(contest_solution.participantID, \'' . implode(',', $winners) . '\')'; $this->todoList->sqlLimit = $this->countItems(); $this->todoList->readObjects(); } } // which price is pickable be the current user NOW? $solution = null; $didPick = false; if ($isWinner) { foreach ($this->priceList->getObjects() as $price) { if ($price->isPickable()) { $solution = $price->pickableByWinner(); break; } else { if ($price->isOwner()) { $didPick = true; } } } } else { if ($this->entry->state == 'scheduled' && $this->entry->untilTime > TIME_NOW) { WCF::getTPL()->append('userMessages', '<p class="info">' . WCF::getLanguage()->get('wcf.contest.price.closed.info') . '</p>'); } else { if ($this->entry->enablePricechoice) { WCF::getTPL()->append('userMessages', '<p class="info">' . WCF::getLanguage()->get('wcf.contest.price.pick.info') . '</p>'); } } } $this->sidebar->assignVariables(); WCF::getTPL()->assign(array('entry' => $this->entry, 'isSponsor' => $this->isSponsor, 'contestID' => $this->contestID, 'userID' => $this->entry->userID, 'solution' => $solution, 'isWinner' => $isWinner, 'didPick' => $didPick, 'prices' => $this->priceList->getObjects(), 'todos' => $this->todoList ? $this->todoList->getObjects() : array(), 'templateName' => $this->templateName, 'allowSpidersToIndexThisPage' => true, 'contestmenu' => ContestMenu::getInstance())); }
/** * when winners are not allowed to take the prices on their own, this is done automatically */ public function updatePricechoices() { require_once WCF_DIR . 'lib/data/contest/solution/ContestSolution.class.php'; // check if there are already solutions with prices $solutionIDs = array(); foreach (ContestSolution::getWinners($this->contestID) as $solution) { if ($solution->hasPrice()) { return; } $solutionIDs[] = $solution->solutionID; } require_once WCF_DIR . 'lib/data/contest/price/ContestPriceList.class.php'; $priceList = new ContestPriceList(); $priceList->sqlConditions .= 'contest_price.state = "accepted" AND contest_price.contestID = ' . intval($this->contestID); $priceList->sqlLimit = count($solutionIDs); $priceList->readObjects(); $i = 0; foreach ($priceList->getObjects() as $price) { $price->getEditor()->pick($solutionIDs[$i], $i + 1); $i++; } }