123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- /**
- * 班级模型类
- * @author jiangfei
- * @date 2015-07-20 16:30:00
- * @company 上海风车教育有限公司.
- */
- class ClassModel extends MyActiveRecord{
-
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return 'class';
- }
-
- // 年级列表
- public function getClassList($semeseter_id=''){
-
- $data = array();
- $criteria = new CDbCriteria();
- $semeseter_id && $criteria->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;
- }
- }
|