public function action_status() { // init $page = $this->get_query('page', 1); if ($page < 1) { $page = 1; } $pid = $this->get_query('pid', null); $uid = $this->get_query('uid', null); $cid = $this->get_query('cid', null); $language = $this->get_query('language', null); $result = $this->get_query('result', null); $per_page = OJ::per_page; $filter = array('problem_id' => $pid, 'user_id' => $uid, 'contest_id' => $cid, 'language' => $language, 'result' => $result); $filter = $this->clear_data($filter, array(-1, '', null)); $orderby = array(Model_Solution::$primary_key => Model_Base::ORDER_DESC); $status = Model_Solution::find($filter, $page, $per_page, $orderby); $total = Model_Solution::count($filter); // view $this->template_data['title'] = __('solution.status.status'); $this->template_data['list'] = $status; $this->template_data['total'] = ceil($total / $per_page); if ($cid) { $contest = Model_Contest::find_by_id($cid); if (!$contest) { $this->go_home(); } $this->template_data['cid'] = $cid; $this->template_data['contest'] = $contest; $this->template_data['title'] = "{$contest['title']} - Status"; } }
public function action_submit() { $current_user = $this->check_login(); if ($this->request->is_post()) { $pid = $this->get_post('pid'); $cid = $this->get_post('cid', null); $cpid = $this->get_post('cpid', -1); // if no pid, then it should be contest // if contest id set, then this submit a contest problem if ($cid and $cpid !== -1) { $contest = Model_Contest::find_by_id($cid); if ($contest and $contest->can_user_access($current_user)) { $problem = $contest->problem($cpid); if (!$problem) { throw new Exception_Page(__('common.problem_not_found')); } } else { throw new Exception_Page(__('common.contest_not_found')); } } else { // so is normal submit $problem = Model_Problem::find_by_id($pid); if (!$problem or !$problem->can_user_access($current_user)) { throw new Exception_Page(__('common.problem_not_found')); } } $last_submission = $current_user->get_last_submission(); if ($last_submission) { $d_start = strtotime($last_submission); $d_end = time(); $limitation = OJ::get_submit_time(); if ($d_end - $d_start < $limitation) { throw new Exception_Page(__('common.too_quick_:sec', array(':sec' => $limitation))); } } $source_code = $this->get_raw_post('source'); $lang = $this->get_post('language'); $solution = Model_Solution::create($current_user, $problem, $lang, $source_code); if ($cid) { // set contest info $solution->contest_id = $cid; $solution->num = $cpid; } $solution->save(); // set user favorite language $current_user->language = $lang; $current_user->save(); $this->redirect('/status'); return; } else { $pid = $this->request->param('id', null); $this->template_data['pid'] = OJ::clean_data($pid); } $this->template_data['cid'] = $this->get_query('cid', null); $this->template_data['cpid'] = $this->get_query('pid', null); $this->template_data['default_lang'] = $current_user->language; $this->template_data['title'] = __('problem.submit.submit_code'); }
public function action_removeuser() { if ($this->request->method() == 'POST') { $cid = $this->request->post('cid', null); $user_id = $this->request->post('uid', null); $contest = Model_Contest::find_by_id($cid); $contest->remove_member($user_id); $this->response->body('{ok: 0}'); } }
/** * @param Model_Contest $contest * @throws Exception_Page */ protected function check_permission($contest) { $current_user = $this->get_current_user(); if ($contest and $contest->can_user_access($current_user)) { return; } //TODO: add more notice if ($current_user) { $message = __('common.contest_private'); } else { $message = __('common.contest_login_first'); } throw new Exception_Page($message); }