public static function save($data, $id = 0) { $model = new OjContestApplyModel(); if (0 == $id) { // 判断是否已经存在 $applyInfo = self::getDetail($data['contest_id'], $data['user_id']); $contestInfo = OjContestInterface::getById(array('id' => $data['contest_id'])); if (empty($contestInfo)) { throw new InterfaceException('竞赛不存在!'); } if ($contestInfo['type'] != ContestVars::TYPE_APPLY) { throw new InterfaceException('比赛不需要报名!'); } if ($contestInfo['end_time'] < time()) { throw new InterfaceException('比赛已经结束!'); } $data['status'] = ContestVars::APPLY_QUEUE; $data['is_diy'] = $contestInfo['is_diy']; if (!empty($applyInfo)) { if ($applyInfo['status'] == ContestVars::APPLY_ACCEPTED) { throw new InterfaceException('报名已通过,无法修改!'); } $model->updateById($applyInfo['id'], $data); return $applyInfo['id']; } else { $id = $model->insert($data); return $id; } } else { // 对某些字段特殊处理 $updateData = $data; $affects = $model->updateById($id, $updateData); return $affects; } }
public function defaultAction() { $pageSize = 20; // 获取参数 $page = Pager::get(); $status = (int) Request::getGET('status', -1); $contestId = (int) Request::getGET('contest-id', 0); $where = array(); $where[] = array('is_diy', '=', 0); if (!empty($contestId)) { $where[] = array('contest_id', '=', $contestId); } if ($status != -1) { $where[] = array('status', '=', $status); } // 获取数据 $offset = ($page - 1) * $pageSize; $applyList = OjContestApplyInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset)); $allCount = 0; $userHash = array(); $contestHash = array(); if (!empty($applyList)) { $allCount = OjContestApplyInterface::getCount($where); $userIds = array_column($applyList, 'user_id'); $userHash = UserCommonInterface::getById(array('id' => $userIds)); $contestIds = array_unique(array_column($applyList, 'contest_id')); $contestHash = OjContestInterface::getById(array('id' => $contestIds)); } // 缓存部分的html $html = array(); $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php'); $this->renderFramework(array('html' => $html, 'applyList' => $applyList, 'contestHash' => $contestHash, 'userHash' => $userHash), 'contest/apply_list.php'); }
public function defaultAction() { $pageSize = 50; // 获取参数 $page = Pager::get(); $contestId = (int) Request::getGET('contest-id'); $status = (int) Request::getGET('status', -1); $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo) || $contestInfo['hidden'] || $contestInfo['type'] != ContestVars::TYPE_APPLY) { $this->renderError('竞赛不存在,或者竞赛不需要报名!'); } // 构建where $where = array(); $where[] = array('contest_id', '=', $contestId); if ($status != -1) { $where[] = array('status', '=', $status); } // 获取数据 $offset = ($page - 1) * $pageSize; $applyList = OjContestApplyInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset)); $allCount = OjContestApplyInterface::getCount($where); // userHash $userIds = array_unique(array_column($applyList, '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, 'applyList' => $applyList, 'contestInfo' => $contestInfo, 'userHash' => $userHash), 'contest/apply_list.php'); }
public function ajaxApplyAction() { if (empty($this->loginUserInfo)) { $this->renderError('请登录!'); } $contestId = (int) Request::getPOST('contest-id'); $realName = trim(Request::getPOST('real-name')); $xuehao = trim(Request::getPOST('xuehao')); $xueyuan = (int) Request::getPOST('xueyuan'); $sex = (int) Request::getPOST('sex'); // 校验 if (empty($realName) || empty($xuehao) || empty($xueyuan) || empty($sex) || !array_key_exists($xueyuan, ContestVars::$XUEYUAN) || !in_array($sex, array(1, 2)) || mb_strlen($realName, 'utf8') < 2 || mb_strlen($realName, 'utf8') > 4) { $this->renderError('参数错误!'); } $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('比赛不存在!'); } if ($contestInfo['type'] != ContestVars::TYPE_APPLY) { $this->renderError('比赛不需要报名!'); } if ($contestInfo['end_time'] < time()) { $this->renderError('比赛已经结束!'); } $applyInfo = OjContestApplyInterface::getDetail(array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'])); if (!empty($applyInfo) && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED) { $this->renderError('报名已通过,无法修改!'); } $data = array('contest_id' => $contestId, 'user_id' => $this->loginUserInfo['id'], 'real_name' => $realName, 'xuehao' => $xuehao, 'xueyuan' => $xueyuan, 'sex' => $sex); OjContestApplyInterface::save($data); $this->renderAjax(0); }
public function defaultAction() { $contestId = Request::getGET('contest-id'); $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } $this->renderFramework(array('contestInfo' => $contestInfo), 'contest/detail.php'); }
public function ajaxSubmitAction() { // 获取参数 $contestId = (int) Request::getPOST('contest-id'); $title = trim(Request::getPOST('title')); $type = Request::getPOST('type'); $password = trim(Request::getPOST('password')); $notice = trim(Request::getPOST('notice')); $beginTime = strtotime(trim(Request::getPOST('begin-time'))); $endTime = strtotime(trim(Request::getPOST('end-time'))); $description = Request::getPOST('description', '', true); $problemHidden = Request::getPOST('problem-hidden', 0); // 参数校验1 if (empty($title) || mb_strlen($title, 'utf8') > 50) { $this->renderError('标题必填,限制50个字以内!'); } if (mb_strlen($notice, 'utf8') > 100) { $this->renderError('提示限制100个字以内!'); } if (!preg_match('/^[A-Za-z0-9_]{0,20}$/', $password)) { $this->renderError('密码格式不合法!'); } if ($type == ContestVars::TYPE_PASSWORD && empty($password)) { $this->renderError('密码不能为空!'); } if (empty($type) || !array_key_exists($type, ContestVars::$TYPE_FORMAT)) { $this->renderError('请选择比赛访问权限!'); } // 竞赛是否存在 $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } // 权限 if ($contestInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('你没有权限操作!'); } // 参数校验2 if ($contestInfo['is_active']) { $beginTime = $contestInfo['begin_time']; } if (empty($beginTime) || empty($endTime) || $beginTime >= $endTime) { $this->renderError('比赛时间不合法!'); } // 时间不能超过1年 if ($endTime - $beginTime > 366 * 86400) { $this->renderError('比赛时间不能超过1年!'); } $data = array('id' => $contestId, 'title' => $title, 'type' => $type, 'password' => $password, 'notice' => $notice, 'begin_time' => $beginTime, 'end_time' => $endTime, 'description' => $description, 'problem_hidden' => $problemHidden ? 1 : 0); OjContestInterface::save($data); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!'); $this->renderAjax(0); }
public function defaultAction() { $contestId = Request::getGET('contest-id'); $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } // 权限 if ($contestInfo['user_id'] != $this->loginUserInfo['id']) { $this->renderError('你没有权限查看!'); } $this->renderFramework(array('contestInfo' => $contestInfo), 'setup/contest/detail.php'); }
public function ajaxHideAction() { $contestId = Request::getPOST('contest-id'); $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } if ($contestInfo['hidden']) { $this->renderError('竞赛已经隐藏!'); } OjContestInterface::hide(array('id' => $contestId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '隐藏成功!'); $this->renderAjax(0); }
public function ajaxRemoveProblemAction() { $contestId = (int) Request::getPOST('contest-id'); $globalId = (int) Request::getPOST('global-id'); $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo)) { $this->renderError('题目不存在!'); } $contestInfo = OjContestInterface::getById(array('id' => $contestId)); if (empty($contestInfo)) { $this->renderError('竞赛不存在!'); } // 更新数据 OjContestInterface::removeProblem(array('id' => $contestId, 'global_id' => $globalId)); $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '移除成功!'); $this->renderAjax(0); }