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');
 }
Ejemplo n.º 2
0
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $status = (int) Request::getGET('status');
     // 构建where
     $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1));
     if (!empty($status) && $status != -1) {
         $where[] = array('hidden', '=', $status - 1);
     }
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     // 获取数据
     $offset = ($page - 1) * $pageSize;
     $contestList = OjContestInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = 0;
     if (!empty($contestList)) {
         $allCount = OjContestInterface::getCount($where);
     }
     $userIds = array_unique(array_column($contestList, '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('contestList' => $contestList, 'userHash' => $userHash, 'html' => $html), 'setup/contest/list.php');
 }
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $status = (int) Request::getGET('status', -1);
     $contestId = (int) Request::getGET('contest-id', 0);
     $where = array();
     $where[] = array('is_diy', '=', 0);
     if (!empty($contestId)) {
         $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 = 0;
     $userHash = array();
     $contestHash = array();
     if (!empty($applyList)) {
         $allCount = OjContestApplyInterface::getCount($where);
         $userIds = array_column($applyList, 'user_id');
         $userHash = UserCommonInterface::getById(array('id' => $userIds));
         $contestIds = array_unique(array_column($applyList, 'contest_id'));
         $contestHash = OjContestInterface::getById(array('id' => $contestIds));
     }
     // 缓存部分的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, 'contestHash' => $contestHash, 'userHash' => $userHash), 'contest/apply_list.php');
 }
Ejemplo n.º 4
0
 public static function save($data, $id = 0)
 {
     $model = new RootManagerModel();
     if (0 == $id) {
         // 插入
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $data['login_name']));
         if (empty($userInfo)) {
             throw new InterfaceException('用户不存在!');
         }
         // 不允许重复添加
         $managerInfo = self::getByField('user_id', $userInfo['id']);
         if (!empty($managerInfo)) {
             throw new InterfaceException("用户 {$data['login_name']} 已经是管理员!");
         }
         $insertData = array('user_id' => $userInfo['id'], 'forbidden' => 0);
         $id = $model->insert($insertData);
         // enable缓存
         $redis = RedisClient::getInstance(RedisConfig::$SERVER_COMMON);
         $key = RedisKeys::ROOT_ENABLED_HASH;
         $redis->hSet($key, $userInfo['id'], $id);
         return $id;
     } else {
         // 更新
         $updateData = $data;
         $affects = $model->updateById($id, $updateData);
         return $affects;
     }
 }
