/** * @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_price.*,\n\t\t\t\t\tuser_table.username,\n\t\t\t\t\tuser_table.disableAvatar, \n\t\t\t\t\tuser_table.avatarID, \n\t\t\t\t\tuser_table.gravatar,\n\t\t\t\t\tgroup_table.groupName,\n\t\t\t\t\tcontest_sponsor.userID,\n\t\t\t\t\tcontest_sponsor.groupID,\n\t\t\t\t\tuser_table_winner.userID AS winner_userID,\n\t\t\t\t\tuser_table_winner.username AS winner_username,\n\t\t\t\t\tgroup_table_winner.groupID AS winner_groupID,\n\t\t\t\t\tgroup_table_winner.groupName AS winner_groupName,\n\t\t\t\t\tavatar_table_winner.avatarID AS winner_avatarID,\n\t\t\t\t\tavatar_table_winner.avatarCategoryID AS winner_avatarCategoryID,\n\t\t\t\t\tavatar_table_winner.avatarName AS winner_avatarName,\n\t\t\t\t\tavatar_table_winner.avatarExtension AS winner_avatarExtension,\n\t\t\t\t\tavatar_table_winner.width AS winner_width,\n\t\t\t\t\tavatar_table_winner.height AS winner_height\n\t\t\tFROM \t\twcf" . WCF_N . "_contest_price contest_price\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_contest_sponsor contest_sponsor\n\t\t\tON\t\t(contest_sponsor.sponsorID = contest_price.sponsorID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = contest_sponsor.userID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_group group_table\n\t\t\tON\t\t(group_table.groupID = contest_sponsor.groupID)\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\t\t\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_contest_solution contest_solution\n\t\t\tON\t\t(contest_solution.solutionID = contest_price.solutionID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_contest_participant contest_participant\n\t\t\tON\t\t(contest_participant.participantID = contest_solution.participantID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table_winner\n\t\t\tON\t\t(user_table_winner.userID = contest_participant.userID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_avatar avatar_table_winner\n\t\t\tON\t\t(avatar_table_winner.avatarID = user_table_winner.avatarID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_group group_table_winner\n\t\t\tON\t\t(group_table_winner.groupID = contest_participant.groupID)\n\t\t\t" . $this->sqlJoins . "\n\n\t\t\tWHERE (" . ContestPrice::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->prices[] = new ViewableContestPrice(null, $row); } }
/** * @see DatabaseObject::handleData() */ protected function handleData($data) { $winnerData = $ownerData = array(); foreach ($data as $key => $val) { if (strpos($key, 'winner_') === 0) { $winnerData[substr($key, strlen('winner_'))] = $val; } else { $ownerData[$key] = $val; } } $this->winner = new ContestOwner($winnerData, $winnerData['userID'], $winnerData['groupID']); $this->owner = new ContestOwner($ownerData, $ownerData['userID'], $ownerData['groupID']); parent::handleData($data); }
/** * @see DatabaseObjectList::countObjects() */ public function countObjects() { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_contest_price contest_price\n\n\t\t\tWHERE (" . ContestPrice::getStateConditions() . ")\n\t\t\t" . (!empty($this->sqlConditions) ? "AND " . $this->sqlConditions : ''); $row = WCF::getDB()->getFirstRow($sql); return $row['count']; }
/** * fills cache * * @param integer $contestID */ public static function getWinners($contestID) { if (isset(self::$winners[$contestID])) { return self::$winners[$contestID]; } // get ordered list of winners require_once WCF_DIR . 'lib/data/contest/solution/ContestSolutionList.class.php'; $solutionList = new ContestSolutionList(); $solutionList->debug = true; $solutionList->sqlConditions .= 'contest_solution.contestID = ' . intval($contestID); $solutionList->sqlLimit = ContestPrice::getMaxPosition($contestID); $solutionList->readObjects(); self::$winners[$contestID] = array(); foreach ($solutionList->getObjects() as $solution) { self::$winners[$contestID][] = $solution; } return self::$winners[$contestID]; }
/** * @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())); }