find('student_id=:stid',array(':stid'=>$id)); if (empty($info)) { return null; } else { return $info->username; } } public function getStudentByUsernames($userNames) { $criteria = new CDbCriteria(); $criteria->addInCondition('username',$userNames); $info = $this->findAll($criteria); if (empty($info)) { return false; } else { return $info; } } public function getStudentByUsernamesAndSchoolId($userNames,$school_id) { $criteria = new CDbCriteria(); $criteria->addInCondition('username',$userNames); $criteria->addCondition('school_id=:school_id'); $criteria->params[':school_id']=$school_id; $info = $this->findAll($criteria); if (empty($info)) { return false; } else { return $info; } } public function getStatus1ByStudentIds($studentIds,$school_id)//获取有效学生 { $student_id=array(); if ($studentIds && is_array($studentIds)) { $criteria = new CDbCriteria(); $criteria->addCondition('school_id=:school_id'); $criteria->params[':school_id']=$school_id; $criteria->addCondition('status=0'); $criteria->addInCondition('student_id', $studentIds); $students = getAttributes($this->findAll($criteria)); if ($students) { foreach ($students as $student) { $student_id[]=$student['student_id']; } } } return $student_id; } public function getCardsByStudentIds($studentIds) { $result = array(); if ($studentIds && is_array($studentIds)) { $criteria = new CDbCriteria(); $criteria->select = 'student_id, student_card, school_student_card'; $criteria->addInCondition('student_id', $studentIds); $students = getAttributes($this->findAll($criteria)); if ($students) { $result[0] = array(); $result[1] = array(); foreach ($students as $student) { $result[0][$student['student_id']] = $student['student_card']; $result[1][$student['student_id']] = $student['school_student_card']; } } } return $result; } //过滤无效学生 public function keepStudentsStatus_0($studentIds){ $result = array(); if ($studentIds && is_array($studentIds)) { $criteria = new CDbCriteria(); $criteria->select = 'student_id,status'; $criteria->addInCondition('student_id',$studentIds); $students = getAttributes($this->findAll($criteria)); if($students){ foreach($students as $student){ if($student['status'] == 0){ $result[] = $student['student_id']; } } } } return $result; } //分页获取学生数据 public function getStudentsByPages($schoolId){ $result = array(); $sql = "select count(0) as count from student where school_id = '{$schoolId}' order by student_id desc"; $countArr = Yii::app()->businessDb->createCommand($sql)->queryRow(); if($countArr && $countArr['count']){ $count = $countArr['count']; $limit = 10000; $page = ceil($count/$limit); $_sql = "select `student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time` from student where school_id = '{$schoolId}' order by student_id desc"; for($a = 1;$a <= $page;$a++){ $offset = ($a - 1)*$limit; $_sqls = $_sql." limit {$offset},{$limit}"; $data = Yii::app()->businessDb->createCommand($_sqls)->queryAll(); foreach($data as $k=>$v){ $result['b_student'][$v['student_id']] = $v; $result['b_student_ids'][$v['student_id']] = $v['student_id']; $result['b_id_student_cards'][$v['student_id']] = $v['student_card']; $result['b_id_school_student_cards'][$v['student_id']] = $v['school_student_card']; $result['b_id_zhixue_student_cards'][$v['student_id']] = $v['zhixue_student_card']; if($v['student_card']) { $result['b_student_cards'][$v['student_card']] = $v['student_id']; } if($v['school_student_card']) { $result['b_school_student_cards'][$v['school_student_card']] = $v['student_id']; } } unset($data); } } return $result; } //获取学生数据(schoolId,zhixue_student_card) public function getStudentsBySchoolIdAndZhixuecard($schoolId,$zhixue_student_card){ $result = array(); if(!$zhixue_student_card){ $zhixue_student_card = array(); } $sql = "select student_id,zhixue_student_card from student where school_id = '{$schoolId}' and zhixue_student_card in (".implode(',',$zhixue_student_card).")"; $data = Yii::app()->businessDb->createCommand($sql)->queryAll(); if($data){ return $data; }else{ return $result; } } }