Ejemplo n.º 5
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()
 {
     $pageSize = 15;
     $problemId = Request::getGET('problem-id');
     $language = (int) Request::getGET('language', -1);
     $result = (int) Request::getGET('result', -1);
     // 获取id
     $maxId = (int) Request::getGET('max-id', -1);
     $minId = (int) Request::getGET('min-id', -1);
     // 获取用户创建的所有题目
     $where = array(array('remote', '=', StatusVars::REMOTE_HQU), array('user_id', '=', $this->loginUserInfo['id']));
     $problemList = OjProblemInterface::getList(array('field' => 'problem_id', 'where' => $where));
     $problemIds = array_column($problemList, 'problem_id');
     // 构建where
     $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('solution_id', '=', 0), array('problem_id', 'IN', $problemIds));
     if (!empty($problemId)) {
         // HQOJ上的题目,problem_code和problem_id相同
         $where[] = array('problem_id', '=', $problemId);
     }
     if ($language != -1) {
         $where[] = array('language', '=', $language);
     }
     if ($result != -1) {
         $where[] = array('result', '=', $result);
     }
     // 获取judgeList
     if ($maxId != -1) {
         $where[] = array('id', '<=', $maxId);
         $judgeList = OjJudgeInterface::getList(array('where' => $where, 'order' => array('id' => 'DESC'), 'limit' => $pageSize));
     } else {
         if ($minId != -1) {
             $where[] = array('id', '>=', $minId);
             $judgeList = OjJudgeInterface::getList(array('where' => $where, 'order' => array('id' => 'ASC'), 'limit' => $pageSize));
             $judgeList = array_reverse($judgeList, true);
         } else {
             $judgeList = OjJudgeInterface::getList(array('where' => $where, 'order' => array('id' => 'DESC'), 'limit' => $pageSize));
         }
     }
     // 获取userHash
     $userIds = array_unique(array_column($judgeList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 格式化solution
     foreach ($judgeList as &$judgeInfo) {
         $text = StatusVars::$RESULT_FORMAT[$judgeInfo['result']];
         $class = StatusVars::$RESULT_CLASS[$judgeInfo['result']];
         $judgeInfo['result_html'] = sprintf('<span class="%s">%s</span>', $class, $text);
     }
     // 计算minId, maxId
     $minId = $maxId = 0;
     if (!empty($judgeList)) {
         $judgeIds = array_keys($judgeList);
         $maxId = $judgeIds[0];
         $minId = end($judgeIds);
     }
     // 缓存html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderMaxId' => $maxId, 'renderMinId' => $minId), 'widget/pager_status.php');
     // render
     $this->renderFramework(array('userHash' => $userHash, 'judgeList' => $judgeList, 'html' => $html), 'setup/problem/judge_list.php');
 }
Ejemplo n.º 7
0
 public function defaultAction()
 {
     $pageSize = 50;
     $page = Pager::get();
     $category = (int) Request::getGET('category', -1);
     $title = trim(Request::getGET('title', ''));
     $username = trim(Request::getGET('username', ''));
     $where = array();
     if ($category != -1) {
         $where[] = array('category', '=', $category);
     }
     if (!empty($username)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
         $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0));
     }
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     if ($category != -1) {
         $order = array('hidden' => 'ASC', 'title' => 'ASC', 'id' => 'DESC');
     } else {
         $order = array('id' => 'DESC');
     }
     $offset = ($page - 1) * $pageSize;
     $docList = DocInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = empty($docList) ? 0 : DocInterface::getCount($where);
     $userIds = array_unique(array_column($docList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 7), 'widget/pager.php');
     $this->renderFramework(array('html' => $html, 'docList' => $docList, 'userHash' => $userHash), 'doc/list.php');
 }
Ejemplo n.º 8
0
 public function iframeRemoveAction()
 {
     $managerId = Request::getGET('manager-id', 0);
     $managerInfo = RootManagerInterface::getById(array('id' => $managerId));
     if (empty($managerInfo)) {
         $this->renderIframeError('管理员不存在!');
     }
     $userInfo = UserCommonInterface::getById(array('id' => $managerInfo['user_id']));
     $this->renderIframe(array('userInfo' => $userInfo), 'manager/iframe/remove_path.php');
 }
Ejemplo n.º 9
0
 public function defaultAction()
 {
     $docId = (int) Request::getGET('doc-id');
     $docInfo = DocInterface::getById(array('id' => $docId));
     if (empty($docInfo)) {
         $this->renderError();
     }
     $userInfo = UserCommonInterface::getById(array('id' => $docInfo['user_id']));
     $this->renderFramework(array('docInfo' => $docInfo, 'userInfo' => $userInfo), 'doc/detail.php');
 }
