public function ajaxSubmitAction()
 {
     // 获取参数
     $language = (int) Request::getPOST('language');
     $code = Request::getPOST('code', '', true);
     $problemHash = Request::getPOST('problem-hash');
     $userId = $this->loginUserInfo['id'];
     $globalId = array_search($problemHash, $this->contestInfo['problem_hash']);
     if (empty($globalId)) {
         $this->renderError('竞赛中无此题!');
     }
     // 校验
     if (strlen($code) < 50 || strlen($code) > 65535) {
         $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!');
     }
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo) || $problemInfo['hidden']) {
         $this->renderError('题目不存在!');
     }
     if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) {
         $this->renderError('编译器不支持!');
     }
     if (OjSolutionInterface::submitAlready(array('user_id' => $userId))) {
         $this->renderError('提交频繁!');
     }
     // 非法字符判断
     if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) {
         if (false === iconv('UTF-8', 'GBK', $code)) {
             $this->renderError('代码中存在非法字符!');
         }
     }
     OjSolutionInterface::save(array('global_id' => $globalId, 'user_id' => $userId, 'language' => $language, 'source' => $code, 'contest_id' => $this->contestInfo['id']));
     $this->renderAjax(0);
 }
 public function ajaxAddProblemAction()
 {
     $setId = Request::getPOST('set-id');
     $remote = Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     // 默认题库
     Cookie::set('default_remote', $remote);
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if ($problemInfo['hidden']) {
         $this->renderError('无法添加隐藏的题目!');
     }
     $setInfo = OjProblemSetInterface::getById(array('id' => $setId));
     if (empty($setInfo)) {
         $this->renderError('专题不存在!');
     }
     // 属主验证
     if ($this->loginUserInfo['id'] != $setInfo['user_id']) {
         $this->renderError('你没有权限操作!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经在专题中!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjProblemSetInterface::addProblem(array('id' => $setId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功');
     $this->renderAjax(0);
 }
 public function ajaxAddProblemAction()
 {
     $problemJson = Request::getPOST('problem-json');
     $problemList = json_decode($problemJson);
     if (empty($problemList)) {
         $this->renderError('参数错误2!');
     }
     $dataList = array();
     foreach ($problemList as $problemInfo) {
         $problemInfo = (array) $problemInfo;
         // 如果title为空,那么不插入
         if (empty($problemInfo['problem_id']) || empty($problemInfo['problem_code']) || empty($problemInfo['title'])) {
             continue;
         }
         $data = array();
         $data['remote'] = $problemInfo['remote'];
         $data['problem_id'] = $problemInfo['problem_id'];
         $data['problem_code'] = $problemInfo['problem_code'];
         $data['title'] = $problemInfo['title'];
         $data['source'] = $problemInfo['source'];
         $data['user_id'] = $this->loginUserInfo['id'];
         $data['hidden'] = empty($data['title']) ? 1 : 0;
         $dataList[] = $data;
     }
     OjProblemInterface::insertAll($dataList);
     $this->renderAjax(0);
 }
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $status = (int) Request::getGET('status');
     // 构建where
     $where = array();
     $where[] = array('remote', '=', StatusVars::REMOTE_HQU);
     $where[] = array('user_id', '=', $this->loginUserInfo['id']);
     if (!empty($status) && $status != -1) {
         $where[] = array('hidden', '=', $status - 1);
     }
     // 获取数据
     $offset = ($page - 1) * $pageSize;
     $problemList = OjProblemInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjProblemInterface::getCount($where);
     $userIds = array_unique(array_column($problemList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 5), 'widget/pager.php');
     // 输出
     $this->renderFramework(array('problemList' => $problemList, 'userHash' => $userHash, 'html' => $html), 'setup/problem/list.php');
 }
 public function defaultAction()
 {
     // 获取参数
     $globalId = (int) Request::getGET('global-id');
     $problemId = Request::getGET('problem-id');
     $problemInfo = array();
     if (!empty($globalId)) {
         $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     } else {
         if (!empty($problemId)) {
             $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $problemId));
         }
     }
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     // 权限校验
     if ($problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限查看!');
     }
     if ($problemInfo['remote'] != StatusVars::REMOTE_HQU) {
         $this->renderError('你没有权限查看!');
     }
     $this->renderFramework(array('problemInfo' => $problemInfo), 'setup/problem/detail.php');
 }
 public function ajaxSubmitAction()
 {
     // 获取参数
     $globalId = Request::getPOST('global-id');
     $language = Request::getPOST('language');
     $code = Request::getPOST('code', '', true);
     // 校验
     if (strlen($code) < 50 || strlen($code) > 65535) {
         $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!');
     }
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) {
         $this->renderError('编译器不支持!');
     }
     // 非法字符判断
     if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) {
         if (false === iconv('UTF-8', 'GBK', $code)) {
             $this->renderError('代码中存在非法字符!');
         }
     }
     OjJudgeInterface::save(array('problem_id' => $problemInfo['problem_id'], 'language' => $language, 'source' => $code, 'user_id' => $this->loginUserInfo['id']));
     // judge
     $this->renderAjax(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);
 }
 public function defaultAction()
 {
     $pageSize = 100;
     // 获取参数
     $page = Pager::get();
     $remote = (int) Request::getGET('remote', 0);
     $keyword = Request::getGET('keyword');
     $searchType = (int) Request::getGET('search-type', 1);
     // 构建where
     $where = array();
     $where[] = array('remote', '=', $remote);
     $where[] = array('hidden', '=', 0);
     if (!empty($keyword)) {
         if ($searchType == 1) {
             $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('title', 'LIKE', "%{$keyword}%")));
         } else {
             if ($searchType == 2) {
                 $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('source', 'LIKE', "%{$keyword}%")));
             }
         }
     }
     // 获取数据
     $order = array('problem_code' => 'ASC');
     $offset = ($page - 1) * $pageSize;
     $problemList = OjProblemInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjProblemInterface::getCount($where);
     // 获取用户解决的题目
     $userSolution = array();
     if ($this->loginUserInfo) {
         $globalIds = array_column($problemList, 'id');
         $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('contest_id', '=', 0), array('problem_global_id', 'IN', $globalIds));
         $solutionList = OjSolutionInterface::getList(array('where' => $where));
         foreach ($solutionList as $solutionId => $solutionInfo) {
             $globalId = $solutionInfo['problem_global_id'];
             if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) {
                 $userSolution[$globalId] = $solutionInfo;
             }
         }
     }
     $userHash = array();
     if ($allCount > 0) {
         $userIds = array_unique(array_column($problemList, 'user_id'));
         $userHash = UserCommonInterface::getById(array('id' => $userIds));
     }
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 10), 'widget/pager.php');
     $tpl = $remote ? 'problem/list_remote.php' : 'problem/list.php';
     // 输出
     $this->renderFramework(array('html' => $html, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userHash' => $userHash), $tpl);
 }
 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);
 }
 public function ajaxRemoveProblemAction()
 {
     $contestId = (int) Request::getPOST('contest-id');
     $globalId = (int) Request::getPOST('global-id');
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     $contestInfo = OjContestInterface::getById(array('id' => $contestId));
     if (empty($contestInfo)) {
         $this->renderError('竞赛不存在!');
     }
     // 更新数据
     OjContestInterface::removeProblem(array('id' => $contestId, 'global_id' => $globalId));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '移除成功!');
     $this->renderAjax(0);
 }
