123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- /**
- * @author: CeeFee
- * @description: 考试
- */
- class STeam extends Model {
- function __construct(){
- parent::__construct();
- }
- public function getByName($name,$class_id){
- if(!$name || !$class_id) return false;
- $result = $this->sConn->createCommand()
- ->select("team_id,class_id,team_name")
- ->from('class_team')
- ->where("team_name = '". $name ."' and class_id='".$class_id."'")
- ->query()
- ->read();
- return $result;
- }
- public function addTeam($name,$class_id){
- if(!$name || !$class_id) return false;
- $insert="insert into class_team(`class_id`,`team_name`) values('".$class_id."','".$name."')";
- $res=$this->sConn->createCommand($insert)->execute();
- if($res){
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $team_id=$last_insert_id['last_insert_id()'];
- return $team_id;
- }
- return false;
- }
- public function fetchById($id){
- if(!$id || !is_numeric($id)){
- return null;
- }
- $result=$this->sConn->createCommand()
- ->select("team_id,class_id,team_name")
- ->from('class_team')
- ->where("team_id='".$id."'")
- ->query()
- ->read();
- return $result;
- }
- //添加分组学生
- public function addTeamStudent($insertArr){
- if(!is_array($insertArr)) return false;
- $rs=false;
- $insql="insert into class_student_team(`team_id`,`student_id`,`class_id`,`real_name`,`student_card`) values ";
- $values=array();
- foreach ($insertArr as $value){
- if(!$value['team_id'] || !$value['student_id'] || !$value['class_id'] || !$value['real_name'] || !$value['student_card']){
- continue;
- }
- $values[]="('".$value['team_id']."','".$value['student_id']."','".$value['class_id']."','".$value['real_name']."','".$value['student_card']."')";
- }
- if($values){
- $insql.=implode(',',$values);
- $rs=$this->sConn->createCommand($insql)->execute();
- }
- return $rs;
- }
- //查询学生
- public function getStudentByStudentIdClassId($student_id,$class_id){
- if(!$student_id || !$class_id) return false;
- return $this->sConn->createCommand("select team_id from class_student_team where student_id='{$student_id}' and class_id='{$class_id}'")->queryAll();
- }
- //删除学生
- public function delStudentByStudentIdClassId($student_id,$class_id){
- if(!$student_id || !$class_id) return false;
- return $this->sConn->createCommand("delete from class_student_team where student_id='{$student_id}' and class_id='{$class_id}'")->execute();
- }
- //删除分组学生
- public function delTeam($team_id){
- if(!$team_id) return false;
- return $this->sConn->createCommand("delete from class_student_team where team_id='{$team_id}' ")->execute();
- }
- //更新分组名称
- public function updateTeam($name,$team_id){
- if(!$team_id || !$name) return false;
- return $this->sConn->createCommand("update class_team set team_name='".$name."' where team_id='{$team_id}' ")->execute();
- }
- //查询分组学生
- public function getStudentByTeamId($team_id){
- if(!$team_id) return false;
- return $this->sConn->createCommand("select team_id from class_student_team where team_id='{$team_id}'")->queryAll();
- }
- //删除分组学生
- public function delRealTeam($team_id){
- if(!$team_id) return false;
- return $this->sConn->createCommand("delete from class_team where team_id='{$team_id}' ")->execute();
- }
- }
|