/** * 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 DatabaseObjectList::readObjects() */ public function readObjects() { $sql = "SELECT\t\t" . (!empty($this->sqlSelects) ? $this->sqlSelects . ',' : '') . "\n\t\t\t\t\tavatar_table.*,\n\t\t\t\t\tcontest_jury.*,\n\t\t\t\t\tgroup_table.groupName, \n\t\t\t\t\tuser_table.username\n\t\t\tFROM\t\twcf" . WCF_N . "_contest_jury contest_jury\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = contest_jury.userID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_avatar avatar_table\n\t\t\tON\t\t(avatar_table.avatarID = user_table.avatarID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_group group_table\n\t\t\tON\t\t(group_table.groupID = contest_jury.groupID)\n\t\t\t" . $this->sqlJoins . "\n\n\t\t\tWHERE (" . ContestJury::getStateConditions() . ")\n\t\t\t" . (!empty($this->sqlConditions) ? "AND " . $this->sqlConditions : '') . "\n\t\t\t" . (!empty($this->sqlOrderBy) ? "ORDER BY " . $this->sqlOrderBy : ''); $result = WCF::getDB()->sendQuery($sql, $this->sqlLimit, $this->sqlOffset); while ($row = WCF::getDB()->fetchArray($result)) { $this->jurys[] = new ViewableContestJury(null, $row); } }
/** * @see DatabaseObjectList::countObjects() */ public function countObjects() { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_contest_jury contest_jury\n\n\t\t\tWHERE (" . ContestJury::getStateConditions() . ")\n\t\t\t" . (!empty($this->sqlConditions) ? "AND " . $this->sqlConditions : ''); $row = WCF::getDB()->getFirstRow($sql); return $row['count']; }
/** * @see DatabaseObject::handleData() */ protected function handleData($data) { parent::handleData($data); $this->owner = new ContestOwner($data, $this->userID, $this->groupID); }
/** * returns all sidebar data in format, which can be cached */ protected function _init() { // get classes $classList = new ContestClassTree(); $classList->readObjects(); // get jurys if (!$this->contest || $this->contest->isEnabledJury()) { $juryList = new ContestJuryList(); if ($this->contest !== null) { $juryList->sqlConditions .= 'contest_jury.contestID = ' . $this->contest->contestID . ' AND contest_jury.state = "accepted" '; } else { $juryList->sqlJoins .= " INNER JOIN wcf" . WCF_N . "_contest contest ON contest.contestID = contest_jury.contestID "; $juryList->sqlConditions .= 'contest.state IN ("scheduled", "closed") AND contest_jury.state = "accepted" '; } $juryList->sqlOrderBy = 'juryID DESC'; $juryList->readObjects(); } else { $juryList = null; } // get participants $participantList = new ContestParticipantList(); if ($this->contest !== null) { $participantList->sqlConditions .= 'contest_participant.contestID = ' . $this->contest->contestID . ' AND contest_participant.state = "accepted" '; } else { $participantList->sqlJoins .= " INNER JOIN wcf" . WCF_N . "_contest contest ON contest.contestID = contest_participant.contestID "; $participantList->sqlConditions .= 'contest.state IN ("scheduled", "closed") AND contest_participant.state = "accepted" '; } $participantList->sqlLimit = 10; $participantList->sqlOrderBy = 'participantID DESC'; $participantList->readObjects(); // get sponsors $sponsorList = new ContestSponsorList(); if ($this->contest !== null) { $sponsorList->sqlConditions .= 'contest_sponsor.contestID = ' . $this->contest->contestID . ' AND contest_sponsor.state = "accepted" '; } else { $sponsorList->sqlJoins .= " INNER JOIN wcf" . WCF_N . "_contest contest ON contest.contestID = contest_sponsor.contestID "; $sponsorList->sqlConditions .= 'contest.state IN ("scheduled", "closed") AND contest_sponsor.state = "accepted" '; } $sponsorList->sqlOrderBy = 'sponsorID DESC'; $sponsorList->readObjects(); // get prices $priceList = new ContestPriceList(); if ($this->contest !== null) { $priceList->sqlConditions .= 'contest_price.contestID = ' . $this->contest->contestID . ' AND contest_price.state != "declined" '; } else { $priceList->sqlJoins .= " INNER JOIN wcf" . WCF_N . "_contest contest ON contest.contestID = contest_price.contestID "; $priceList->sqlConditions .= 'contest.state IN ("scheduled", "closed") AND contest_price.state != "declined" '; } $priceList->sqlOrderBy = 'position ASC'; $priceList->readObjects(); // get tag cloud $tagList = null; if (MODULE_TAGGING) { $tagList = new ContestTagList($this->contest, WCF::getSession()->getVisibleLanguageIDArray()); $tagList->readObjects(); } // get latest entries $latestEntryList = new ContestList(); if ($this->contest !== null) { $latestEntryList->sqlConditions .= 'contest.contestID != ' . $this->contest->contestID; } $latestEntryList->sqlLimit = 10; $latestEntryList->readObjects(); // get latest solutions if (!$this->contest || $this->contest->enableSolution) { $latestSolutionList = new ContestSolutionList(); if ($this->contest !== null) { $latestSolutionList->sqlConditions .= 'contest_solution.contestID = ' . $this->contest->contestID; } $latestSolutionList->sqlOrderBy = 'solutionID DESC'; $latestSolutionList->sqlLimit = 5; $latestSolutionList->readObjects(); } else { $latestSolutionList = null; } return array('classList' => $classList, 'juryList' => $juryList, 'participantList' => $participantList, 'sponsorList' => $sponsorList, 'priceList' => $priceList, 'tagList' => $tagList, 'latestEntryList' => $latestEntryList, 'latestSolutionList' => $latestSolutionList); }