本文整理汇总了PHP中Problem::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Problem::getId方法的具体用法?PHP Problem::getId怎么用?PHP Problem::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Problem
的用法示例。
在下文中一共展示了Problem::getId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submit
public function submit($problem_id)
{
try {
$problem = new Problem($problem_id);
$language = fRequest::get('language', 'integer');
if (!array_key_exists($language, static::$languages)) {
throw new fValidationException('Invalid language.');
}
fSession::set('last_language', $language);
$code = trim(fRequest::get('code', 'string'));
if (strlen($code) == 0) {
throw new fValidationException('Code cannot be empty.');
}
if ($problem->isSecretNow()) {
if (!User::can('view-any-problem')) {
throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.');
}
}
$record = new Record();
$record->setOwner(fAuthorization::getUserToken());
$record->setProblemId($problem->getId());
$record->setSubmitCode($code);
$record->setCodeLanguage($language);
$record->setSubmitDatetime(Util::currentTime());
$record->setJudgeStatus(JudgeStatus::PENDING);
$record->setJudgeMessage('Judging... PROB=' . $problem->getId() . ' LANG=' . static::$languages[$language]);
$record->setVerdict(Verdict::UNKNOWN);
$record->store();
Util::redirect('/status');
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('code', '/submit', fRequest::get('code', 'string'));
Util::redirect("/submit?problem={$problem_id}");
}
}
示例2: newQuestion
public function newQuestion($id)
{
try {
$report = new Report($id);
if (!$report->allowQuestion()) {
throw new fValidationException('Not allowed to ask question.');
}
$category = fRequest::get('category', 'integer');
if ($category == 0) {
throw new fValidationException('Please choose a category.');
}
$question = new Question();
$question->setUsername(fAuthorization::getUserToken());
$question->setReportId($report->getId());
if ($category < 0) {
$question->setCategory($category);
} else {
$question->setCategory(Question::ABOUT_PROBLEM_HIDDEN);
$problem = new Problem($category);
$question->setProblemId($problem->getId());
}
$question->setAskTime(new fTimestamp());
$question->setQuestion(trim(fRequest::get('question')));
if (strlen($question->getQuestion()) < 10) {
throw new fValidationException('Question too short (minimum 10 bytes).');
}
if (strlen($question->getQuestion()) > 500) {
throw new fValidationException('Question too long (maximum 500 bytes).');
}
$question->store();
fMessaging::create('success', 'Question saved.');
} catch (fExpectedException $e) {
fMessaging::create('warning', $e->getMessage());
} catch (fUnexpectedException $e) {
fMessaging::create('error', $e->getMessage());
}
Util::redirect("/contest/{$id}");
}