Ejemplo n.º 10
0
 protected function __construct()
 {
     $dir = PROJECT_PATH . '/template';
     $this->view = new View($dir);
     // 设置html属性
     $this->setTitle();
     $this->setMeta();
     // 获取登陆用户
     $this->loginUserInfo = UserCommonInterface::getLoginUserInfo();
     $this->view->assign(array('loginUserInfo' => $this->loginUserInfo));
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 public function defaultAction()
 {
     $pageSize = 25;
     $page = Pager::get();
     $order = array('solved_all' => 'DESC', 'submit_all' => 'DESC', 'id' => 'ASC');
     $offset = ($page - 1) * $pageSize;
     $userList = UserCommonInterface::getList(array('order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = UserCommonInterface::getCount();
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 10), 'widget/pager.php');
     // 输出
     $this->renderFramework(array('userList' => $userList, 'html' => $html, 'beginRank' => $offset + 1), 'rank/list.php');
 }
Ejemplo n.º 13
0
 public function defaultAction()
 {
     // 如果已经选定专题,那么跳转
     if (Request::getGET('from') == 'nav') {
         $setId = (int) Cookie::get('current_set');
         if ($setId) {
             $url = '/set_problem/?set-id=' . $setId;
             Url::redirect($url);
         }
     }
     Cookie::delete('current_set');
     $pageSize = 50;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $username = Request::getGET('username');
     // 构建where
     $where = array();
     $where[] = array('hidden', '=', 0);
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     if (!empty($username)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
         $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0));
     }
     // 获取列表
     $order = array('listing_status' => 'DESC', 'refresh_at' => 'DESC', 'id' => 'DESC');
     $offset = ($page - 1) * $pageSize;
     $setList = OjProblemSetInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjProblemSetInterface::getCount($where);
     foreach ($setList as &$setInfo) {
         $problemJson = $setInfo['problem_set'];
         $globalIds = json_decode($problemJson, true);
         $setInfo['count'] = count($globalIds);
     }
     // 获取用户
     $userHash = array();
     if (!empty($setList)) {
         $userIds = array_unique(array_column($setList, '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, 'setList' => $setList, 'userHash' => $userHash), 'set/list.php');
 }
Ejemplo n.º 14
0
 public function defaultAction()
 {
     $pageSize = 50;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $status = (int) Request::getGET('status');
     $username = Request::getGET('username');
     // userInfo
     $userInfo = array();
     if (!empty($username)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
     }
     // 构建where
     if (!empty($username) && empty($userInfo)) {
         $where = false;
     } else {
         $where = array();
         if (!empty($userInfo)) {
             $where[] = array('user_id', '=', $userInfo['id']);
         }
         if (!empty($status) && $status != -1) {
             $where[] = array('hidden', '=', $status - 1);
         }
         if (!empty($title)) {
             $where[] = array('title', 'LIKE', "%{$title}%");
         }
     }
     $order = array('listing_status' => 'DESC', 'refresh_at' => 'DESC', 'id' => 'DESC');
     $offset = ($page - 1) * $pageSize;
     $setList = OjProblemSetInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = 0;
     if (!empty($setList)) {
         $allCount = OjProblemSetInterface::getCount($where);
     }
     foreach ($setList as &$setInfo) {
         $globalIds = (array) json_decode($setInfo['problem_set'], true);
         $setInfo['count'] = count($globalIds);
     }
     // 获取用户
     $userIds = array_unique(array_column($setList, '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, 'setList' => $setList, 'userHash' => $userHash), 'set/list.php');
 }
Ejemplo n.º 15
0
 public function iframeShowAction()
 {
     $solutionId = (int) Request::getGET('solution-id');
     $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId));
     if (empty($solutionInfo) || false == OjSolutionHelper::hasLog($solutionInfo)) {
         $this->renderError();
     }
     // 获取属主
     $userId = $solutionInfo['user_id'];
     $userInfo = UserCommonInterface::getById(array('id' => $userId));
     // 是否有权限查看,竞赛管理员,自己的solution
     if (!$this->isContestAdmin && $solutionInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('您没有权限查看!');
     }
     $this->renderIframe(array('solutionInfo' => $solutionInfo), 'status/iframe/judge_log.php');
 }
Ejemplo n.º 16
0
 public function defaultAction()
 {
     $username = Request::getGET('username');
     if (empty($username)) {
         $this->renderError();
     }
     // 校验用户
     $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
     if (empty($userInfo)) {
         $this->renderError();
     }
     // 获取solutionList
     $where = array(array('user_id', '=', $userInfo['id']));
     $order = array('remote' => 'ASC', 'problem_code' => 'ASC');
     $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order));
     // 计算排名,先按题数,再按照提交次数
     $where = array(array('OR' => array(array('solved_all', '>', $userInfo['solved_all']), array(array('solved_all', '=', $userInfo['solved_all']), array('submit_all', '>', $userInfo['submit_all'])), array(array('solved_all', '=', $userInfo['solved_all']), array('submit_all', '=', $userInfo['submit_all']), array('id', '<', $userInfo['id'])))));
     $prevCount = UserCommonInterface::getCount($where);
     $rank = intval($prevCount) + 1;
     // 计算解决的题目
     $solvedProblemList = array();
     $visited = array();
     // 标记数组
     foreach ($solutionList as $solutionInfo) {
         $remote = $solutionInfo['remote'];
         $problemCode = $solutionInfo['problem_code'];
         if (!isset($visited[$remote][$problemCode]) && $solutionInfo['result'] == StatusVars::ACCEPTED) {
             $problemInfo = array('remote' => $remote, 'problem_code' => $problemCode);
             $solvedProblemList[] = $problemInfo;
             $visited[$remote][$problemCode] = 1;
         }
     }
     // 计算未解决的题目
     $unSolvedProblemList = array();
     $visited2 = array();
     foreach ($solutionList as $solutionInfo) {
         $remote = $solutionInfo['remote'];
         $problemCode = $solutionInfo['problem_code'];
         if (!isset($visited2[$remote][$problemCode]) && !isset($visited[$remote][$problemCode])) {
             $problemInfo = array('remote' => $remote, 'problem_code' => $problemCode);
             $unSolvedProblemList[] = $problemInfo;
             $visited2[$remote][$problemCode] = 1;
         }
     }
     // 输出
     $this->renderFramework(array('rank' => $rank, 'userInfo' => $userInfo, 'solvedProblemList' => $solvedProblemList, 'unSolvedProblemList' => $unSolvedProblemList), 'user/my.php');
 }
