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'); }
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 ajaxLoadProblemAction() { require_once INCLUDE_PATH . '/remote/RemoteProblemApi.class.php'; $remote = (int) Request::getPOST('remote'); $number = (int) Request::getPOST('number'); if (empty($number)) { $this->renderError('参数错误1!'); } if (!array_key_exists($remote, StatusVars::$REMOTE_SCHOOL) || $remote == StatusVars::REMOTE_HQU) { $this->renderError('参数错误2!'); } // 获取各个OJ下题号 $where = array('group_by' => 'remote'); $problemList = OjProblemInterface::getList(array('field' => 'remote, max(problem_code) AS max_id', 'where' => $where)); if (false === $problemList) { $this->renderError('查询失败!'); } $remoteHash = Arr::listToHash('remote', $problemList); foreach ($problemList as $problemInfo) { $remoteHash[$problemInfo['remote']] = $problemInfo['max_id']; } $hduFromId = (int) Arr::get(StatusVars::REMOTE_HDU, $remoteHash, 999) + 1; $pojFromId = (int) Arr::get(StatusVars::REMOTE_POJ, $remoteHash, 999) + 1; $zojFromId = (int) Arr::get(StatusVars::REMOTE_POJ, $remoteHash, 1000) + 1; $loadProblemList = array(); if ($remote == StatusVars::REMOTE_HDU) { $loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_HDU, $hduFromId, $number); } else { if ($remote == StatusVars::REMOTE_POJ) { $loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_POJ, $pojFromId, $number); } else { if ($remote == StatusVars::REMOTE_ZOJ) { $loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_ZOJ, $zojFromId, $number); } } } foreach ($loadProblemList as &$problemInfo) { $problemInfo['remote'] = $remote; $problemInfo['remote_format'] = StatusVars::$REMOTE_SCHOOL[$remote]; } $this->renderAjax(0, 'Success!', array('problemList' => $loadProblemList)); }