Example #11
0
 public static function rejudge($id, $trans = null)
 {
     if (!empty($trans)) {
         $model = new OjJudgeModel($trans);
     } else {
         $model = new OjJudgeModel();
     }
     // 校验
     $judgeInfo = self::getById($id);
     if (empty($judgeInfo)) {
         throw new InterfaceException('judgeInfo不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $judgeInfo['problem_id']));
     // 更新
     $data = array('time_limit' => $problemInfo['time_limit'], 'memory_limit' => $problemInfo['memory_limit'], 'judge_time' => 0, 'result' => StatusVars::REJUDGE, 'time_cost' => 0, 'memory_cost' => 0, 'ce' => '', 're' => '', 'detail' => '');
     $affects = $model->updateById($id, $data);
     return $affects;
 }
 public function defaultAction()
 {
     // 获取参数
     $id = Request::getGET('global-id');
     // 校验题目
     $problemInfo = OjProblemInterface::getById(array('id' => $id));
     if (empty($problemInfo) || $problemInfo['hidden']) {
         $this->renderError('题目不存在!');
     }
     $remote = $problemInfo['remote'];
     $problemId = $problemInfo['problem_id'];
     $problemCode = $problemInfo['problem_code'];
     if ($remote) {
         $srcUrl = OjCommonHelper::getSrcUrl($remote, $problemId, $problemCode);
         $this->renderFramework(array('srcUrl' => $srcUrl, 'problemInfo' => $problemInfo), 'problem/detail_remote.php');
     } else {
         $this->renderFramework(array('problemInfo' => $problemInfo), 'problem/detail.php');
     }
 }
 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);
 }
 public function ajaxRejudgeAction()
 {
     // 获取参数
     $judgeId = Request::getPOST('judge-id');
     // 只能重判自己的solution
     $judgeInfo = OjJudgeInterface::getById(array('id' => $judgeId));
     if (empty($judgeInfo)) {
         $this->renderError('judgeInfo不存在!');
     }
     if ($judgeInfo['solution_id'] > 0 || $judgeInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判!');
     }
     // 获取题目
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $judgeInfo['problem_id']));
     if ($problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判他人的题目!');
     }
     // rejudge
     OjJudgeInterface::rejudge(array('id' => $judgeId));
     $this->renderAjax(0);
 }
 public function defaultAction()
 {
     // 获取参数
     $problemHash = Request::getGET('problem-hash');
     $globalId = array_search($problemHash, $this->contestInfo['problem_hash']);
     if (empty($globalId)) {
         $this->renderError('竞赛中无此题!');
     }
     // 获取题目
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     $remote = $problemInfo['remote'];
     $problemId = $problemInfo['problem_id'];
     $problemCode = $problemInfo['problem_code'];
     if ($remote) {
         $srcUrl = OjCommonHelper::getSrcUrl($remote, $problemId, $problemCode);
         $this->renderFramework(array('srcUrl' => $srcUrl, 'problemInfo' => $problemInfo), 'problem/detail_remote.php');
     } else {
         $this->renderFramework(array('problemInfo' => $problemInfo), 'problem/detail.php');
     }
 }
 public function defaultAction()
 {
     $setId = (int) Request::getGET('set-id');
     if (empty($setId)) {
         $this->renderError();
     }
     $setInfo = OjProblemSetInterface::getById(array('id' => $setId));
     if (empty($setInfo)) {
         $this->renderError();
     }
     if (!$this->isOjAdmin && $setInfo['hidden'] && $this->loginUserInfo['id'] != $setInfo['user_id']) {
         Cookie::delete('current_set');
         $this->renderError('您没有权限查看!');
     }
     // 设置当前的set
     Cookie::set('current_set', $setId);
     $problemJson = $setInfo['problem_set'];
     $globalIds = (array) json_decode($problemJson, true);
     // 按照$globalIds顺序
     $problemList = OjProblemInterface::getById(array('id' => $globalIds));
     // 获取用户解决的题目
     $userSolution = array();
     if ($this->loginUserInfo) {
         $where = array(array('problem_global_id', 'IN', $globalIds), array('user_id', '=', $this->loginUserInfo['id']));
         $solutionList = OjSolutionInterface::getList(array('where' => $where));
         foreach ($solutionList as $solutionInfo) {
             $globalId = $solutionInfo['problem_global_id'];
             if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) {
                 $userSolution[$globalId] = $solutionInfo;
             }
         }
     }
     // userInfo
     $userInfo = UserCommonInterface::getById(array('id' => $setInfo['user_id']));
     $this->renderFramework(array('setInfo' => $setInfo, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userInfo' => $userInfo), 'set/set_problem.php');
 }
 public static function getProblemHash($id)
 {
     $contestInfo = self::getDetail($id);
     if (empty($contestInfo)) {
         throw new InterfaceException('比赛不存在!');
     }
     // 获取problemList
     $globalIds = $contestInfo['global_ids'];
     $problemHash = OjProblemInterface::getById(array('id' => $globalIds));
     // 重置solved, submit
     foreach ($problemHash as &$problemInfo) {
         $problemInfo['contest_solved'] = $problemInfo['contest_submit'] = 0;
     }
     // 获取solutionList
     $field = 'id,user_id,problem_global_id,result';
     $where = array(array('contest_id', '=', $id), array('problem_global_id', 'IN', $globalIds));
     $order = array('id' => 'ASC');
     $solutionList = OjSolutionInterface::getList(array('field' => $field, 'where' => $where, 'order' => $order, 'include_contest' => true));
     // 计算solved, submit
     $userAccept = array();
     // 标记
     foreach ($solutionList as $solutionInfo) {
         $globalId = $solutionInfo['problem_global_id'];
         $userId = $solutionInfo['user_id'];
         $result = $solutionInfo['result'];
         $problemHash[$globalId]['contest_submit']++;
         if (!isset($userAccept[$userId])) {
             $userAccept[$userId] = array();
         }
         if (!isset($userAccept[$userId][$globalId]) && $result == StatusVars::ACCEPTED) {
             $userAccept[$userId][$globalId] = 1;
             $problemHash[$globalId]['contest_solved']++;
         }
     }
     return $problemHash;
 }
 public function ajaxUploadAction()
 {
     $problemId = Request::getPOST('problem-id');
     $fileList = Upload::getFileList('file');
     if (empty($fileList) || empty($problemId)) {
         $this->echoJson(1, '参数错误!');
     }
     // 校验权限
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $problemId));
     if (empty($problemInfo)) {
         $this->echoJson(1, '题目不存在!');
     }
     // 获取upload所有文件,并计算大小
     $dataUploadDir = '/home/judge/data/' . $problemId . '/upload/';
     if (false == ($handle = opendir($dataUploadDir))) {
         $this->echoJson(1, '打开upload文件夹失败!');
     }
     $uploadFileSize = 0;
     while (false !== ($filename = readdir($handle))) {
         $file = $dataUploadDir . '/' . $filename;
         if ($filename[0] == '.' || is_dir($file)) {
             continue;
         }
         $uploadFileSize += filesize($file);
     }
     closedir($handle);
     foreach ($fileList as $key => $fileInfo) {
         if (!preg_match('/^[A-Za-z0-9_\\.]{1,14}$/', $fileInfo['name'])) {
             $this->echoJson(1, '文件名必须是字母数字下划线组成,并且不能超过14个字符!');
             return;
         }
         $uploadFileSize += $fileInfo['size'];
     }
     if ($uploadFileSize > 5 * 1024 * 1024) {
         $this->echoJson(1, '上传目录空间限制5M,你已经超出范围啦!');
     }
     // 移动
     foreach ($fileList as $key => $fileInfo) {
         $path = '/home/judge/data/' . $problemId . '/upload/' . $fileInfo['name'];
         move_uploaded_file($fileInfo['tmp_name'], $path);
     }
     // 重新获取upload文件夹
     if (false == ($handle = opendir($dataUploadDir))) {
         $this->echoJson(1, '打开upload文件夹失败!');
     }
     $uploadFileList = array();
     while (false !== ($filename = readdir($handle))) {
         $file = $dataUploadDir . '/' . $filename;
         if ($filename[0] == '.' || is_dir($file)) {
             continue;
         }
         $fileInfo = array();
         $fileInfo['filename'] = $filename;
         //文件名,包含扩展名
         $fileInfo['datetime'] = date('Y-m-d H:i:s', filemtime($file));
         //文件最后修改时间
         $fileInfo['filesize'] = filesize($file);
         $uploadFileList[] = $fileInfo;
     }
     closedir($handle);
     // 排序
     function cmpFunc($a, $b)
     {
         return strcmp($a['filename'], $b['filename']);
     }
     usort($uploadFileList, 'cmpFunc');
     // 计算大小,并格式化
     $uploadFileSize = 0;
     foreach ($uploadFileList as $key => $fileInfo) {
         $uploadFileList[$key]['format'] = sprintf('%-14s %10d %s', $fileInfo['filename'], $fileInfo['filesize'], $fileInfo['datetime']);
         $uploadFileList[$key]['format'] = str_replace(' ', '&nbsp;', $uploadFileList[$key]['format']);
         $uploadFileSize += $uploadFileList[$key]['filesize'];
     }
     // 记录操作
     $dateTime = date('Y-m-d H:i:s', time());
     $history = "<p>{$dateTime} 管理员{$this->loginUserInfo['username']}批量上传了文件</p>";
     OjProblemInterface::auditHistory(array('problem_id' => $problemId, 'append_history' => $history));
     $this->echoJson(0, 'success', array('uploadFileList' => $uploadFileList, 'uploadFileSize' => $uploadFileSize));
 }
 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;
 }
 public static function addProblem($id, $remote, $problemCode)
 {
     $setInfo = self::getById($id);
     if (empty($setInfo)) {
         throw new InterfaceException('专题不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         throw new InterfaceException('题目不存在!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         return 0;
     }
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         throw new InterfaceException('题目数量达到上限!');
     }
     $globalIds[] = (int) $problemInfo['id'];
     $json = json_encode($globalIds);
     $model = new OjProblemSetModel();
     $data = array('problem_set' => $json);
     $affects = $model->updateById($id, $data);
     return $affects;
 }
 public function ajaxSetUserAction()
 {
     // 获取参数
     $globalId = Request::getPOST('global-id');
     $username = trim(Request::getPOST('username', ''));
     // 校验用户
     $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
     if (empty($userInfo)) {
         $this->renderError('用户不存在!');
     }
     // 校验problem
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     OjProblemInterface::setUser(array('id' => $globalId, 'username' => $username));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '设置成功!');
     $this->renderAjax(0);
 }