TeamController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * 班级管理控制器类
  4. * @author jiangfei
  5. * @date 2015-09-22 10:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class TeamController extends Controller{
  9. // 首页
  10. public function actionIndex(){
  11. $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
  12. if(!$get_id){
  13. Yii::app()->jump->error('参数错误!');
  14. }
  15. $data=array();
  16. $data['teamData']=$this->schoolManager->getTeamByClass($get_id);
  17. //读取所有分组
  18. //debug($data);
  19. $data['cid']=$get_id;
  20. $this->render('index',$data);
  21. }
  22. //添加小组
  23. public function actionAdd_team(){
  24. $team_name = safe_replace(Req::post('team_name'));
  25. $cid = safe_replace(Req::post('cid'));
  26. $team_id = safe_replace(Req::post('team_id'));
  27. $result['status']=0;
  28. if(!$team_name){
  29. $result['msg']='添加失败,参数不正确';
  30. exit(json_encode($result));
  31. }
  32. $TeamModel=new STeam();
  33. if($team_id){
  34. $checkData=$TeamModel->fetchById($team_id);
  35. if(!$checkData){
  36. $result['msg']='编辑失败,分组不存在';
  37. exit(json_encode($result));
  38. }
  39. $checkRepeat=$TeamModel->getByName($team_name,$cid);
  40. if($checkRepeat && $checkRepeat['team_id']!=$team_id){
  41. $result['msg']='编辑失败,分组名称已存在';
  42. exit(json_encode($result));
  43. }
  44. if($TeamModel->updateTeam($team_name,$team_id)){
  45. $result['status']=1;
  46. exit(json_encode($result));
  47. }else{
  48. $result['msg']='编辑失败';
  49. exit(json_encode($result));
  50. }
  51. }else{
  52. $checkRepeat=$TeamModel->getByName($team_name,$cid);
  53. if($checkRepeat){
  54. $result['msg']='添加失败,分组已经存在';
  55. exit(json_encode($result));
  56. }
  57. if($team_id=$TeamModel->addTeam($team_name,$cid)){
  58. $result['status']=1;
  59. $result['team_id']=$team_id;
  60. exit(json_encode($result));
  61. }else{
  62. $result['msg']='添加失败';
  63. exit(json_encode($result));
  64. }
  65. }
  66. }
  67. //编辑小组
  68. public function actionEdit_team(){
  69. $team_name=$getName = safe_replace(Yii::app()->request->getQuery('Name'));
  70. $cid=$getName = safe_replace(Yii::app()->request->getQuery('cid'));
  71. $team_id=safe_replace(Yii::app()->request->getQuery('tid'));
  72. }
  73. //删除整组
  74. public function actionDel_team(){
  75. $team_id=safe_replace(Req::post('team_id'));
  76. $result['status']=0;
  77. if(!$team_id){
  78. $result['msg']='操作失败,参数不正确';
  79. exit(json_encode($result));
  80. }
  81. $TeamModel=new STeam();
  82. //判断小组是否有学生
  83. $team_student=$TeamModel->getStudentByTeamId($team_id);
  84. if($team_student){
  85. if($TeamModel->delTeam($team_id)){
  86. $result['status']=1;
  87. exit(json_encode($result));
  88. }
  89. }else{
  90. if($TeamModel->delRealTeam($team_id)){
  91. $result['status']=1;
  92. exit(json_encode($result));
  93. }
  94. }
  95. $result['msg']='操作失败';
  96. exit(json_encode($result));
  97. }
  98. //学生列表
  99. public function actionGetStudent(){
  100. $cid=safe_replace(Req::post('cid'));
  101. $student_list=$this->schoolManager->getStudentByClassId($cid); //所有学生列表
  102. //已分组学生列表
  103. $team_student=$this->schoolManager->getTeamByClass($cid,'student'); //所有学生列表
  104. $html='';
  105. $html.="<tr>";
  106. $html.="<td></td>";
  107. $html.="<td>姓名</td>";
  108. $html.="<td>性别</td>";
  109. $html.="<td>系统准考证号</td>";
  110. $html.="<td>学校准考证号</td>";
  111. $html.="<td>学号</td>";
  112. $html.="<td>分组状态</td>";
  113. $html.="</tr>";
  114. if($student_list){
  115. foreach ($student_list as $key=>$val){
  116. if(in_array($val['student_id'],$team_student)){
  117. $student_list[$key]['assign']=1;
  118. }else{
  119. $student_list[$key]['assign']=0;
  120. }
  121. if($val['sex']==1){
  122. $sex='男';
  123. }else{
  124. $sex='女';
  125. }
  126. $html.="<tr>";
  127. if(isset($team_student[$val['student_id']])) {
  128. $html .= '<td><input type="checkbox" class="checkbox-add-group-student-list" name="student-list" value="'.$val['student_id'].'" disabled="disabled"></td>';
  129. $groupType=$team_student[$val['student_id']];
  130. }else{
  131. $html .= '<td><input type="checkbox" class="checkbox-add-group-student-list" name="student-list" value="'.$val['student_id'].'" ></td>';
  132. $groupType='未分组';
  133. }
  134. $html.="<td class='realname'>{$val['realname']}</td>";
  135. $html.="<td>{$sex}</td>";
  136. $html.="<td class='student_card'>{$val['student_card']}</td>";
  137. $html.="<td>{$val['school_student_card']}</td>";
  138. $html.="<td>{$val['userno']}</td>";
  139. $html.="<td>{$groupType}</td>";
  140. $html.="</tr>";
  141. }
  142. }
  143. $result['status']=1;
  144. $result['data']=$html;
  145. exit(json_encode($result));
  146. }
  147. //添加学生
  148. public function actionAdd_student(){
  149. $studentId=Req::post('student_id');
  150. $realname=Req::post('realname');
  151. $student_card=Req::post('student_card');
  152. $team_id=Req::post('team_id');
  153. $class_id=Req::post('cid');
  154. $result['status']=0;
  155. if(!$team_id || !$studentId || !$realname || !$student_card || !$class_id){
  156. $result['msg']='添加失败,参数不正确';
  157. exit(json_encode($result));
  158. }
  159. $insert=array();
  160. foreach ($studentId as $key=>$val){
  161. $insert[]=array(
  162. 'team_id'=>$team_id,
  163. 'student_id'=>$val,
  164. 'class_id'=>$class_id,
  165. 'real_name'=>$realname[$key],
  166. 'student_card'=>$student_card[$key]
  167. );
  168. }
  169. $TeamModel=new STeam();
  170. if($insert){
  171. $rs =$TeamModel->addTeamStudent($insert);
  172. if($rs){
  173. $result['status']=1;
  174. }
  175. }
  176. exit(json_encode($result));
  177. }
  178. //删除学生
  179. public function actionDel_student(){
  180. $studentId=Req::post('student_id');
  181. $class_id=Req::post('cid');
  182. $result['status']=0;
  183. if( !$studentId || !$class_id){
  184. $result['msg']='添加失败,参数不正确';
  185. exit(json_encode($result));
  186. }
  187. $TeamModel=new STeam();
  188. $team_student=$TeamModel->getStudentByStudentIdClassId($studentId,$class_id);
  189. if(!$team_student){
  190. $result['msg']='学生已经删除';
  191. exit(json_encode($result));
  192. }
  193. if($TeamModel->delStudentByStudentIdClassId($studentId,$class_id)){
  194. $result['status']=1;
  195. exit(json_encode($result));
  196. }
  197. $result['msg']='删除失败';
  198. exit(json_encode($result));
  199. }
  200. }