本文整理汇总了PHP中Contest类的典型用法代码示例。如果您正苦于以下问题:PHP Contest类的具体用法?PHP Contest怎么用?PHP Contest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Contest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContest
static function createContest($data)
{
require_once "common.php";
$data = Filter::filterArray($data);
$c = new Contest($data);
$c->save();
return $c;
}
示例2: readParameters
/**
* @see Action::readParameters()
*/
public function readParameters()
{
parent::readParameters();
if (!MODULE_CONTEST) {
throw new IllegalLinkException();
}
$this->contestID = intval($_REQUEST['contestID']);
if (isset($_REQUEST['contestAction'])) {
$this->contestAction = $_REQUEST['contestAction'];
}
$this->contest = new Contest($this->contestID);
if (!$this->contest->isViewable()) {
throw new IllegalLinkException();
}
}
示例3: assignVariables
/**
* @see Form::assignVariables()
*/
public function assignVariables()
{
parent::assignVariables();
// display branding
require_once WCF_DIR . 'lib/util/ContestUtil.class.php';
ContestUtil::assignVariablesBranding();
// save ratings
if ($this->solutionObj->isRateable()) {
require_once WCF_DIR . 'lib/form/ContestSolutionRatingUpdateForm.class.php';
new ContestSolutionRatingUpdateForm($this->solutionObj);
}
// init form
if ($this->action == 'edit') {
require_once WCF_DIR . 'lib/form/ContestSolutionCommentEditForm.class.php';
new ContestSolutionCommentEditForm($this->solutionObj);
} else {
if ($this->entry->isCommentable()) {
require_once WCF_DIR . 'lib/form/ContestSolutionCommentAddForm.class.php';
new ContestSolutionCommentAddForm($this->solutionObj);
}
}
if (!$this->entry->enableOpenSolution && $this->entry->state != 'closed' && ($this->entry->state != 'scheduled' || !($this->entry->fromTime < TIME_NOW && TIME_NOW < $this->entry->untilTime))) {
WCF::getTPL()->append('userMessages', '<p class="info">' . WCF::getLanguage()->get('wcf.contest.enableOpenSolution.info') . '</p>');
}
if ($this->entry->enableParticipantCheck) {
WCF::getTPL()->append('userMessages', '<p class="info">' . WCF::getLanguage()->get('wcf.contest.enableParticipantCheck.info') . '</p>');
}
$this->sidebar->assignVariables();
WCF::getTPL()->assign(array('entry' => $this->entry, 'solutionObj' => $this->solutionObj, 'contestID' => $this->contestID, 'solutionID' => $this->solutionID, 'userID' => $this->entry->userID, 'comments' => $this->commentList->getObjects(), 'ratings' => $this->ratingList->getObjects(), 'todos' => $this->todoList ? $this->todoList->getObjects() : array(), 'templateName' => $this->templateName, 'allowSpidersToIndexThisPage' => true, 'attachments' => $this->attachments, 'contestmenu' => ContestMenu::getInstance()));
}
示例4: actionShow
public function actionShow($id)
{
$model = Contest::model()->findByPk((int) $id);
if (is_null($model)) {
throw new CHttpException(404, Yii::t('contest', 'Страница не найдена!'));
}
$image = new Image();
if (Yii::app()->request->isPostRequest && isset($_POST['Image'])) {
$transaction = Yii::app()->db->beginTransaction();
try {
$image = $image->create($_POST['Image']);
if (!$image->hasErrors()) {
if ($model->addImage($image)) {
Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('contest', 'Фотография добавлена!'));
}
$transaction->commit();
$this->redirect(array('/contest/contest/show/', 'id' => $model->id));
}
throw new CDbException(Yii::t('contest', 'При добавлении изображения произошла ошибка!'));
} catch (Exception $e) {
$transaction->rollback();
Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('contest', $e->getMessage()));
}
}
$dataProvider = new CActiveDataProvider('ImageToContest', array('criteria' => array('condition' => 'contest_id = :contest_id', 'params' => array(':contest_id' => $model->id), 'limit' => self::CONTEST_PER_PAGE, 'order' => 't.creation_date DESC', 'with' => 'image'), 'pagination' => array('pageSize' => self::CONTEST_PER_PAGE)));
$this->render('show', array('image' => $image, 'dataProvider' => $dataProvider, 'model' => $model));
}
示例5: actionStats
public function actionStats($id)
{
if (!($model = Contest::model()->with(array('fields'))->findByPk($id))) {
throw new CHttpException(404, 'The requested page does not exist.');
}
$this->render('stats', array('model' => $model));
}
示例6: getRecipients
/**
* @see ContestNotificationInterface::getRecipients()
*/
public function getRecipients()
{
$ids = array();
switch ($this->state) {
// tell contest owner that s.o. did apply
case 'applied':
require_once WCF_DIR . 'lib/data/contest/Contest.class.php';
$contest = Contest::getInstance($this->contestID);
$ids = array_merge($ids, $contest->getOwner()->getUserIDs());
break;
case 'invited':
$ids = array_merge($ids, $this->getInstance()->getOwner()->getUserIDs());
break;
// tell recipient that s.o. did moderator interaction
// tell recipient that s.o. did moderator interaction
case 'accepted':
$ids = array_merge($ids, $this->getInstance()->getOwner()->getUserIDs());
// maybe the user applied himself, then tell the owners
require_once WCF_DIR . 'lib/data/contest/Contest.class.php';
$contest = Contest::getInstance($this->contestID);
if ($contest->enableSponsorCheck == false) {
$ids = array_merge($ids, $contest->getOwner()->getUserIDs());
}
break;
}
return array_unique($ids);
}
示例7: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Contest::create([]);
}
}
示例8: Insert
public function Insert(Contest $data)
{
try {
$query = "INSERT INTO Concursos (id_type, name, question, initial_date, final_date, winner, active)\n VALUES (?, ?, ?, ?, ?, ?, ?)";
$this->pdo->prepare($query)->execute(array($data->__GET('id_type'), $data->__GET('name'), $data->__GET('question'), $data->__GET('initial_date'), $data->__GET('final_date'), $data->__GET('winner'), $data->__GET('active')));
} catch (Exception $e) {
die($e->getMessage());
}
}
示例9: close
/**
* 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');
}
示例10: execute
public function execute()
{
if (!ContestSettings::get('contestDeletionEnabled')) {
$this->dieUsage('Contest deletion is disabled', 'contestdeletiondisabled');
}
global $wgUser;
if (!$wgUser->isAllowed('contestadmin') || $wgUser->isBlocked()) {
$this->dieUsageMsg(array('badaccess-groups'));
}
$params = $this->extractRequestParams();
$everythingOk = true;
foreach ($params['ids'] as $id) {
$contest = new Contest(array('id' => $id));
$everythingOk = $contest->removeAllFromDB() && $everythingOk;
}
$this->getResult()->addValue(null, 'success', $everythingOk);
}
示例11: readObjects
/**
* @see DatabaseObjectList::readObjects()
*/
public function readObjects()
{
$sql = "SELECT\t\t" . (!empty($this->sqlSelects) ? $this->sqlSelects . ',' : '') . "\n\t\t\t\t\tuser_table.username, contest.*\n\t\t\tFROM\t\twcf" . WCF_N . "_contest contest\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = contest.userID)\n\t\t\t" . $this->sqlJoins . "\n\t\t\t" . (!empty($this->sqlConditions) ? "WHERE (" . $this->sqlConditions . ")" : '') . "\n\t\t\tAND (" . Contest::getStateConditions() . ")\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->entries[] = new ContestFeedEntry(null, $row);
}
}
示例12: isDeletable
/**
* Returns true, if the active user can delete this entry.
*
* @return boolean
*/
public function isDeletable()
{
$contest = Contest::getInstance($this->contestID);
if ($contest->isOwner()) {
return true;
}
return false;
}
示例13: getStates
/**
* returns available states
*/
protected function getStates()
{
$flags = (!isset($this->entry) || $this->entry->isOwner() ? ContestState::FLAG_USER : 0) + ($this->contest->isOwner() ? ContestState::FLAG_CONTESTOWNER : 0) + (ContestCrew::isMember() ? ContestState::FLAG_CREW : 0);
if (isset($this->entry) && $this->entry->enableOpenSolution) {
$flags += ContestSolutionEditor::FLAG_OPENSOLUTION;
}
return ContestSolutionEditor::getStates(isset($this->entry) ? $this->entry->state : '', $flags);
}
示例14: readObjects
/**
* @see DatabaseObjectList::readObjects()
*/
public function readObjects()
{
$sql = "SELECT\t\t" . (!empty($this->sqlSelects) ? $this->sqlSelects . ',' : '') . "\n\t\t\t\t\tcontest.*\n\t\t\tFROM\t\twcf" . WCF_N . "_contest contest\n\t\t\t" . $this->sqlJoins . "\n\n\t\t\tWHERE\t\t(" . Contest::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->entries[] = new Contest(null, $row);
}
}
示例15: readParameters
/**
* @see Page::readParameters()
*/
public function readParameters()
{
parent::readParameters();
// get entry
if (isset($_REQUEST['contestID'])) {
$this->contestID = intval($_REQUEST['contestID']);
}
$this->entry = new ViewableContest($this->contestID);
if (!$this->entry->isViewable()) {
throw new IllegalLinkException();
}
// validation
if ($this->entry->enableInteraction == 0) {
throw new Exception('invalid contest type');
}
// init price list
$this->interactionList = new ContestInteractionList($this->entry);
}