Teacher.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 教师管理模型类
  4. * @author jiangfei
  5. * @date 2015-08-03 17:30:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class Teacher extends MyActiveRecord{
  9. public static function model($className = __CLASS__){
  10. return parent::model($className);
  11. }
  12. public function tableName(){
  13. return 'teacher';
  14. }
  15. // 教练列表
  16. public function getTeacherList(){
  17. $data = array();
  18. $criteria = new CDbCriteria();
  19. $total = $this->count($criteria);
  20. $pager = new CPagination($total);
  21. $criteria->order = 'add_time desc';
  22. $pager->pageSize = 20;
  23. $pager->applyLimit($criteria);
  24. $data['result']=$this->findAll($criteria);
  25. $data['page']=$pager;
  26. $data['page_total']= $total;
  27. return $data;
  28. }
  29. // 根据id获取教师名称
  30. public function getTeacherName($tid){
  31. $info = $this->find('teacher_id=:tid',array(':tid'=>$tid));
  32. if (empty($info)) {
  33. return null;
  34. } else {
  35. return $info->teacher_name;
  36. }
  37. }
  38. public function getNameCount($name){
  39. if(empty($name)) return array('same'=>array(),'info'=>array());
  40. $idNameRel = $same = array();
  41. $nameStr = '';
  42. foreach($name as $val){
  43. $val = trim(preg_replace('/\d+/','',$val));
  44. $nameStr .= '"'.$val.'",';
  45. }
  46. $nameStr = substr($nameStr,0,-1);
  47. $sql = 'SELECT teacher_name,teacher_id FROM teacher WHERE teacher_name in ('.$nameStr.')';
  48. $res = $this->getDbConnection()->createCommand($sql)->queryAll();
  49. $teacherName = array();
  50. foreach($res as $value){
  51. $teacherName[] = $value['teacher_name'];
  52. }
  53. $valueCount = array_count_values($teacherName);
  54. foreach($valueCount as $node=>$item){
  55. if($item>1) $same[] = $node;
  56. }
  57. foreach($res as $val){
  58. $idNameRel[(string)$val['teacher_id']] = $val['teacher_name'];
  59. }
  60. return array('same'=>$same,'info'=>$idNameRel);
  61. }
  62. public function getTeacherSub(){
  63. $sql = 'SELECT teacher_id,subjects FROM teacher';
  64. $res = $this->getDbConnection()->createCommand($sql)->queryAll();
  65. $subArr = array();
  66. foreach($res as $value){
  67. $subArr[$value['teacher_id']] = $value['subjects'];
  68. }
  69. return $subArr;
  70. }
  71. public function getTeacherNames($subject=0){
  72. if($subject){
  73. $sql = "SELECT teacher_id,teacher_name FROM teacher where subjects='{$subject}' and status=0";
  74. }else{
  75. $sql = "SELECT teacher_id,teacher_name FROM teacher where status=0";
  76. }
  77. $res = $this->getDbConnection()->createCommand($sql)->queryAll();
  78. $Arr = array();
  79. foreach($res as $value){
  80. $Arr[$value['teacher_id']] = $value['teacher_name'];
  81. }
  82. return $Arr;
  83. }
  84. //根据姓名查询教师ID
  85. public function getTeacherIdByName($name){
  86. $sql="select teacher_id from teacher where teacher_name like '%$name%'";
  87. $res = $this->getDbConnection()->createCommand($sql)->queryAll();
  88. $Arr = array();
  89. foreach($res as $value){
  90. $Arr[] = $value['teacher_id'];
  91. }
  92. return $Arr;
  93. }
  94. }