public function ajaxSubmitAction() { $setId = Request::getPOST('set-id'); $title = trim(Request::getPOST('title')); $refreshAt = strtotime(trim(Request::getPOST('refresh-at'))); if (empty($setId)) { $this->renderError('参数错误!'); } if (empty($title) || mb_strlen($title, 'utf8') > 50) { $this->renderError('标题必填,限制50个字以内!'); } $currentDay = intval(time() / 86400) * 86400 + 86400; if (empty($refreshAt) || $refreshAt > $currentDay) { $this->renderError('刷新时间不能超过今天!'); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError('专题不存在!'); } // 属主验证 if ($setInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('你没有修改权限!'); } $data = array('id' => $setId, 'title' => $title, 'refresh_at' => $refreshAt); OjProblemSetInterface::save($data); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '修改成功!'); $this->renderAjax(0); }
public function ajaxSubmitAction() { // 如果空专题超过20,提示编辑 $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('title', '=', '')); $count = OjProblemSetInterface::getCount($where); if ($count > 20) { $this->renderError('您有很多空的专题,请先编辑!'); } // 创建空的专题 $data = array('user_id' => $this->loginUserInfo['id']); OjProblemSetInterface::save($data); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '您成功创建了专题,请编辑!'); $this->renderAjax(0); }
public function ajaxStickCancelAction() { $setId = Request::getPOST('set-id'); $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError('专题不存在!'); } if (!$setInfo['listing_status']) { $this->renderError('已取消置顶!'); } OjProblemSetInterface::cancelStick(array('id' => $setId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!'); $this->renderAjax(0); }
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() { $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'] && Arr::get('id', $this->loginUserInfo['id'], 0) != $setInfo['user_id']) { $this->renderError(); } $setInfo['global_ids'] = (array) json_decode($setInfo['problem_set'], true); list($rankHash, $mat, $userHash) = OjProblemSetInterface::getRankBoard(array('id' => $setId)); $this->renderFramework(array('setInfo' => $setInfo, 'rankHash' => $rankHash, 'mat' => $mat, 'userHash' => $userHash), 'set/rank.php'); }
public function ajaxRemoveProblemAction() { $setId = (int) Request::getPOST('set-id'); $globalId = (int) Request::getPOST('global-id'); if (empty($setId) || empty($globalId)) { $this->renderError('参数错误!'); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError('专题不存在!'); } // 属主验证 if ($this->loginUserInfo['id'] != $setInfo['user_id']) { $this->renderError('你没有权限操作!'); } OjProblemSetInterface::removeProblem(array('id' => $setId, 'global_id' => $globalId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功'); $this->renderAjax(0); }
public function ajaxHideAction() { // 获取参数 $setId = Request::getPOST('set-id'); if (empty($setId)) { $this->renderError('参数错误!'); } $setInfo = OjProblemSetInterface::getById(array('id' => $setId)); if (empty($setInfo)) { $this->renderError('专题不存在!'); } // 属主验证 if ($this->loginUserInfo['id'] != $setInfo['user_id']) { $this->renderError('你没有权限操作!'); } if ($setInfo['hidden']) { $this->renderError('已经隐藏!'); } // 更新数据 OjProblemSetInterface::hide(array('id' => $setId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!'); $this->renderAjax(0); }
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'); }