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()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $status = (int) Request::getGET('status');
     // 构建where
     $where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1));
     if (!empty($status) && $status != -1) {
         $where[] = array('hidden', '=', $status - 1);
     }
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     // 获取数据
     $offset = ($page - 1) * $pageSize;
     $contestList = OjContestInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = 0;
     if (!empty($contestList)) {
         $allCount = OjContestInterface::getCount($where);
     }
     $userIds = array_unique(array_column($contestList, '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('contestList' => $contestList, 'userHash' => $userHash, 'html' => $html), 'setup/contest/list.php');
 }
 public function defaultAction()
 {
     $pageSize = 20;
     // 获取参数
     $page = Pager::get();
     $title = Request::getGET('title');
     $passed = (int) Request::getGET('passed', 0);
     $diy = (int) Request::getGET('diy', 0);
     // 构建where
     $where = array();
     $where[] = array('hidden', '=', 0);
     if ($passed) {
         $where[] = array('end_time', '<=', time());
     } else {
         $where[] = array('end_time', '>', time());
     }
     if ($diy) {
         $where[] = array('is_diy', '=', 1);
     } else {
         $where[] = array('is_diy', '=', 0);
     }
     if (!empty($title)) {
         $where[] = array('title', 'LIKE', "%{$title}%");
     }
     if ($passed) {
         $order = array('end_time' => 'DESC');
     } else {
         $order = array('end_time' => 'ASC');
     }
     // 获取数据
     $offset = ($page - 1) * $pageSize;
     $tmpContestList = OjContestInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset));
     $allCount = OjContestInterface::getCount($where);
     // 将进行中的比赛提前
     $contestList = array();
     if (!$passed) {
         foreach ($tmpContestList as $i => $contestInfo) {
             if ($contestInfo['begin_time'] < time()) {
                 $contestList[] = $contestInfo;
                 unset($tmpContestList[$i]);
             }
         }
         foreach ($tmpContestList as $i => $contestInfo) {
             $contestList[] = $contestInfo;
             unset($tmpContestList[$i]);
         }
     } else {
         $contestList = $tmpContestList;
     }
     $userIds = array_unique(array_column($contestList, 'user_id'));
     $userHash = UserCommonInterface::getById(array('id' => $userIds));
     // 格式化
     foreach ($contestList as &$contestInfo) {
         // row_class
         $now = time();
         if ($contestInfo['end_time'] < $now) {
             $contestInfo['row_css'] = 'passed';
         } else {
             if ($contestInfo['begin_time'] > $now) {
                 $contestInfo['row_css'] = 'pending';
             } else {
                 $contestInfo['row_css'] = 'running';
             }
         }
         // type_format
         $type = $contestInfo['type'];
         if ($type == ContestVars::TYPE_PUBLIC) {
             $contestInfo['type_format'] = '<p class="red">公开</p>';
         } else {
             if ($type == ContestVars::TYPE_APPLY) {
                 $contestInfo['type_format'] = '<p class="orange">报名</p>';
             } else {
                 if ($type == ContestVars::TYPE_PASSWORD) {
                     $contestInfo['type_format'] = '<p class="green">密码</p>';
                 } else {
                     $contestInfo['type_format'] = '<p class="gray">未定义</p>';
                 }
             }
         }
     }
     // 缓存部分的html
     $html = array();
     $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
     // 输出
     $this->renderFramework(array('contestList' => $contestList, 'userHash' => $userHash, 'html' => $html), 'contest/list.php');
 }