예제 #1
0
 public function ajaxAddAction()
 {
     $data = array('remote' => StatusVars::REMOTE_HQU, 'user_id' => $this->loginUserInfo['id']);
     OjProblemInterface::save($data);
     $msg = '你成功创建了题目,请记得编辑题目哦!';
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, $msg);
     $this->renderAjax(0);
 }
예제 #2
0
 public function ajaxAddAction()
 {
     // 判断用户可以创建的题目是否上限
     $where = array(array('remote', '=', StatusVars::REMOTE_HQU), array('user_id', '=', $this->loginUserInfo['id']), array('hidden', '=', 1));
     $count = OjProblemInterface::getCount($where);
     if ($count >= 20) {
         $this->renderError('你的私有题目达到上限(20题)!');
     }
     $data = array('remote' => StatusVars::REMOTE_HQU, 'user_id' => $this->loginUserInfo['id']);
     OjProblemInterface::save($data);
     $msg = '你成功创建了题目,请记得编辑题目哦!';
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, $msg);
     $this->renderAjax(0);
 }
예제 #3
0
 public function ajaxSubmitAction()
 {
     // 获取参数
     $globalId = (int) Request::getPOST('global-id');
     $title = trim(Request::getPOST('title'));
     $source = trim(Request::getPOST('source'));
     $timeLimit = max(1, Request::getPOST('time-limit'));
     $memoryLimit = max(32, Request::getPOST('memory-limit'));
     $description = Request::getPOST('description', '', true);
     $input = Request::getPOST('input', '', true);
     $output = Request::getPOST('output', '', true);
     $sampleInput = Request::getPOST('sample-input', '', true);
     $sampleOutput = Request::getPOST('sample-output', '', true);
     $hint = Request::getPOST('hint', '', true);
     if (!in_array($timeLimit, StatusVars::$TIME_LIMIT) || !in_array($memoryLimit, StatusVars::$MEMORY_LIMIT)) {
         $this->renderError('参数错误!');
     }
     // 校验
     if (mb_strlen($title, 'utf8') > 50) {
         $this->renderError('标题限制50个字以内!');
     }
     if (mb_strlen($source, 'utf8') > 50) {
         $this->renderError('来源限制50个字以内!');
     }
     // 校验problem
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo) || !$problemInfo['hidden'] || $problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有操作权限!');
     }
     // 更新
     $data = array('id' => $globalId, 'title' => $title, 'source' => str_replace(',', ',', $source), 'time_limit' => $timeLimit * 1000, 'memory_limit' => $memoryLimit * 1024, 'description' => $description, 'input' => $input, 'output' => $output, 'sample_input' => $sampleInput, 'sample_output' => $sampleOutput, 'hint' => $hint);
     OjProblemInterface::save($data);
     // 记录编辑历史
     if ($problemInfo['remote'] == StatusVars::REMOTE_HQU) {
         $dateTime = date('Y-m-d H:i:s', time());
         $history = "<p>{$dateTime} 用户{$this->loginUserInfo['username']}编辑了题目</p>";
         OjProblemInterface::auditHistory(array('problem_id' => $problemInfo['problem_id'], 'append_history' => $history));
     }
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '编辑成功!');
     $this->renderAjax(0);
 }
예제 #4
0
 private static function updateResult($id, $result, $trans = null)
 {
     $solutionInfo = self::getById($id);
     if (empty($solutionInfo)) {
         throw new InterfaceException('solution不存在!');
     }
     $innerTrans = $trans;
     if (null == $trans) {
         $innerTrans = new Trans(DbConfig::$SERVER_TRANS);
         $innerTrans->begin();
     }
     $solutionModel = new OjSolutionModel($innerTrans);
     $remote = $solutionInfo['remote'];
     $globalId = $solutionInfo['problem_global_id'];
     $userId = $solutionInfo['user_id'];
     $contestId = $solutionInfo['contest_id'];
     // 如果状态从 非AC -> AC,那么修改user表和problem表,竞赛状态下不改变
     if (0 == $contestId && $result == StatusVars::ACCEPTED && $solutionInfo['result'] != StatusVars::ACCEPTED) {
         // 判断是否没有AC过
         $where = array(array('problem_global_id', '=', $globalId), array('user_id', '=', $userId), array('result', '=', StatusVars::ACCEPTED), array('contest_id', '=', 0));
         $count = self::getCount($where);
         if (0 == $count) {
             $userInfo = UserCommonInterface::getById(array('id' => $userId));
             $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
             $remoteStr = strtolower(StatusVars::$REMOTE_SCHOOL[$remote]);
             UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'solved_all' => $userInfo['solved_all'] + 1, "solved_{$remoteStr}" => $userInfo["solved_{$remoteStr}"] + 1));
             OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $globalId, 'solved' => $problemInfo['solved'] + 1));
         }
     }
     // 如果状态从 AC -> 非AC,那么修改user表和problem表,竞赛状态下不改变
     if (0 == $contestId && $result != StatusVars::ACCEPTED && $solutionInfo['result'] == StatusVars::ACCEPTED) {
         // 判断是否只AC过一次
         $where = array(array('problem_global_id', '=', $globalId), array('user_id', '=', $userId), array('result', '=', StatusVars::ACCEPTED), array('contest_id', '=', 0));
         $count = self::getCount($where);
         if (1 == $count) {
             $userInfo = UserCommonInterface::getById(array('id' => $userId));
             $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
             $remoteStr = strtolower(StatusVars::$REMOTE_SCHOOL[$remote]);
             UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'solved_all' => $userInfo['solved_all'] - 1, "solved_{$remoteStr}" => $userInfo["solved_{$remoteStr}"] - 1));
             OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $globalId, 'solved' => $problemInfo['solved'] - 1));
         }
     }
     // 更新solution
     $affects = $solutionModel->updateById($id, array('result' => $result));
     if (null == $trans && null != $innerTrans) {
         // 没有外部事务,并且存在内部事务
         $innerTrans->commit();
     }
     return $affects;
 }