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; } }
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 = 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 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'); }
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); }
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); }
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); }
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 = 15; $username = Request::getGET('username'); $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); $userInfo = array(); if (!empty($userInfo)) { $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); } // 构建where $where = array(); if (!empty($username)) { $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0)); } 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), 'problem/judge_list.php'); }
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; }
public function ajaxSetUserAction() { // 获取参数 $globalId = Request::getPOST('global-id'); $username = trim(Request::getPOST('username', '')); // 校验用户 $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); if (empty($userInfo)) { $this->renderError('用户不存在!'); } // 校验problem $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } OjProblemInterface::setUser(array('id' => $globalId, 'username' => $username)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '设置成功!'); $this->renderAjax(0); }
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'); }
public static function setUser($id, $username) { $problemInfo = self::getById($id); if (empty($problemInfo)) { throw new InterfaceException('题目不存在!'); } $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); if (empty($userInfo)) { throw new InterfaceException('用户不存在!'); } $model = new OjProblemModel(); $data = array('user_id' => $userInfo['id']); $affects = $model->updateById($id, $data); return $affects; }