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_rejudge() { if ($this->request->is_post()) { $type = $this->get_post('type'); $id = intval($this->get_post('typeid')); if ($type == 'PROBLEM') { $problem = Model_Problem::find_by_id($id); if ($problem) { $problem->rejudge(); $this->flash_info(__('common.rejudge_:problem', array(':problem' => $problem->problem_id))); } } else { if ($type == 'SOLUTION') { $solution = Model_Solution::find_by_id($id); if ($solution) { $solution->rejudge(); $this->flash_info(__('common.rejudge_:runid', array(':runid' => $solution->solution_id))); } } } } $this->redirect('/admin/'); }
/** * @param Model_User $user * @param Model_Problem $problem * @param int $language * @param string $source_code * * @return Model_Solution */ public static function create($user, $problem, $language, $source_code) { $solution = new Model_Solution(); $solution->user_id = $user->user_id; $solution->problem_id = $problem->problem_id; $solution->language = $language; $solution->ip = Request::$client_ip; $solution->set_source_code($source_code); $problem->have_new_solution(); $user->take_new_submit(); return $solution; }
/** * the problem id list for user tried * * @return array */ public function problems_tried() { if (!$this->trying_problem_list) { $all_tried = Model_Solution::user_tried_problem($this->user_id); $resolved_problem = $this->problems_resolved(); $this->trying_problem_list = array_diff($all_tried, $resolved_problem); } return $this->trying_problem_list; }
public function solutions() { return Model_Solution::find_solution_for_contest($this->contest_id, $this->start_time, $this->end_time); }
/** * best solutions for problem * * @param int $page * @param int $limit * * @return Model_Solution[] */ public function best_solution($page = 0, $limit = 50) { return Model_Solution::solution_by_rank($this->problem_id, $page, $limit); }