123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * 教师管理模型类
- * @author jiangfei
- * @date 2015-08-03 17:30:00
- * @company 上海风车教育有限公司.
- */
- class Teacher extends MyActiveRecord{
-
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return 'teacher';
- }
-
-
- // 教练列表
- public function getTeacherList(){
- $data = array();
- $criteria = new CDbCriteria();
-
- $total = $this->count($criteria);
- $pager = new CPagination($total);
- $criteria->order = 'add_time desc';
-
- $pager->pageSize = 20;
- $pager->applyLimit($criteria);
- $data['result']=$this->findAll($criteria);
- $data['page']=$pager;
- $data['page_total']= $total;
- return $data;
- }
-
- // 根据id获取教师名称
- public function getTeacherName($tid){
- $info = $this->find('teacher_id=:tid',array(':tid'=>$tid));
- if (empty($info)) {
- return null;
- } else {
- return $info->teacher_name;
- }
- }
- public function getNameCount($name){
- if(empty($name)) return array('same'=>array(),'info'=>array());
- $idNameRel = $same = array();
- $nameStr = '';
- foreach($name as $val){
- $val = trim(preg_replace('/\d+/','',$val));
- $nameStr .= '"'.$val.'",';
- }
- $nameStr = substr($nameStr,0,-1);
- $sql = 'SELECT teacher_name,teacher_id FROM teacher WHERE teacher_name in ('.$nameStr.')';
- $res = $this->getDbConnection()->createCommand($sql)->queryAll();
- $teacherName = array();
- foreach($res as $value){
- $teacherName[] = $value['teacher_name'];
- }
- $valueCount = array_count_values($teacherName);
- foreach($valueCount as $node=>$item){
- if($item>1) $same[] = $node;
- }
- foreach($res as $val){
- $idNameRel[(string)$val['teacher_id']] = $val['teacher_name'];
- }
- return array('same'=>$same,'info'=>$idNameRel);
- }
- public function getTeacherSub(){
- $sql = 'SELECT teacher_id,subjects FROM teacher';
- $res = $this->getDbConnection()->createCommand($sql)->queryAll();
- $subArr = array();
- foreach($res as $value){
- $subArr[$value['teacher_id']] = $value['subjects'];
- }
- return $subArr;
- }
- public function getTeacherNames($subject=0){
- if($subject){
- $sql = "SELECT teacher_id,teacher_name FROM teacher where subjects='{$subject}' and status=0";
- }else{
- $sql = "SELECT teacher_id,teacher_name FROM teacher where status=0";
- }
- $res = $this->getDbConnection()->createCommand($sql)->queryAll();
- $Arr = array();
- foreach($res as $value){
- $Arr[$value['teacher_id']] = $value['teacher_name'];
- }
- return $Arr;
- }
- //根据姓名查询教师ID
- public function getTeacherIdByName($name){
- $sql="select teacher_id from teacher where teacher_name like '%$name%'";
- $res = $this->getDbConnection()->createCommand($sql)->queryAll();
- $Arr = array();
- foreach($res as $value){
- $Arr[] = $value['teacher_id'];
- }
- return $Arr;
- }
- }
|