Ejemplo n.º 17
0
 public function ajaxUpdatePasswordAction()
 {
     // 获取参数
     $oldPassword = Request::getPOST('old-password');
     $password = trim(Request::getPOST('password'));
     if (!Regex::match($password, RegexVars::PASSWORD)) {
         $this->renderError('新密码限制为6-20位!');
     }
     $encryptPassword = UserCommonInterface::encryptPassword(array('password' => $oldPassword));
     if ($encryptPassword != $this->loginUserInfo['password']) {
         $this->renderError('旧密码不正确!');
     }
     $data = array('id' => $this->loginUserInfo['id'], 'password' => $password);
     UserCommonInterface::save($data);
     UserCommonInterface::logout();
     $this->renderAjax(0);
 }
Ejemplo n.º 18
0
 public function iframeShowAction()
 {
     $solutionId = (int) Request::getGET('solution-id');
     $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId));
     if (empty($solutionInfo) || false == OjSolutionHelper::hasLog($solutionInfo)) {
         $this->renderError();
     }
     // 获取属主
     $userId = $solutionInfo['user_id'];
     $userInfo = UserCommonInterface::getById(array('id' => $userId));
     // solution level
     list($solutionInfo['level'], $solutionInfo['permission']) = OjSolutionHelper::solutionPermission($solutionInfo, $userInfo['share'], Arr::get('id', $this->loginUserInfo, 0), $this->isOjAdmin);
     if (!$solutionInfo['permission']) {
         $this->renderError('您没有权限查看!');
     }
     $this->renderIframe(array('solutionInfo' => $solutionInfo), 'status/iframe/judge_log.php');
 }
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $status = (int) Request::getGET('status', -1);
     $contestId = (int) Request::getGET('contest-id', 0);
     // 获取属于用户的竞赛
     $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);
     $userHash = array();
     $applyList = array();
     $allCount = 0;
     if (!empty($contestIds)) {
         if ($contestId > 0 && !in_array($contestId, $contestIds)) {
             $where = false;
         } else {
             if ($contestId > 0 && in_array($contestId, $contestIds)) {
                 $where = array(array('contest_id', '=', $contestId));
             } else {
                 $where = array(array('contest_id', 'IN', $contestIds));
             }
         }
         if (false !== $where) {
             if ($status != -1) {
                 $where[] = array('status', '=', $status);
             }
             $offset = ($page - 1) * $pageSize;
             $applyList = OjContestApplyInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
             if (!empty($applyList)) {
                 $allCount = OjContestApplyInterface::getCount($where);
                 $userIds = 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, 'contestHash' => $contestHash, 'userHash' => $userHash), 'setup/contest/apply_list.php');
 }
Ejemplo n.º 20
0
 public function defaultAction()
 {
     $solutionId = (int) Request::getGET('solution-id');
     // 获取solutionInfo
     $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId));
     if (empty($solutionInfo)) {
         $this->renderError();
     }
     // 获取属主
     $userId = $solutionInfo['user_id'];
     $userInfo = UserCommonInterface::getById(array('id' => $userId));
     if (empty($userInfo)) {
         $this->renderError();
     }
     // 是否有权限查看,竞赛管理员,自己的solution
     if (!$this->isContestAdmin && $solutionInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('您没有权限查看!');
     }
     $this->renderFramework(array('solutionInfo' => $solutionInfo), 'status/code.php');
 }
