ClassModel.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * 班级模型类
  4. * @author jiangfei
  5. * @date 2015-07-20 16:30:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class ClassModel extends MyActiveRecord{
  9. public static function model($className = __CLASS__){
  10. return parent::model($className);
  11. }
  12. public function tableName(){
  13. return 'class';
  14. }
  15. // 年级列表
  16. public function getClassList($semeseter_id=''){
  17. $data = array();
  18. $criteria = new CDbCriteria();
  19. $semeseter_id && $criteria->addCondition('semester_id="'.$semeseter_id.'"');
  20. $total = $this->count($criteria);
  21. $pager = new CPagination($total);
  22. $criteria->order = 'class_id desc';
  23. $pager->pageSize = 12;
  24. $pager->applyLimit($criteria);
  25. $data['result']=$this->findAll($criteria);
  26. $data['page']=$pager;
  27. $data['page_total']= $total;
  28. return $data;
  29. }
  30. public function getClassWithSort($sid)
  31. {
  32. $data = array();
  33. $sql = "select class_name,sort,class_id from class
  34. where semester_id = {$sid} and is_hide=0
  35. order by sort!=0 DESC,sort,class_id DESC";
  36. $data = $this->findAllBySql($sql);
  37. return $data;
  38. }
  39. public function saveClassSort($sql){
  40. return $this->getDbConnection()->createCommand($sql)->execute();
  41. }
  42. // 根据id获取班级级名称
  43. public function getClassName($cid){
  44. $info = $this->find('class_id=:cid',array(':cid'=>$cid));
  45. if (empty($info)) {
  46. return null;
  47. } else {
  48. return $info->class_name;
  49. }
  50. }
  51. // 获取助教当前学期管理班级
  52. public function getClassArray($sid,$cid) {
  53. $sql = 'SELECT c.class_id,c.class_name FROM '.$this->tableName().' as c where semester_id="'.$sid;
  54. $list = $this->findAllBySql($sql);
  55. return $list;
  56. }
  57. /**
  58. * 当前学期的班级
  59. * @作者:刘红伟
  60. * @时间:2016-07-19
  61. *
  62. */
  63. public function getClassBySemester($semester_id)
  64. {
  65. if($semester_id!=-1){
  66. $data = $this->findAll('semester_id=:semester_id',array(':semester_id'=>$semester_id));
  67. }else{
  68. $data = $this->findAll();
  69. }
  70. if($data)
  71. {
  72. return $data;
  73. }
  74. return false;
  75. }
  76. public function getClassBySemesternianji($semester_id,$nianji,$class_type=1)
  77. {
  78. if($nianji>=0){
  79. if($semester_id!=-1){
  80. $data = $this->findAll('semester_id=:semester_id and grade=:grade and class_type=:ct',array(':semester_id'=>$semester_id,":grade"=>$nianji,":ct"=>$class_type));
  81. }else{
  82. $data = $this->findAll('grade=:grade and class_type=:ct',array(":grade"=>$nianji,":ct"=>$class_type));
  83. }
  84. }else{
  85. if($semester_id!=-1){
  86. $data = $this->findAll('semester_id=:semester_id and class_type=:ct',array(':semester_id'=>$semester_id,":ct"=>$class_type));
  87. }else{
  88. $data = $this->findAll();
  89. }
  90. }
  91. if($data)
  92. {
  93. return $data;
  94. }
  95. return false;
  96. }
  97. //根据教师获取执教班级
  98. public function getSelectclassesByTeacher($sid,$tid) {
  99. $data = array();
  100. if(!empty($sid) && !empty($tid)){
  101. $sql = "select c.class_name,c.grade,c.class_id,c.class_type"
  102. . " from ".$this->tableName()." c "
  103. . "join teacher_class_relation tcr on c.class_id = tcr.class_id "
  104. . "where c.semester_id = '".$sid."'and tcr.teacher_id = ".$tid." and c.is_hide=0 order by c.sort !=0 desc,c.sort";
  105. $data = $this->findAllBySql($sql);
  106. }
  107. return $data;
  108. }
  109. //根据教师获取未执教班级
  110. public function getNoSelectclassesByTeacher($sid,$tid,$class_arr_select_ids_str) {
  111. $data = array();
  112. if(!empty($sid) && !empty($tid) ){
  113. if($class_arr_select_ids_str){
  114. $sql = "select DISTINCT(c.class_name),c.grade,c.class_id,c.class_type"
  115. . " from ".$this->tableName()." c "
  116. . "join teacher_class_relation tcr on c.class_id = tcr.class_id "
  117. . "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";
  118. }else{
  119. $sql = "select DISTINCT(c.class_name),c.grade,c.class_id,c.class_type"
  120. . " from ".$this->tableName()." c "
  121. . "join teacher_class_relation tcr on c.class_id = tcr.class_id "
  122. . "where c.semester_id = '".$sid."'and tcr.teacher_id != ".$tid." and c.is_hide=0 order by c.sort !=0 desc,c.sort";
  123. }
  124. $data = $this->findAllBySql($sql);
  125. }
  126. return $data;
  127. }
  128. public function getClassArrayByIds($cids) {
  129. if(!$cids || !is_array($cids)){
  130. return false;
  131. }
  132. $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';
  133. $list = $this->findAllBySql($sql);
  134. $result=array();
  135. if($list){
  136. foreach ($list as $val){
  137. $result[]=array(
  138. 'class_id'=>$val->class_id,
  139. 'class_name'=>$val->class_name,
  140. 'grade'=>$val->grade,
  141. );
  142. }
  143. }
  144. return $result;
  145. }
  146. //根据教师获取未执教班级
  147. public function getNoSelectclasses($sid,$class_arr_select_ids_str) {
  148. $data = array();
  149. $sql = "select DISTINCT(c.class_name),c.grade,c.class_id"
  150. . " from ".$this->tableName()." c "
  151. . "join teacher_class_relation tcr on c.class_id = tcr.class_id "
  152. . "where c.semester_id = '".$sid."' and c.is_hide=0 ";
  153. if($class_arr_select_ids_str){
  154. $sql.=" and tcr.class_id not in (".$class_arr_select_ids_str.")";
  155. }
  156. $data = $this->findAllBySql($sql);
  157. return $data;
  158. }
  159. public function getClassByName($name){
  160. if(empty($name)) return false;
  161. $name = '("'.implode('","',$name).'")';
  162. $sql = "SELECT class_name,class_id FROM class WHERE class_name in {$name}";
  163. $res = $this->getDbConnection()->createCommand($sql)->queryAll();
  164. $info = array();
  165. foreach($res as $key=>$val){
  166. $info[$val['class_name']] = $val['class_id'];
  167. }
  168. return $info;
  169. }
  170. //根据教师获取执教班级
  171. public function getSelectclassesByTeacherGrade($sid,$tid,$grade) {
  172. $data = array();
  173. if(!empty($sid) && !empty($tid) && $grade){
  174. $sql = "select c.class_name,c.grade,c.class_id,c.class_type"
  175. . " from ".$this->tableName()." c "
  176. . "join teacher_class_relation tcr on c.class_id = tcr.class_id "
  177. . "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";
  178. $data = $this->getDbConnection()->createCommand($sql)->queryAll();
  179. }
  180. return $data;
  181. }
  182. }