public function ajaxChangeStatusAction() { $applyId = Request::getPOST('apply-id'); $op = Request::getPOST('op'); if (!in_array($op, array(1, 2)) || empty($applyId)) { $this->renderError('参数错误!'); } $applyInfo = OjContestApplyInterface::getById(array('id' => $applyId)); if (empty($applyInfo)) { $this->renderError('报名信息不存在!'); } // 只能处理自己竞赛下的报名 $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1)); $contestHash = OjContestInterface::getList(array('where' => $where)); $contestHash = Arr::listToHash('id', $contestHash); $contestIds = array_keys($contestHash); if (!in_array($applyInfo['contest_id'], $contestIds)) { $this->renderError('你没有权限操作!'); } if ($op == 1 && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED || $op == 2 && $applyInfo['status'] == ContestVars::APPLY_REJECTED) { $msg = $op == 1 ? '已经通过!' : '已经拒绝!'; $this->renderError($msg); } if ($op == 1) { OjContestApplyInterface::accept(array('id' => $applyId)); } else { OjContestApplyInterface::reject(array('id' => $applyId)); } $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!'); $this->renderAjax(0); }
public function defaultAction() { $pageSize = 50; // 获取参数 $page = Pager::get(); $contestId = (int) Request::getGET('contest-id'); $status = (int) Request::getGET('status', -1); $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo) || $contestInfo['hidden'] || $contestInfo['type'] != ContestVars::TYPE_APPLY) { $this->renderError('竞赛不存在,或者竞赛不需要报名!'); } // 构建where $where = array(); $where[] = array('contest_id', '=', $contestId); if ($status != -1) { $where[] = array('status', '=', $status); } // 获取数据 $offset = ($page - 1) * $pageSize; $applyList = OjContestApplyInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset)); $allCount = OjContestApplyInterface::getCount($where); // userHash $userIds = array_unique(array_column($applyList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); // 缓存部分的html $html = array(); $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php'); $this->renderFramework(array('html' => $html, 'applyList' => $applyList, 'contestInfo' => $contestInfo, 'userHash' => $userHash), 'contest/apply_list.php'); }
public function ajaxApplyAction() { if (empty($this->loginUserInfo)) { $this->renderError('请登录!'); } $contestId = (int) Request::getPOST('contest-id'); $realName = trim(Request::getPOST('real-name')); $xuehao = trim(Request::getPOST('xuehao')); $xueyuan = (int) Request::getPOST('xueyuan'); $sex = (int) Request::getPOST('sex'); // 校验 if (empty($realName) || empty($xuehao) || empty($xueyuan) || empty($sex) || !array_key_exists($xueyuan, ContestVars::$XUEYUAN) || !in_array($sex, array(1, 2)) || mb_strlen($realName, 'utf8') < 2 || mb_strlen($realName, 'utf8') > 4) { $this->renderError('参数错误!'); } $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('比赛不存在!'); } if ($contestInfo['type'] != ContestVars::TYPE_APPLY) { $this->renderError('比赛不需要报名!'); } if ($contestInfo['end_time'] < time()) { $this->renderError('比赛已经结束!'); } $applyInfo = OjContestApplyInterface::getDetail(array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'])); if (!empty($applyInfo) && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED) { $this->renderError('报名已通过,无法修改!'); } $data = array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'], 'real_name' => $realName, 'xuehao' => $xuehao, 'xueyuan' => $xueyuan, 'sex' => $sex); OjContestApplyInterface::save($data); $this->renderAjax(0); }
public function defaultAction() { list($rankHash, $mat, $userHash) = OjContestInterface::getRankBoard(array('id' => $this->contestInfo['id'])); // 如果是报名,获取报名列表 $applyHash = array(); if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) { $where = array(array('contest_id', '=', $this->contestInfo['id'])); $applyHash = OjContestApplyInterface::getList(array('where' => $where)); $applyHash = Arr::listToHash('user_id', $applyHash); } $this->renderFramework(array('rankHash' => $rankHash, 'mat' => $mat, 'userHash' => $userHash, 'applyHash' => $applyHash), 'rank/list.php'); }
public function __construct() { parent::__construct(); // 校验登陆 if (empty($this->loginUserInfo)) { $this->login(); } // 获取$contestId $contestId = (int) Request::getREQUEST('contest-id', 0); if (empty($contestId)) { $this->render404('比赛ID不存在!'); } // 获取$contestInfo $this->contestInfo = OjContestInterface::getDetail(array('id' => $contestId)); if (empty($this->contestInfo) || $this->contestInfo['hidden']) { $this->render404('比赛不存在!'); } if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) { $this->applyInfo = OjContestApplyInterface::getDetail(array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'])); } // 管理员 $isOjAdmin = RootCommonInterface::allowed(array('user_id' => $this->loginUserInfo['id'], 'path' => '/hqoj/admin')); if ($isOjAdmin || $this->contestInfo['user_id'] == $this->loginUserInfo['id']) { $this->isContestAdmin = true; } // 如果未注册,未输入密码,比赛未开始,那么跳转到比赛首页 if (Router::$CONTROLLER != 'index') { if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) { if (empty($this->applyInfo) || $this->applyInfo['status'] != ContestVars::APPLY_ACCEPTED) { $this->setNotice('error', '您未通过报名!'); $url = '/?contest-id=' . $contestId; Url::redirect($url); } } else { if ($this->contestInfo['type'] == ContestVars::TYPE_PASSWORD) { if ($this->password != $this->contestInfo['password']) { $this->setNotice('error', '请输入密码!'); $url = '/?contest-id=' . $contestId; Url::redirect($url); } } } if (time() < $this->contestInfo['begin_time']) { $this->setNotice('error', '比赛未开始!'); $url = '/?contest-id=' . $contestId; Url::redirect($url); } } $this->view->assign(array('contestInfo' => $this->contestInfo, 'applyInfo' => $this->applyInfo, 'password' => $this->password, 'isContestAdmin' => $this->isContestAdmin)); }
public function ajaxChangeStatusAction() { $applyId = Request::getPOST('apply-id'); $op = Request::getPOST('op'); if (!in_array($op, array(1, 2)) || empty($applyId)) { $this->renderError('参数错误!'); } $applyInfo = OjContestApplyInterface::getById(array('id' => $applyId)); if (empty($applyInfo)) { $this->renderError('报名信息不存在!'); } if ($op == 1 && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED || $op == 2 && $applyInfo['status'] == ContestVars::APPLY_REJECTED) { $msg = $op == 1 ? '已经通过!' : '已经拒绝!'; $this->renderError($msg); } if ($op == 1) { OjContestApplyInterface::accept(array('id' => $applyId)); } else { OjContestApplyInterface::reject(array('id' => $applyId)); } $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!'); $this->renderAjax(0); }
public function defaultAction() { $pageSize = 15; // 获取参数 $username = Request::getGET('username'); $language = (int) Request::getGET('language', -1); $result = (int) Request::getGET('result', -1); $problemHash = Request::getGET('problem-hash'); $maxId = (int) Request::getGET('max-id', -1); $minId = (int) Request::getGET('min-id', -1); $globalId = array_search($problemHash, $this->contestInfo['problem_hash']); // 获取userInfo,username转换为userId $userInfo = array(); if (!empty($username)) { $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); } // 构建where $where = array(); $where[] = array('contest_id', '=', $this->contestInfo['id']); $where[] = array('hidden', '=', 0); $where[] = array('problem_global_id', 'IN', $this->contestInfo['global_ids']); if (!empty($username)) { $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0)); } if (!empty($globalId)) { $where[] = array('problem_global_id', '=', $globalId); } if ($language != -1) { $where[] = array('language', '=', $language); } if ($result != -1) { $where[] = array('result', '=', $result); } // 获取solutionList if ($maxId != -1) { $where[] = array('solution_id', '<=', $maxId); $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => array('id' => 'DESC'), 'limit' => $pageSize, 'include_contest' => true)); } else { if ($minId != -1) { $where[] = array('solution_id', '>=', $minId); $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => array('id' => 'ASC'), 'limit' => $pageSize, 'include_contest' => true)); $solutionList = array_reverse($solutionList, true); } else { $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => array('id' => 'DESC'), 'limit' => $pageSize, 'include_contest' => true)); } } // 获取userHash $userIds = array_unique(array_column($solutionList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); // 格式化solution foreach ($solutionList as &$solutionInfo) { $solutionInfo['permission'] = false; if ($this->isContestAdmin || $solutionInfo['user_id'] == $this->loginUserInfo['id']) { $solutionInfo['permission'] = true; } $solutionInfo['has_log'] = OjSolutionHelper::hasLog($solutionInfo); } // 如果是报名,获取报名列表 $applyHash = array(); if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) { $where = array(array('contest_id', '=', $this->contestInfo['id'])); $applyHash = OjContestApplyInterface::getList(array('where' => $where)); $applyHash = Arr::listToHash('user_id', $applyHash); } // 计算minId, maxId $minId = $maxId = 0; if (!empty($solutionList)) { $solutionIds = array_keys($solutionList); $maxId = $solutionIds[0]; $minId = end($solutionIds); } // 缓存html $html = array(); $html['pager'] = $this->view->fetch(array('renderMaxId' => $maxId, 'renderMinId' => $minId), 'widget/pager_status.php'); // render $this->renderFramework(array('userHash' => $userHash, 'solutionList' => $solutionList, 'html' => $html, 'applyHash' => $applyHash), 'status/list.php'); }