Ejemplo n.º 21
0
 public function ajaxAddAction()
 {
     $loginName = Request::getPOST('login-name');
     if (empty($loginName)) {
         $this->renderAjax(1, '请填写登录名!');
     }
     // 校验一个用户
     $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $loginName));
     if (empty($userInfo)) {
         $this->renderAjax(1, "用户 {$loginName} 不存在!");
     }
     // 是否已经添加
     $managerInfo = RootManagerInterface::getByField(array('user_id' => $userInfo['id']));
     if (!empty($managerInfo)) {
         $this->renderAjax(1, "用户 {$loginName} 已经是管理员!");
     }
     // 添加用户到管理员
     RootManagerInterface::save(array('login_name' => $loginName));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '添加成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 22
0
 public function defaultAction()
 {
     $solutionId = (int) Request::getGET('solution-id');
     // 获取solutionInfo
     $solutionInfo = OjSolutionInterface::getDetail(array('id' => $solutionId));
     if (empty($solutionInfo)) {
         $this->renderError();
     }
     // 获取属主
     $userId = $solutionInfo['user_id'];
     $userInfo = UserCommonInterface::getById(array('id' => $userId));
     if (empty($userInfo)) {
         $this->renderError();
     }
     // solution level
     list($solutionInfo['level'], $solutionInfo['permission']) = OjSolutionHelper::solutionPermission($solutionInfo, $userInfo['share'], Arr::get('id', $this->loginUserInfo, 0), $this->isOjAdmin);
     if (!$solutionInfo['permission']) {
         $this->renderError('您没有权限查看!');
     }
     $this->renderFramework(array('solutionInfo' => $solutionInfo), 'status/code.php');
 }
Ejemplo n.º 23
0
 public function ajaxSubmitAction()
 {
     $sex = Request::getPOST('sex');
     $share = Request::getPOST('share');
     $motto = trim(Request::getPOST('motto'));
     $nickname = trim(Request::getPOST('nickname'));
     if (empty($nickname)) {
         $this->renderError('昵称不能为空!');
     }
     if (!in_array($share, array(0, 1)) || !in_array($sex, array(1, 2))) {
         $this->renderError('请填写信息!');
     }
     if (mb_strlen($motto, 'utf8') > 100) {
         $this->renderError('签名不能超过100个字!');
     }
     if (mb_strlen($nickname, 'utf8') > 16) {
         $this->renderError('昵称长度16个字符以内!');
     }
     $data = array('id' => $this->loginUserInfo['id'], 'nickname' => $nickname, 'motto' => $motto, 'sex' => $sex, 'share' => $share);
     UserCommonInterface::save($data);
     $this->renderAjax(0);
 }
Ejemplo n.º 24
0
 public function ajaxSubmitAction()
 {
     $email = Request::getPOST('email');
     $checkCode = Request::getPOST('check-code');
     if (empty($email) || empty($checkCode)) {
         $this->renderError('请填写信息!');
     }
     // 是否已经被绑定
     $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $email));
     if (!empty($userInfo)) {
         $this->renderError('该邮箱已经被绑定!');
     }
     $check = AuthCommonInterface::checkEmailCode(array('email' => $email, 'code' => $checkCode));
     if (false === $check) {
         $this->renderError('邮箱验证码错误!');
     }
     // 删除email code
     AuthCommonInterface::deleteEmailCode(array('email' => $email));
     // 修改用户
     UserCommonInterface::save(array('id' => $this->loginUserInfo['id'], 'email' => $email));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '绑定邮箱成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 25
0
 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');
 }
Ejemplo n.º 26
0
 public function ajaxChangeAction()
 {
     // 获取参数
     $docId = (int) Request::getPOST('doc-id');
     $username = trim(Request::getPOST('username', ''));
     $category = (int) Request::getPOST('category');
     if (empty($username) || !array_key_exists($category, DocVars::$CATEGORY)) {
         $this->renderError('参数错误!');
     }
     // 校验用户
     $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
     if (empty($userInfo)) {
         $this->renderError('用户不存在!');
     }
     // 校验doc
     $docInfo = DocInterface::getById(array('id' => $docId));
     if (empty($docInfo)) {
         $this->renderError('文章不存在!');
     }
     // 更新
     DocInterface::change(array('id' => $docId, 'username' => $username, 'category' => $category));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功');
     $this->renderAjax(0);
 }
