123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- /**
- * 班级管理控制器类
- * @author jiangfei
- * @date 2015-09-22 10:50:00
- * @company 上海风车教育有限公司.
- */
- class TeamController extends Controller{
- // 首页
- public function actionIndex(){
- $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
- if(!$get_id){
- Yii::app()->jump->error('参数错误!');
- }
- $data=array();
- $data['teamData']=$this->schoolManager->getTeamByClass($get_id);
- //读取所有分组
- //debug($data);
- $data['cid']=$get_id;
- $this->render('index',$data);
- }
- //添加小组
- public function actionAdd_team(){
- $team_name = safe_replace(Req::post('team_name'));
- $cid = safe_replace(Req::post('cid'));
- $team_id = safe_replace(Req::post('team_id'));
- $result['status']=0;
- if(!$team_name){
- $result['msg']='添加失败,参数不正确';
- exit(json_encode($result));
- }
- $TeamModel=new STeam();
- if($team_id){
- $checkData=$TeamModel->fetchById($team_id);
- if(!$checkData){
- $result['msg']='编辑失败,分组不存在';
- exit(json_encode($result));
- }
- $checkRepeat=$TeamModel->getByName($team_name,$cid);
- if($checkRepeat && $checkRepeat['team_id']!=$team_id){
- $result['msg']='编辑失败,分组名称已存在';
- exit(json_encode($result));
- }
- if($TeamModel->updateTeam($team_name,$team_id)){
- $result['status']=1;
- exit(json_encode($result));
- }else{
- $result['msg']='编辑失败';
- exit(json_encode($result));
- }
- }else{
- $checkRepeat=$TeamModel->getByName($team_name,$cid);
- if($checkRepeat){
- $result['msg']='添加失败,分组已经存在';
- exit(json_encode($result));
- }
- if($team_id=$TeamModel->addTeam($team_name,$cid)){
- $result['status']=1;
- $result['team_id']=$team_id;
- exit(json_encode($result));
- }else{
- $result['msg']='添加失败';
- exit(json_encode($result));
- }
- }
- }
- //编辑小组
- public function actionEdit_team(){
- $team_name=$getName = safe_replace(Yii::app()->request->getQuery('Name'));
- $cid=$getName = safe_replace(Yii::app()->request->getQuery('cid'));
- $team_id=safe_replace(Yii::app()->request->getQuery('tid'));
- }
- //删除整组
- public function actionDel_team(){
- $team_id=safe_replace(Req::post('team_id'));
- $result['status']=0;
- if(!$team_id){
- $result['msg']='操作失败,参数不正确';
- exit(json_encode($result));
- }
- $TeamModel=new STeam();
- //判断小组是否有学生
- $team_student=$TeamModel->getStudentByTeamId($team_id);
- if($team_student){
- if($TeamModel->delTeam($team_id)){
- $result['status']=1;
- exit(json_encode($result));
- }
- }else{
- if($TeamModel->delRealTeam($team_id)){
- $result['status']=1;
- exit(json_encode($result));
- }
- }
- $result['msg']='操作失败';
- exit(json_encode($result));
- }
- //学生列表
- public function actionGetStudent(){
- $cid=safe_replace(Req::post('cid'));
- $student_list=$this->schoolManager->getStudentByClassId($cid); //所有学生列表
- //已分组学生列表
- $team_student=$this->schoolManager->getTeamByClass($cid,'student'); //所有学生列表
- $html='';
- $html.="<tr>";
- $html.="<td></td>";
- $html.="<td>姓名</td>";
- $html.="<td>性别</td>";
- $html.="<td>系统准考证号</td>";
- $html.="<td>学校准考证号</td>";
- $html.="<td>学号</td>";
- $html.="<td>分组状态</td>";
- $html.="</tr>";
- if($student_list){
- foreach ($student_list as $key=>$val){
- if(in_array($val['student_id'],$team_student)){
- $student_list[$key]['assign']=1;
- }else{
- $student_list[$key]['assign']=0;
- }
- if($val['sex']==1){
- $sex='男';
- }else{
- $sex='女';
- }
- $html.="<tr>";
- if(isset($team_student[$val['student_id']])) {
- $html .= '<td><input type="checkbox" class="checkbox-add-group-student-list" name="student-list" value="'.$val['student_id'].'" disabled="disabled"></td>';
- $groupType=$team_student[$val['student_id']];
- }else{
- $html .= '<td><input type="checkbox" class="checkbox-add-group-student-list" name="student-list" value="'.$val['student_id'].'" ></td>';
- $groupType='未分组';
- }
- $html.="<td class='realname'>{$val['realname']}</td>";
- $html.="<td>{$sex}</td>";
- $html.="<td class='student_card'>{$val['student_card']}</td>";
- $html.="<td>{$val['school_student_card']}</td>";
- $html.="<td>{$val['userno']}</td>";
- $html.="<td>{$groupType}</td>";
- $html.="</tr>";
- }
- }
- $result['status']=1;
- $result['data']=$html;
- exit(json_encode($result));
- }
- //添加学生
- public function actionAdd_student(){
- $studentId=Req::post('student_id');
- $realname=Req::post('realname');
- $student_card=Req::post('student_card');
- $team_id=Req::post('team_id');
- $class_id=Req::post('cid');
- $result['status']=0;
- if(!$team_id || !$studentId || !$realname || !$student_card || !$class_id){
- $result['msg']='添加失败,参数不正确';
- exit(json_encode($result));
- }
- $insert=array();
- foreach ($studentId as $key=>$val){
- $insert[]=array(
- 'team_id'=>$team_id,
- 'student_id'=>$val,
- 'class_id'=>$class_id,
- 'real_name'=>$realname[$key],
- 'student_card'=>$student_card[$key]
- );
- }
- $TeamModel=new STeam();
- if($insert){
- $rs =$TeamModel->addTeamStudent($insert);
- if($rs){
- $result['status']=1;
- }
- }
- exit(json_encode($result));
- }
- //删除学生
- public function actionDel_student(){
- $studentId=Req::post('student_id');
- $class_id=Req::post('cid');
- $result['status']=0;
- if( !$studentId || !$class_id){
- $result['msg']='添加失败,参数不正确';
- exit(json_encode($result));
- }
- $TeamModel=new STeam();
- $team_student=$TeamModel->getStudentByStudentIdClassId($studentId,$class_id);
- if(!$team_student){
- $result['msg']='学生已经删除';
- exit(json_encode($result));
- }
- if($TeamModel->delStudentByStudentIdClassId($studentId,$class_id)){
- $result['status']=1;
- exit(json_encode($result));
- }
- $result['msg']='删除失败';
- exit(json_encode($result));
- }
- }
|