/** * A handler of each state. * @param int state code */ public function state($state) { eval(USER); $cm = new ContestModel(); $contest = $cm->getCurrentContest(); $contest = $contest[0]; $qm = new QuizModel(); $this->assign('contestname', $contest['name']); $this->assign('contest', $contest); $team = DBModel::getTeamDetail(DBModel::getTeamByUser(session('userid'))); $states = DBModel::selectDB('cernet_statepage'); $this->assign('statepage', $states[$state - 1]['html']); switch ($state) { case 1: // dump($qm); $this->assign('total', $qm->getTotalOnce()); $this->assign('pass', $qm->getPass()); break; case 2: $conf = array(); $conf['user_id'] = session('userid'); $conf['statecode'] = 0; $model = D('cernet_teammate'); $invitations = $model->where($conf)->select(); $list = array(); foreach ($invitations as $invitation) { array_push($list, DBModel::getFullInvitation($invitation)); } $this->assign('list', $list); $this->assign('invitation', json_encode($invitations)); case 3: // invitation $conf = array(); $conf['user_id'] = session('userid'); $conf['statecode'] = 0; $model = D('cernet_teammate'); $invitations = $model->where($conf)->select(); $teamsize = $cm->getTeamSize(); $list = array(); foreach ($invitations as $invitation) { array_push($list, DBModel::getFullInvitation($invitation)); } $this->assign('list', $list); $this->assign('invitation', json_encode($invitations)); // inteam $this->assign('inteam', DBModel::inteam(session('userid')) ? 1 : ''); // get the team $this->assign('teamname', $team['team']['name']); $this->assign('leadername', getNameById('cernet_user', $team['team']['leader'])); $this->assign('isleader', DBModel::isLeader(session('userid'))); $this->assign('teamsize', $teamsize); $contest = $cm->getCurrentContest(); $contest = $contest[0]; $model = D('cernet_user'); $team_id = DBModel::getTeamByUser(session('userid')); $map['cernet_teammate.statecode'] = array(array('neq', 1), array('exp', 'is NULL'), 'OR'); $map['cernet_teammate.team_id'] = array(array('neq', $team_id), array('exp', 'is NULL'), 'OR'); $map['cernet_user.statecode'] = array(array('gt', 1), array('lt', 4)); // $map['cernet_user.statecode'] = 3; $userlist = $model->join('LEFT JOIN cernet_teammate ON cernet_user.id = cernet_teammate.user_id')->where($map)->field('cernet_teammate.statecode,id,name')->select(); $model = D('cernet_teammate'); unset($map['cernet_teammate.statecode']); $map['cernet_teammate.team_id'] = $team_id; $map['cernet_user.id'] = array('NEQ', session('userid')); $candidate = $model->join('LEFT JOIN cernet_user ON cernet_user.id = cernet_teammate.user_id')->field('cernet_teammate.statecode,id,name')->where($map)->select(); // dump($map); // dump($candidate); // die(); $team = DBModel::getTeamDetail($team_id); $this->assign('banner', $cm->getBanner()); $this->assign('team', $team); $this->assign('userlist', json_encode($userlist)); $this->assign('candidate', json_encode($candidate)); $this->assign('teamsize', $cm->getTeamSize()); $this->assign('contest', $contest); $this->assign("less", "buildteam" . ".less"); break; case 4: $this->assign('team', $team); $this->assign('mates', $team['teammate']); break; case 5: $team_id = DBModel::getTeamByUser(session('userid')); $teamdetail = DBModel::getTeamDetail($team_id)['team']; $post['post_time'] = $teamdetail['post_time']; $post['post_company'] = $teamdetail['post_company']; $post['post_id'] = $teamdetail['post_id']; $post['post_status'] = $teamdetail['post_status']; $this->assign('post', $post); $this->assign('team', $team['team']); break; case 6: break; case 8: $this->assign('prize', $team['team']['prize']); break; case 7: $this->assign('team', $team); $this->assign('mates', $team['teammate']); break; } }
public static function getSecondTeamDetail($team_id) { $model = D('second_team'); $matemod = D('second_teammate'); $conf['second_team.id'] = $team_id; $res = array(); $res['team'] = $model->where($conf)->find(); $res['teammate'] = $matemod->join("second_user ON second_teammate.user_id = second_user.id")->where(array('second_teammate.team_id' => $team_id))->select(); $res['teacher'] = $model->join('second_teacher ON second_teacher.id = second_team.teacher')->where($conf)->find() or -1; $res['tutor'] = $model->join('cernet_tutor ON cernet_tutor.id = second_team.tutor_id')->where($conf)->find() or -1; $res['report'] = $model->join('second_report ON second_team.report_id = second_report.id')->where($conf)->find() or -1; // get name by id $res['team']['universityname'] = getNameById('cernet_university', $res['team']['university']); foreach ($res['teammate'] as $k => $v) { $res['teammate'][$k]['universityname'] = getNameById('cernet_university', $v['university']); $res['teammate'][$k]['majorname'] = getNameById('cernet_major', $v['major']); $res['teammate'][$k]['cityname'] = getNameById('cernet_city', $v['city']); $res['teammate'][$k]['degreename'] = getNameById('cernet_degree', $v['degree']); $res['teammate'][$k]['isleader'] = DBModel::isLeader($v['id']); } // get leader $cond = array(); $cond['id'] = $res['team']['leader']; $res['leader'] = DBModel::getByFields('second_user', $cond); $res['leader'] = $res['leader'][0]; return $res; }