addCondition('semester_id="'.$semeseter_id.'"'); $total = $this->count($criteria); $pager = new CPagination($total); $criteria->order = 'class_id desc'; $pager->pageSize = 12; $pager->applyLimit($criteria); $data['result']=$this->findAll($criteria); $data['page']=$pager; $data['page_total']= $total; return $data; } public function getClassWithSort($sid) { $data = array(); $sql = "select class_name,sort,class_id from class where semester_id = {$sid} and is_hide=0 order by sort!=0 DESC,sort,class_id DESC"; $data = $this->findAllBySql($sql); return $data; } public function saveClassSort($sql){ return $this->getDbConnection()->createCommand($sql)->execute(); } // 根据id获取班级级名称 public function getClassName($cid){ $info = $this->find('class_id=:cid',array(':cid'=>$cid)); if (empty($info)) { return null; } else { return $info->class_name; } } // 获取助教当前学期管理班级 public function getClassArray($sid,$cid) { $sql = 'SELECT c.class_id,c.class_name FROM '.$this->tableName().' as c where semester_id="'.$sid; $list = $this->findAllBySql($sql); return $list; } /** * 当前学期的班级 * @作者:刘红伟 * @时间:2016-07-19 * */ public function getClassBySemester($semester_id) { if($semester_id!=-1){ $data = $this->findAll('semester_id=:semester_id',array(':semester_id'=>$semester_id)); }else{ $data = $this->findAll(); } if($data) { return $data; } return false; } public function getClassBySemesternianji($semester_id,$nianji,$class_type=1) { if($nianji>=0){ if($semester_id!=-1){ $data = $this->findAll('semester_id=:semester_id and grade=:grade and class_type=:ct',array(':semester_id'=>$semester_id,":grade"=>$nianji,":ct"=>$class_type)); }else{ $data = $this->findAll('grade=:grade and class_type=:ct',array(":grade"=>$nianji,":ct"=>$class_type)); } }else{ if($semester_id!=-1){ $data = $this->findAll('semester_id=:semester_id and class_type=:ct',array(':semester_id'=>$semester_id,":ct"=>$class_type)); }else{ $data = $this->findAll(); } } if($data) { return $data; } return false; } //根据教师获取执教班级 public function getSelectclassesByTeacher($sid,$tid) { $data = array(); if(!empty($sid) && !empty($tid)){ $sql = "select c.class_name,c.grade,c.class_id,c.class_type" . " from ".$this->tableName()." c " . "join teacher_class_relation tcr on c.class_id = tcr.class_id " . "where c.semester_id = '".$sid."'and tcr.teacher_id = ".$tid." and c.is_hide=0 order by c.sort !=0 desc,c.sort"; $data = $this->findAllBySql($sql); } return $data; } //根据教师获取未执教班级 public function getNoSelectclassesByTeacher($sid,$tid,$class_arr_select_ids_str) { $data = array(); if(!empty($sid) && !empty($tid) ){ if($class_arr_select_ids_str){ $sql = "select DISTINCT(c.class_name),c.grade,c.class_id,c.class_type" . " from ".$this->tableName()." c " . "join teacher_class_relation tcr on c.class_id = tcr.class_id " . "where c.semester_id = '".$sid."'and tcr.teacher_id != ".$tid." and tcr.class_id not in (".$class_arr_select_ids_str.") and c.is_hide=0 order by c.sort !=0 desc,c.sort"; }else{ $sql = "select DISTINCT(c.class_name),c.grade,c.class_id,c.class_type" . " from ".$this->tableName()." c " . "join teacher_class_relation tcr on c.class_id = tcr.class_id " . "where c.semester_id = '".$sid."'and tcr.teacher_id != ".$tid." and c.is_hide=0 order by c.sort !=0 desc,c.sort"; } $data = $this->findAllBySql($sql); } return $data; } public function getClassArrayByIds($cids) { if(!$cids || !is_array($cids)){ return false; } $sql = 'SELECT c.class_id,c.class_name,c.grade FROM '.$this->tableName().' as c where class_id in('.implode(',',$cids).') order by c.sort !=0 desc,c.sort'; $list = $this->findAllBySql($sql); $result=array(); if($list){ foreach ($list as $val){ $result[]=array( 'class_id'=>$val->class_id, 'class_name'=>$val->class_name, 'grade'=>$val->grade, ); } } return $result; } //根据教师获取未执教班级 public function getNoSelectclasses($sid,$class_arr_select_ids_str) { $data = array(); $sql = "select DISTINCT(c.class_name),c.grade,c.class_id" . " from ".$this->tableName()." c " . "join teacher_class_relation tcr on c.class_id = tcr.class_id " . "where c.semester_id = '".$sid."' and c.is_hide=0 "; if($class_arr_select_ids_str){ $sql.=" and tcr.class_id not in (".$class_arr_select_ids_str.")"; } $data = $this->findAllBySql($sql); return $data; } public function getClassByName($name){ if(empty($name)) return false; $name = '("'.implode('","',$name).'")'; $sql = "SELECT class_name,class_id FROM class WHERE class_name in {$name}"; $res = $this->getDbConnection()->createCommand($sql)->queryAll(); $info = array(); foreach($res as $key=>$val){ $info[$val['class_name']] = $val['class_id']; } return $info; } //根据教师获取执教班级 public function getSelectclassesByTeacherGrade($sid,$tid,$grade) { $data = array(); if(!empty($sid) && !empty($tid) && $grade){ $sql = "select c.class_name,c.grade,c.class_id,c.class_type" . " from ".$this->tableName()." c " . "join teacher_class_relation tcr on c.class_id = tcr.class_id " . "where c.semester_id = '".$sid."'and tcr.teacher_id = ".$tid." and c.is_hide=0 and c.grade='".$grade."' order by c.sort !=0 desc,c.sort"; $data = $this->getDbConnection()->createCommand($sql)->queryAll(); } return $data; } }