public function ajaxChangeStatusAction()
 {
     $applyId = Request::getPOST('apply-id');
     $op = Request::getPOST('op');
     if (!in_array($op, array(1, 2)) || empty($applyId)) {
         $this->renderError('参数错误!');
     }
     $applyInfo = OjContestApplyInterface::getById(array('id' => $applyId));
     if (empty($applyInfo)) {
         $this->renderError('报名信息不存在!');
     }
     // 只能处理自己竞赛下的报名
     $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1));
     $contestHash = OjContestInterface::getList(array('where' => $where));
     $contestHash = Arr::listToHash('id', $contestHash);
     $contestIds = array_keys($contestHash);
     if (!in_array($applyInfo['contest_id'], $contestIds)) {
         $this->renderError('你没有权限操作!');
     }
     if ($op == 1 && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED || $op == 2 && $applyInfo['status'] == ContestVars::APPLY_REJECTED) {
         $msg = $op == 1 ? '已经通过!' : '已经拒绝!';
         $this->renderError($msg);
     }
     if ($op == 1) {
         OjContestApplyInterface::accept(array('id' => $applyId));
     } else {
         OjContestApplyInterface::reject(array('id' => $applyId));
     }
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!');
     $this->renderAjax(0);
 }
 public function defaultAction()
 {
     list($rankHash, $mat, $userHash) = OjContestInterface::getRankBoard(array('id' => $this->contestInfo['id']));
     // 如果是报名,获取报名列表
     $applyHash = array();
     if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) {
         $where = array(array('contest_id', '=', $this->contestInfo['id']));
         $applyHash = OjContestApplyInterface::getList(array('where' => $where));
         $applyHash = Arr::listToHash('user_id', $applyHash);
     }
     $this->renderFramework(array('rankHash' => $rankHash, 'mat' => $mat, 'userHash' => $userHash, 'applyHash' => $applyHash), 'rank/list.php');
 }
 public function 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));
 }
 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');
 }
 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');
 }
 /**
  * 如果id是一个数字,返回对应的一行;如果id是数组,返回一个关联列表;
  *
  * @param   int|array   $id
  * @return  array       null|一行, array()|关联列表
  * @throws  LibraryException
  */
 public function getById($id)
 {
     // 校验参数
     if (is_numeric($id) && intval($id) == $id && $id > 0 || is_array($id)) {
     } else {
         throw new LibraryException('参数错误:$id');
     }
     if (empty($id)) {
         return array();
     }
     // 校验字段id是否存在
     if (!array_key_exists('id', $this->fieldTypes)) {
         throw new LibraryException("数据表`{$this->dbName}`.`{$this->tableName}`或者Model中不存在字段id!");
     }
     // 获取缓存,如果处在事务,那么不使用缓存
     $staticCache = array();
     if (!$this->isTransModel && isset(self::$rowCache[$this->dbName][$this->tableName]['id']['eq'])) {
         $staticCache = self::$rowCache[$this->dbName][$this->tableName]['id']['eq'];
     }
     if (is_array($id)) {
         $queryIds = $id;
         if (!empty($staticCache)) {
             // 如果缓存不为空,排除已经处在缓存中的id
             foreach ($queryIds as $i => $k) {
                 if (array_key_exists($k, $staticCache)) {
                     unset($queryIds[$i]);
                 }
             }
         }
         // 查询
         $retList = array();
         if (!empty($queryIds)) {
             $where = array();
             if (count($queryIds) == 1) {
                 $where[] = array('id', '=', current($queryIds));
             } else {
                 $where[] = array('id', 'IN', $queryIds);
             }
             $retList = $this->getList('*', $where);
             $retList = Arr::listToHash('id', $retList);
         }
         // 合并结果
         $ret = array();
         foreach ($id as $k) {
             $row = array();
             if (array_key_exists($k, $staticCache)) {
                 $row = $staticCache[$k];
             } else {
                 if (array_key_exists($k, $retList)) {
                     $row = $retList[$k];
                 }
             }
             // 不在事务中才能更新静态缓存
             if (!$this->isTransModel) {
                 self::$rowCache[$this->dbName][$this->tableName]['id']['eq'][$k] = $row;
             }
             $ret[$k] = $row;
         }
         return $ret;
     } else {
         // 在缓存中,返回
         if (array_key_exists($id, $staticCache)) {
             return $staticCache[$id];
         }
         // 查询
         $where = array(array('id', '=', $id));
         $rowInfo = $this->getRow('*', $where);
         // 不在事务中才能更新静态缓存
         if (!$this->isTransModel) {
             self::$rowCache[$this->dbName][$this->tableName]['id']['eq'][$id] = $rowInfo;
         }
         return $rowInfo;
     }
 }