STeam.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class STeam extends Model {
  7. function __construct(){
  8. parent::__construct();
  9. }
  10. public function getByName($name,$class_id){
  11. if(!$name || !$class_id) return false;
  12. $result = $this->sConn->createCommand()
  13. ->select("team_id,class_id,team_name")
  14. ->from('class_team')
  15. ->where("team_name = '". $name ."' and class_id='".$class_id."'")
  16. ->query()
  17. ->read();
  18. return $result;
  19. }
  20. public function addTeam($name,$class_id){
  21. if(!$name || !$class_id) return false;
  22. $insert="insert into class_team(`class_id`,`team_name`) values('".$class_id."','".$name."')";
  23. $res=$this->sConn->createCommand($insert)->execute();
  24. if($res){
  25. $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
  26. $team_id=$last_insert_id['last_insert_id()'];
  27. return $team_id;
  28. }
  29. return false;
  30. }
  31. public function fetchById($id){
  32. if(!$id || !is_numeric($id)){
  33. return null;
  34. }
  35. $result=$this->sConn->createCommand()
  36. ->select("team_id,class_id,team_name")
  37. ->from('class_team')
  38. ->where("team_id='".$id."'")
  39. ->query()
  40. ->read();
  41. return $result;
  42. }
  43. //添加分组学生
  44. public function addTeamStudent($insertArr){
  45. if(!is_array($insertArr)) return false;
  46. $rs=false;
  47. $insql="insert into class_student_team(`team_id`,`student_id`,`class_id`,`real_name`,`student_card`) values ";
  48. $values=array();
  49. foreach ($insertArr as $value){
  50. if(!$value['team_id'] || !$value['student_id'] || !$value['class_id'] || !$value['real_name'] || !$value['student_card']){
  51. continue;
  52. }
  53. $values[]="('".$value['team_id']."','".$value['student_id']."','".$value['class_id']."','".$value['real_name']."','".$value['student_card']."')";
  54. }
  55. if($values){
  56. $insql.=implode(',',$values);
  57. $rs=$this->sConn->createCommand($insql)->execute();
  58. }
  59. return $rs;
  60. }
  61. //查询学生
  62. public function getStudentByStudentIdClassId($student_id,$class_id){
  63. if(!$student_id || !$class_id) return false;
  64. return $this->sConn->createCommand("select team_id from class_student_team where student_id='{$student_id}' and class_id='{$class_id}'")->queryAll();
  65. }
  66. //删除学生
  67. public function delStudentByStudentIdClassId($student_id,$class_id){
  68. if(!$student_id || !$class_id) return false;
  69. return $this->sConn->createCommand("delete from class_student_team where student_id='{$student_id}' and class_id='{$class_id}'")->execute();
  70. }
  71. //删除分组学生
  72. public function delTeam($team_id){
  73. if(!$team_id) return false;
  74. return $this->sConn->createCommand("delete from class_student_team where team_id='{$team_id}' ")->execute();
  75. }
  76. //更新分组名称
  77. public function updateTeam($name,$team_id){
  78. if(!$team_id || !$name) return false;
  79. return $this->sConn->createCommand("update class_team set team_name='".$name."' where team_id='{$team_id}' ")->execute();
  80. }
  81. //查询分组学生
  82. public function getStudentByTeamId($team_id){
  83. if(!$team_id) return false;
  84. return $this->sConn->createCommand("select team_id from class_student_team where team_id='{$team_id}'")->queryAll();
  85. }
  86. //删除分组学生
  87. public function delRealTeam($team_id){
  88. if(!$team_id) return false;
  89. return $this->sConn->createCommand("delete from class_team where team_id='{$team_id}' ")->execute();
  90. }
  91. }