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; } }