Ejemplo n.º 27
0
 public static function getRankBoard($id)
 {
     $setInfo = self::getById($id);
     if (empty($setInfo)) {
         throw new InterfaceException('专题不存在!');
     }
     $globalIds = json_decode($setInfo['problem_set'], true);
     if (empty($globalIds)) {
         return array(array(), array(), array());
     }
     // 取出提交记录
     $where = array(array('problem_global_id', 'IN', $globalIds), array('result', '>=', 4));
     $order = array('id' => 'ASC');
     $solutionList = OjSolutionInterface::getList(array('field' => 'id,user_id,problem_global_id,result', 'where' => $where, 'order' => $order));
     // 计算$rankHash
     $rankHash = array();
     $mat = array();
     $firstBlood = array();
     // 标记第一滴血
     foreach ($solutionList as $solutionInfo) {
         $globalId = $solutionInfo['problem_global_id'];
         $userId = $solutionInfo['user_id'];
         $result = $solutionInfo['result'];
         if (!isset($rankHash[$userId])) {
             $rankHash[$userId]['solved'] = 0;
             $rankHash[$userId]['all_fail_count'] = 0;
         }
         if (!isset($mat[$userId][$globalId])) {
             $mat[$userId][$globalId] = array();
             $mat[$userId][$globalId]['fail_count'] = 0;
         }
         // 已经通过的,直接continue
         if (isset($mat[$userId][$globalId]['accepted'])) {
             continue;
         }
         // 如果这条solution是accepted
         if ($result == StatusVars::ACCEPTED) {
             $mat[$userId][$globalId]['accepted'] = 1;
             $rankHash[$userId]['solved']++;
             // 标记1血
             if (!isset($firstBlood[$globalId])) {
                 $mat[$userId][$globalId]['first_blood'] = 1;
                 $firstBlood[$globalId] = 1;
             }
             continue;
         } else {
             $mat[$userId][$globalId]['fail_count']++;
             $rankHash[$userId]['all_fail_count']++;
         }
     }
     uasort($rankHash, array('OjProblemSetLogic', 'cmp'));
     // 获取用户信息
     $userIds = array_unique(array_column($solutionList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     return array($rankHash, $mat, $userHash);
 }
Ejemplo n.º 28
0
 public function defaultAction()
 {
     $pageSize = 15;
     $username = Request::getGET('username');
     $remote = (int) Request::getGET('remote', -1);
     $problemCode = Request::getGET('problem-code');
     // 因为ZOJ的题号是code
     $language = (int) Request::getGET('language', -1);
     $result = (int) Request::getGET('result', -1);
     $contestId = (int) Request::getGET('contest-id');
     $globalId = (int) Request::getGET('global-id');
     // 获取id
     $maxId = (int) Request::getGET('max-id', -1);
     $minId = (int) Request::getGET('min-id', -1);
     // 获取userInfo,username转换为userId
     $userInfo = array();
     if (!empty($username)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
     }
     // 构建where
     $where = array();
     if ($this->isOjAdmin) {
         if ($contestId) {
             $where[] = array('contest_id', '=', $contestId);
         }
     }
     if (!empty($username)) {
         $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0));
     }
     if ($remote != -1) {
         $where[] = array('remote', '=', $remote);
     }
     if (!empty($problemCode)) {
         $where[] = array('problem_code', '=', $problemCode);
     }
     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('id', '<=', $maxId);
         $order = array('id' => 'DESC');
         $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'include_contest' => $this->isOjAdmin));
     } else {
         if ($minId != -1) {
             $where[] = array('id', '>=', $minId);
             $order = array('id' => 'ASC');
             $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'include_contest' => $this->isOjAdmin));
             $solutionList = array_reverse($solutionList, true);
         } else {
             $order = array('id' => 'DESC');
             $solutionList = OjSolutionInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'include_contest' => $this->isOjAdmin));
         }
     }
     // 获取userHash
     $userIds = array_unique(array_column($solutionList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 格式化solution
     foreach ($solutionList as &$solutionInfo) {
         // level
         $userInfo = $userHash[$solutionInfo['user_id']];
         list($solutionInfo['level'], $solutionInfo['permission']) = OjSolutionHelper::solutionPermission($solutionInfo, $userInfo['share'], Arr::get('id', $this->loginUserInfo, 0), $this->isOjAdmin);
         $solutionInfo['has_log'] = OjSolutionHelper::hasLog($solutionInfo);
     }
     // 计算minId, maxId
     $minId = $maxId = 0;
     if (!empty($solutionList)) {
         $n = count($solutionList);
         $maxId = $solutionList[0]['id'];
         $minId = $solutionList[$n - 1]['id'];
     }
     // 缓存html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderMaxId' => $maxId, 'renderMinId' => $minId), 'widget/pager_status.php');
     $tpl = $this->isOjAdmin ? 'status/list_admin.php' : 'status/list.php';
     // render
     $this->renderFramework(array('userHash' => $userHash, 'solutionList' => $solutionList, 'html' => $html), $tpl);
 }
Ejemplo n.º 29
0
 public static function change($id, $username = '', $category = -1)
 {
     if (empty($username) && $category == -1) {
         return 0;
     }
     // 校验doc
     $docInfo = self::getById($id);
     if (empty($docInfo)) {
         throw new InterfaceException('文章不存在!');
     }
     $data = array();
     if ($category != -1) {
         if (!array_key_exists($category, DocVars::$CATEGORY)) {
             throw new InterfaceException('类别不存在!');
         }
         $data['category'] = $category;
     }
     if (!empty($username)) {
         // 校验用户
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username));
         if (empty($userInfo)) {
             throw new InterfaceException('用户不存在!');
         }
         $data['user_id'] = $userInfo['id'];
     }
     $model = new DocListModel();
     $affects = $model->updateById($id, $data);
     return $affects;
 }
