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 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');
 }
 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');
 }
 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 = 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');
 }
 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 iframeChangeAction()
 {
     $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->renderIframe(array('userInfo' => $userInfo, 'docInfo' => $docInfo), 'doc/iframe/change.php');
 }
 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');
 }
 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');
 }
 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 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');
 }
 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');
 }
 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');
 }
 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');
 }
 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');
 }
 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');
 }
 public static function save($data, $id = 0, $trans = null)
 {
     if (!empty($trans)) {
         $model = new OjProblemModel($trans);
     } else {
         $model = new OjProblemModel();
     }
     if (0 == $id) {
         $userInfo = UserCommonInterface::getById(array('id' => $data['user_id']));
         if (empty($userInfo)) {
             throw new InterfaceException('用户不存在!');
         }
         $history = '';
         if ($data['remote'] == StatusVars::REMOTE_HQU) {
             $dataTime = date('Y-m-d H:i:s', time());
             $history = "<p>{$dataTime} 用户{$userInfo['username']}新建了题目</p>";
         }
         $insertData = array('user_id' => $data['user_id'], 'remote' => $data['remote'], 'time_limit' => Arr::get('time_limit', $data, 1000), 'memory_limit' => Arr::get('memory_limit', $data, 32768), 'hidden' => $data['remote'] == StatusVars::REMOTE_HQU ? 1 : 0, 'audit_history' => $history);
         if ($data['remote'] == StatusVars::REMOTE_HQU) {
             // 如果添加是华大题目
             if (!isset($data['problem_id'])) {
                 $where = array(array('remote', '=', $data['remote']));
                 $lastInfo = self::getRow('MAX(problem_id) AS max_problem_id', $where);
                 $lastId = Arr::get('max_problem_id', $lastInfo, 999);
                 $insertData['problem_id'] = $lastId + 1;
                 $insertData['problem_code'] = $lastId + 1;
             }
         } else {
             $insertData['problem_id'] = $data['problem_id'];
             $insertData['problem_code'] = $data['problem_code'];
         }
         $id = $model->insert($insertData);
         return $id;
     } else {
         // 对某些字段特殊处理
         $updateData = $data;
         $affects = $model->updateById($id, $updateData);
         return $affects;
     }
 }
 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 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');
 }
 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 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);
 }
 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);
 }
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $passed = (int) Request::getGET('passed', 0);
     $diy = (int) Request::getGET('diy', 0);
     // 构建where
     $where = array();
     $where[] = array('hidden', '=', 0);
     if ($passed) {
         $where[] = array('end_time', '<=', time());
     } else {
         $where[] = array('end_time', '>', time());
     }
     if ($diy) {
         $where[] = array('is_diy', '=', 1);
     } else {
         $where[] = array('is_diy', '=', 0);
     }
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     if ($passed) {
         $order = array('end_time' => 'DESC');
     } else {
         $order = array('end_time' => 'ASC');
     }
     // 获取数据
     $offset = ($page - 1) * $pageSize;
     $tmpContestList = OjContestInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjContestInterface::getCount($where);
     // 将进行中的比赛提前
     $contestList = array();
     if (!$passed) {
         foreach ($tmpContestList as $i => $contestInfo) {
             if ($contestInfo['begin_time'] < time()) {
                 $contestList[] = $contestInfo;
                 unset($tmpContestList[$i]);
             }
         }
         foreach ($tmpContestList as $i => $contestInfo) {
             $contestList[] = $contestInfo;
             unset($tmpContestList[$i]);
         }
     } else {
         $contestList = $tmpContestList;
     }
     $userIds = array_unique(array_column($contestList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 格式化
     foreach ($contestList as &$contestInfo) {
         // row_class
         $now = time();
         if ($contestInfo['end_time'] < $now) {
             $contestInfo['row_css'] = 'passed';
         } else {
             if ($contestInfo['begin_time'] > $now) {
                 $contestInfo['row_css'] = 'pending';
             } else {
                 $contestInfo['row_css'] = 'running';
             }
         }
         // type_format
         $type = $contestInfo['type'];
         if ($type == ContestVars::TYPE_PUBLIC) {
             $contestInfo['type_format'] = '<p class="red">公开</p>';
         } else {
             if ($type == ContestVars::TYPE_APPLY) {
                 $contestInfo['type_format'] = '<p class="orange">报名</p>';
             } else {
                 if ($type == ContestVars::TYPE_PASSWORD) {
                     $contestInfo['type_format'] = '<p class="green">密码</p>';
                 } else {
                     $contestInfo['type_format'] = '<p class="gray">未定义</p>';
                 }
             }
         }
     }
     // 缓存部分的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), 'contest/list.php');
 }
 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);
 }
 public function defaultAction()
 {
     $pageSize = 20;
     $page = Pager::get();
     $loginName = Request::getGET('login-name', '');
     $path = Request::getGET('path', '');
     $includePath = Request::getGET('include-path', '');
     // 路径非法提示
     if (!empty($path)) {
         if (!RootPermissionInterface::isValidPath(array('path' => $path))) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$path}格式不正确!");
             $url = Url::getCurrentUrl(array('path' => null));
             Url::redirect($url);
         }
     }
     // 路径非法提示
     if (!empty($includePath)) {
         if (!RootPermissionInterface::isValidPath(array('path' => $includePath))) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$includePath}格式不正确!");
             $url = Url::getCurrentUrl(array('include-path' => null));
             Url::redirect($url);
         }
     }
     // 用户不存在提示
     if (!empty($loginName)) {
         $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $loginName));
         if (empty($userInfo)) {
             $this->setNotice(FrameworkVars::NOTICE_ERROR, '用户不存在!');
             $url = Url::getCurrentUrl(array('login-name' => null));
             Url::redirect($url);
         }
     }
     // 构建where
     $where = array();
     if (!empty($userInfo)) {
         $where[] = array('user_id', '=', $userInfo['id']);
     }
     if (!empty($path)) {
         $managerIds = RootManagerInterface::getAllowedManagerIds(array('path' => $path));
         $where[] = array('id', 'IN', $managerIds);
     }
     if (!empty($includePath)) {
         $managerIds = RootManagerInterface::getIncludeManagerIds(array('path' => $includePath));
         $where[] = array('id', 'IN', $managerIds);
     }
     $offset = ($page - 1) * $pageSize;
     $managerList = RootManagerInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = RootManagerInterface::getCount($where);
     $userList = array();
     $pathHash = array();
     if (!empty($managerList)) {
         $userIds = array_column($managerList, 'user_id');
         $userList = UserCommonInterface::getById(array('id' => $userIds));
         $userList = Arr::listToHash('id', $userList);
         // 获取权限列表
         $managerIds = array_column($managerList, 'id');
         $pathHash = RootManagerInterface::getPaths(array('id' => $managerIds));
     }
     // 找出invalid path
     $invalidHash = array();
     foreach ($pathHash as $id => $pathSet) {
         foreach ($pathSet as $tmpPath) {
             if (array_key_exists($tmpPath, $invalidHash)) {
                 continue;
             }
             $invalidHash[$tmpPath] = RootPermissionInterface::findPath(array('path' => $tmpPath)) ? 0 : 1;
         }
     }
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
     $this->renderFramework(array('html' => $html, 'managerList' => $managerList, 'userList' => $userList, 'pathHash' => $pathHash, 'invalidHash' => $invalidHash), 'manager/list.php');
 }