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 = 100;
     // 获取参数
     $page = Pager::get();
     $remote = (int) Request::getGET('remote', 0);
     $keyword = Request::getGET('keyword');
     $searchType = (int) Request::getGET('search-type', 1);
     // 构建where
     $where = array();
     $where[] = array('remote', '=', $remote);
     $where[] = array('hidden', '=', 0);
     if (!empty($keyword)) {
         if ($searchType == 1) {
             $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('title', 'LIKE', "%{$keyword}%")));
         } else {
             if ($searchType == 2) {
                 $where[] = array('OR' => array(array('problem_code', '=', $keyword), array('source', 'LIKE', "%{$keyword}%")));
             }
         }
     }
     // 获取数据
     $order = array('problem_code' => 'ASC');
     $offset = ($page - 1) * $pageSize;
     $problemList = OjProblemInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjProblemInterface::getCount($where);
     // 获取用户解决的题目
     $userSolution = array();
     if ($this->loginUserInfo) {
         $globalIds = array_column($problemList, 'id');
         $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('contest_id', '=', 0), array('problem_global_id', 'IN', $globalIds));
         $solutionList = OjSolutionInterface::getList(array('where' => $where));
         foreach ($solutionList as $solutionId => $solutionInfo) {
             $globalId = $solutionInfo['problem_global_id'];
             if (!array_key_exists($globalId, $userSolution) || $solutionInfo['result'] == StatusVars::ACCEPTED) {
                 $userSolution[$globalId] = $solutionInfo;
             }
         }
     }
     $userHash = array();
     if ($allCount > 0) {
         $userIds = array_unique(array_column($problemList, 'user_id'));
         $userHash = UserCommonInterface::getById(array('id' => $userIds));
     }
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 10), 'widget/pager.php');
     $tpl = $remote ? 'problem/list_remote.php' : 'problem/list.php';
     // 输出
     $this->renderFramework(array('html' => $html, 'problemList' => $problemList, 'userSolution' => $userSolution, 'userHash' => $userHash), $tpl);
 }
 public function ajaxAddAction()
 {
     // 判断用户可以创建的题目是否上限
     $where = array(array('remote', '=', StatusVars::REMOTE_HQU), array('user_id', '=', $this->loginUserInfo['id']), array('hidden', '=', 1));
     $count = OjProblemInterface::getCount($where);
     if ($count >= 20) {
         $this->renderError('你的私有题目达到上限(20题)!');
     }
     $data = array('remote' => StatusVars::REMOTE_HQU, 'user_id' => $this->loginUserInfo['id']);
     OjProblemInterface::save($data);
     $msg = '你成功创建了题目,请记得编辑题目哦!';
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, $msg);
     $this->renderAjax(0);
 }