Ejemplo n.º 30
0
 public static function getRankBoard($id)
 {
     $contestInfo = self::getDetail($id);
     if (empty($contestInfo)) {
         throw new InterfaceException('专题不存在!');
     }
     // 取出提交记录
     $where = array(array('contest_id', '=', $id), array('result', '>=', 4), array('problem_global_id', 'IN', $contestInfo['global_ids']));
     $order = array('id' => 'ASC');
     $solutionList = OjSolutionInterface::getList(array('field' => 'id,user_id,problem_global_id,result,contest_submit_second', 'where' => $where, 'order' => $order, 'include_contest' => true));
     // 计算$rankHash
     $rankHash = array();
     $mat = array();
     $firstBlood = array();
     // 标记第一滴血
     foreach ($solutionList as $solutionInfo) {
         $globalId = $solutionInfo['problem_global_id'];
         $userId = $solutionInfo['user_id'];
         $result = $solutionInfo['result'];
         if (!isset($rankHash[$userId])) {
             $rankHash[$userId]['solved'] = 0;
             $rankHash[$userId]['cost_second'] = 0;
         }
         if (!isset($mat[$userId][$globalId])) {
             $mat[$userId][$globalId] = array('accepted' => 0, 'first_blood' => 0, 'fail_count' => 0, 'pass_second' => 0);
         }
         // 已经通过的,直接continue
         if ($mat[$userId][$globalId]['accepted']) {
             continue;
         }
         // 如果这条solution是accepted
         if ($result == StatusVars::ACCEPTED) {
             // 记录到mat
             $mat[$userId][$globalId]['accepted'] = 1;
             $mat[$userId][$globalId]['pass_second'] = $solutionInfo['contest_submit_second'];
             if (!isset($firstBlood[$globalId])) {
                 $mat[$userId][$globalId]['first_blood'] = 1;
                 $firstBlood[$globalId] = 1;
             }
             // 记录到rankHash
             $rankHash[$userId]['solved']++;
             $rankHash[$userId]['cost_second'] += $mat[$userId][$globalId]['pass_second'] + $mat[$userId][$globalId]['fail_count'] * 20 * 60;
             continue;
         } else {
             $mat[$userId][$globalId]['fail_count']++;
         }
     }
     uasort($rankHash, array('OjContestLogic', 'cmp'));
     // 获取用户信息
     $userIds = array_unique(array_column($solutionList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     return array($rankHash, $mat, $userHash);
 }