1,
"填空题" => 2,
"解答题" => 3,
);
public $msgs = array(
"global" => array(
"0" => "操作成功",
"1001" => "缺少参数",
"1002" => "系统错误",
),
"changeSemester" => array(
"2001" => "不能切换到已完成的学期",
"2002" => "",
"2003"=>"创建班级失败",
),
"delSemester" => array(
"2001" => "不能删除当前学期",
"2002" => "学期已关联班级",
),
"delClass" => array(
"2001" => "该班级已关联学生",
"2002" => "该班级已创建过考试",
),
"delTeacher" => array(
"2001" => "该老师已绑定班级",
"2002" => "该老师已创建过周周练",
),
"purgeTeacher" => array(
"2001" => "该老师已绑定班级",
"2002" => "该老师已创建过考试",
"2003" => "该老师还有未完成的阅卷任务",
"2004" => "该老师还有未处理的问题卷",
),
"purgeStudent" => array(
"2001" => "无法操作,该学生已存在考试数据",
),
"removeStudentClassRelation" => array(
"2001" => "该学生存在周周练数据",
),
"replaceIspTopic" => array(
"2001" => "新题目和被替换的题目相同,未替换",
"2002" => "被替换的题目在该提分册不存在",
"2003" => "新题目已经存在于该提分册,请选择别的题目",
),
);
public $inciseTables=array(
'student_paper_topic_rs',
'student_paper_relation',
'student_improve_score_plan_topics',
'student_wrong_plan_topics',
'student_upload_result'
);
function __construct($coachId, $role = ROLE_USER,$pad=''){
parent::__construct();
if($pad)
{
$this->role = $role;
$this->parentNotificationHost = Yii::app()->params["notification_host"];
$this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
$this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
$this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
$this->apiUrl = Yii::app()->params["api"][0]["prefix"];
$this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
$this->topicField = Yii::app()->params["topic_store"]["topic_field"];
$this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
$this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
$this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
$this->sTopic = new STopic();
}else
{
if(!$coachId)
throw new CException("助教ID不能为空");
$this->coachId = $coachId;
$this->role = $role;
$this->coach = $this->getMyInfo();
$this->coachRole = $this->coach["leader"];
$this->parentNotificationHost = Yii::app()->params["notification_host"];
$this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
$this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
$this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
$this->apiUrl = Yii::app()->params["api"][0]["prefix"];
$this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
$this->topicField = Yii::app()->params["topic_store"]["topic_field"];
$this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
$this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
$this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
$this->sTopic = new STopic();
}
}
protected function rs($code, $action = __FUNCTION__){
$rs = array();
if($code !== null){
if(is_array($code))
$codeStr = implode(", ", $code);
else
$codeStr = $code;
$rs = array(
"code" => $codeStr,
"msg" => $this->translateCode($code, $action),
);
}
return $rs;
}
protected function translateCode($code, $action = __FUNCTION__, $symbol = "
"){
$msg = array();
if($code !== null && isset($this->msgs[$action])){
if(!is_array($code))
$code = array($code);
$i = 1;
foreach($code as $val){
if(isset($this->msgs[$action][(string)$val])){
if($val != 0)
$msg[] = "{$this->msgs[$action][(string)$val]}";
else
$msg[] = "{$this->msgs[$action][(string)$val]}";
$i++;
}
}
}
if($msg){
$msg = implode($symbol, $msg);
}
else
$msg = "";
return $msg;
}
public function getTeachers($orderBy = array("teacher_id asc", "teacher_name asc")){
$teachers = array();
$orderBy = $this->orderBy($orderBy);
$rs = $this->sConn->createCommand("select * from teacher where status != 2 group by teacher_id{$orderBy}")->queryAll();
if($rs)
$teachers = $rs;
return $teachers;
}
public function getTeacherAccount($teacherId){
$account = array();
if($teacherId){
$account = $this->conn->createCommand("select * from xb_teacher where teacher_id = '{$teacherId}'")->queryRow();
}
return $account;
}
public function getTeachersAccounts($teachersIds){
if(!is_array($teachersIds) || !$teachersIds)
return array();
$teachersIds = "'".implode("','", $teachersIds)."'";
return $this->conn->createCommand("select * from xb_teacher where teacher_id in({$teachersIds})")->queryAll();
}
public function countTeachersAccountsPages($pageSize){
if(!$pageSize)
return 0;
$rs = $this->conn->createCommand("select count(*) from xb_teacher")->queryRow();
$rs = current($rs);
return ceil($rs / $pageSize);
}
public function getTeachersByClassesIds($classesIds){
$teachers = array();
if($classesIds){
$classesIds = "'".implode("','", $classesIds)."'";
return $this->sConn->createCommand("
select t.*, tcr.class_id,tcr.is_bzr,t.subjects,tcr.hxb_ing
from teacher_class_relation as tcr
join teacher as t on t.teacher_id = tcr.teacher_id
where tcr.class_id in($classesIds)
")->queryAll();
}
return $teachers;
}
public function getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name){
$teachers = array();
if($classesIds){
$classesIds = "'".implode("','", $classesIds)."'";
return $this->sConn->createCommand("
select t.*, tcr.class_id
from teacher_class_relation as tcr
join teacher as t on t.teacher_id = tcr.teacher_id
where tcr.class_id in($classesIds) and t.teacher_name LIKE '%{$teacher_name}%'
")->queryAll();
}
return $teachers;
}
public function getTeachersIdsByClassesIds($classesIds){
$classes = $this->getTeachersByClassesIds($classesIds);
return $this->grouping($classes, "teacher_id");
}
public function getMyInfo(){
return $this->conn->createCommand("select * from coach where coach_id = '{$this->coachId}'")->queryRow();
}
public function getNowClassesByTeacherId($teacherId,$class_id = 0){
$classes = array();
if($teacherId){
if($class_id >0){
$classes = $this->sConn->createCommand("
select c.*
from teacher_class_relation as tcr
join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
where tcr.teacher_id = '{$teacherId}' and c.class_id = '{$class_id}'
")->queryAll();
}else{
$classes = $this->sConn->createCommand("
select c.*
from teacher_class_relation as tcr
join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
where tcr.teacher_id = '{$teacherId}' and c.is_hide=0
")->queryAll();
}
}
return $classes;
}
public function getClassesByTeacherId($teacherId){
$classes = array();
if($teacherId){
$classes = $this->sConn->createCommand("
select c.*
from teacher_class_relation as tcr
join class as c on c.class_id = tcr.class_id
where tcr.teacher_id = '{$teacherId}'
")->queryAll();
}
return $classes;
}
/**
* 获取 上传试卷列表
*
* @author CeeFee
*/
public function getUploadPaperList($orderBy = array("add_time DESC", "id DESC"),$subject_id=3, $pageSize = 10)
{
$str = '';
$orderBy = $this->orderBy($orderBy);
if($subject_id==3)
{
$str = ' subject_id in ('.implode(',',Yii::app()->params['mathSubjectId']).')';
}else
{
$str = ' subject_id = '.$subject_id;
}
$handle = $this->sConn->createCommand("
SELECT * FROM upload_paper WHERE {$str}
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getTeachersList($orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
/*$orderBy = $this->orderBy($orderBy);
$classesIds = $this->getClassesIdsByCoachId($this->coachId);
$teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
$teachersIds = "'".implode("','", $teachersIds)."'";
$handle = $this->sConn->createCommand("
select * from teacher where coach_id = '{$this->coachId}' and status != 2
union
select * from teacher where teacher_id in({$teachersIds})
{$orderBy}
")->query();*/
/**
* 刘红伟修改
* 时间:2016-11-7
*/
$orderBy = $this->orderBy($orderBy);
/*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
$teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
$teachersIds = "'".implode("','", $teachersIds)."'";*/
$handle = $this->sConn->createCommand("
select * from teacher where status != 2 {$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$teachersIds = $this->grouping($rs["rs"], "teacher_id");
$teachersAccounts = $this->getTeachersAccounts($teachersIds);
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["businessphone"] = null;
$rs["rs"][$key]["class_name"] = null;
foreach($teachersAccounts as $account){
if($val["teacher_id"] == $account["teacher_id"]){
$rs["rs"][$key]["businessphone"] = $account["phone_number"];
$classes = $this->getNowClassesByTeacherId($val["teacher_id"]);
$classes = $this->grouping($classes, "class_name");
$classes = implode(",", $classes);
$rs["rs"][$key]["class_name"] = $classes;
}
}
}
return $rs;
}
public function getTeachersListre($teacher_name='',$subject_id = 0,$class_id = 0,$orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
/*$orderBy = $this->orderBy($orderBy);
$classesIds = $this->getClassesIdsByCoachId($this->coachId);
$teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
$teachersIds = "'".implode("','", $teachersIds)."'";
$handle = $this->sConn->createCommand("
select * from teacher where coach_id = '{$this->coachId}' and status != 2
union
select * from teacher where teacher_id in({$teachersIds})
{$orderBy}
")->query();*/
/**
* 刘红伟修改
* 时间:2016-11-7
*/
$orderBy = $this->orderBy($orderBy);
/*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
$teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
$teachersIds = "'".implode("','", $teachersIds)."'";*/
$condition=array();
if($teacher_name){
if(is_array($teacher_name)){
$condition[]="t.teacher_id in(".implode(',',$teacher_name).")";
}else{
$condition[]="t.teacher_name LIKE '%{$teacher_name}%'";
}
}
if($subject_id){
if(in_array($subject_id,Yii::app()->params['mathSubjectId'])){
$condition[]="t.subjects in(".implode(',',Yii::app()->params['mathSubjectId']).")";
}else{
$condition[]="t.subjects ='{$subject_id}'";
}
}
if($class_id){
$condition[]="tr.class_id = ".$class_id." and tr. semester_id = '".$this->semester["id"]."'";
$handle = $this->sConn->createCommand("
select t.*,tr.class_id from teacher as t LEFT JOIN teacher_class_relation tr on t.teacher_id = tr.teacher_id where ".implode(' and ',$condition)." GROUP by t.teacher_id HAVING tr.class_id >0 order by t.add_time desc
")->query();
}else{
if($condition){
$handle = $this->sConn->createCommand("select * from teacher t where ".implode(' and ',$condition)." {$orderBy}")->query();
}else{
$handle = $this->sConn->createCommand("select * from teacher {$orderBy}")->query();
}
}
$rs = $this->paging($this->sConn, $handle, $pageSize);
$teachersIds = $this->grouping($rs["rs"], "teacher_id");
$teachersAccounts = $this->getTeachersAccounts($teachersIds);
$teachers = array();
if($teachersAccounts)
{
foreach($teachersAccounts as $v)
{
$teachers[$v['teacher_id']] = $v;
}
}
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["businessphone"] = null;
$rs["rs"][$key]["class_name"] = null;
if(isset($teachers[$val["teacher_id"]]) && !empty($teachers[$val["teacher_id"]])){
$rs["rs"][$key]["businessphone"] = $teachers[$val["teacher_id"]]["phone_number"];
}
$classes = $this->getNowClassesByTeacherId($val["teacher_id"],$class_id);
if(!$classes&&$class_id){
unset($rs["rs"][$key]);
continue;
}
$classes = $this->grouping($classes, "class_name");
$classes = implode(",", $classes);
$rs["rs"][$key]["class_name"] = $classes;
}
return $rs;
}
public function getClasses($grade = "ALL", $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
$classes = array();
$condition = array();
if(in_array($grade, array("1", "2", "3")))
$condition = array("grade = '{$grade}'");
else if($grade !== "ALL")
return $classes;
$condition = Arr::merge($condition, array("semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$limit = $this->limit($offset, $limit);
$classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
return $classes;
}
public function getClassesWithoutTheClass($classId, $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
$classes = array();
if($classId){
$condition = array("semester_id = '{$this->semester["id"]}'", "class_id != '{$classId}'");
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$limit = $this->limit($offset, $limit);
$classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
$classes = Arr::toObj($classes);
}
return $classes;
}
public function getClassesList($condition = array(), $pageSize = 9){
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select c.*
from class as c
{$condition}
order by c.class_id desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getMyClassesList($condition = array(), $pageSize = 9){
$condition = Arr::merge(array("ccr.coach_id = '{$this->coachId}'"), $condition);
return $this->getClassesList($condition, $pageSize);
}
public function getClassesDetailListre($condition = array(), $pageSize = 9){
$condition = $this->condition($condition);
/*$handle = $this->sConn->createCommand("
select c.*, seme.semester_name as name, seme.school_year
from class as c
join semester as seme on seme.semester_id = c.semester_id
JOIN teacher_class_relation as tc on c.class_id = tc.class_id and seme.semester_id = tc.semester_id
JOIN teacher as t on tc.teacher_id = t.teacher_id
{$condition}
order by c.class_id desc
")->query();*/
$handle = $this->sConn->createCommand("
select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
from class as c
join semester as seme on seme.semester_id = c.semester_id
{$condition}
order by c.sort!=0 desc,c.sort,c.class_id desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs["rs"]){
$coachesIds = $this->grouping($rs["rs"], "coach_id");
$coachesIds = array_unique($coachesIds);
$coaches = $this->getCoachesByIds($coachesIds);
$classesIds = $this->grouping($rs["rs"], "class_id");
$classesIds = array_unique($classesIds);
$teachers = $this->getTeachersByClassesIds($classesIds);
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["coach_name"] = "";
foreach($coaches as $coach){
if($val["coach_id"] == $coach["coach_id"]){
$rs["rs"][$key]["coach_name"] = $coach["coach_name"];
}
}
}
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["teachers"] = "";
$rs["rs"][$key]["teachers_count"]=0;
$rs["rs"][$key]["teachers_bzr"]='';
foreach($teachers as $teacher){
if(strcmp($val["class_id"],$teacher["class_id"])==0){
$rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
$rs["rs"][$key]["teachers_count"] ++;
}
}
//读取班主任
if($val['teacher_id']){
$rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
}
}
}
return $rs;
}
public function getClassesDetailList($condition = array(), $pageSize = 9,$teacher_name=''){
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
from class as c
join semester as seme on seme.semester_id = c.semester_id
{$condition}
order by c.sort!=0 desc,c.sort,c.class_id desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs["rs"]){
$coachesIds = $this->grouping($rs["rs"], "coach_id");
$coachesIds = array_unique($coachesIds);
$coaches = $this->getCoachesByIds($coachesIds);
$classesIds = $this->grouping($rs["rs"], "class_id");
$classesIds = array_unique($classesIds);
if($teacher_name){
$teachers = $this->getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name);
}else{
$teachers = $this->getTeachersByClassesIds($classesIds);
}
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["coach_name"] = "";
foreach($coaches as $coach){
if($val["coach_id"] == $coach["coach_id"]){
$rs["rs"][$key]["coach_name"] = $coach["coach_name"];
}
}
$rs["rs"][$key]["teachers"] = "";
foreach($teachers as $teacher){
if($val["class_id"] == $teacher["class_id"]){
$rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
}
}
//读取班主任
if($val['teacher_id']){
$rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
}
}
}
return $rs;
}
public function getMyclassesDetailList($condition = array(), $pageSize = 9){
$condition = Arr::merge(array("c.coach_id = '{$this->coachId}'"), $condition);
return $this->getClassesDetailList($condition, $pageSize);
}
public function getCoachesByIds($coachesIds){
$coaches = array();
if($coachesIds && is_array($coachesIds)){
$coachesIds = implode("','", $coachesIds);
$coachesIds = "'{$coachesIds}'";
$coaches = $this->conn->createCommand("select * from coach where coach_id in($coachesIds)")->queryAll();
}
return $coaches;
}
public function changeClassTeachersRelation($classId, $teachersIds,$semesterId=0){
if($classId && $teachersIds){
if(!is_array($teachersIds))
$teachersIds = array($teachersIds);
$values = "";
foreach($teachersIds as $key => $teacherId){
if(trim((string)$teacherId) == null){
unset($teachersIds[$key]);
continue;
}
$values .= ",('{$classId}', '{$teacherId}', '{$semesterId}')";
}
if($values){
$values = "values".substr($values, 1);
try{
$trans = $this->sConn->beginTransaction();
$this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
return $rs;
}
}
return false;
}
public function _changeClassTeachersRelation($classId, $teachersIds,$class_data = array()){
if($classId && $teachersIds){
if(!is_array($teachersIds))
$teachersIds = array($teachersIds);
$values = "";
foreach($teachersIds as $key => $teacherId){
if(trim((string)$teacherId) == null){
unset($teachersIds[$key]);
continue;
}
$values .= ",('{$classId}', '{$teacherId}', '{$class_data['semester_id']}')";
}
if(!isset($class_data['class_type'])){
$class_data['class_type']=1;
}
if($values){
$values = "values".substr($values, 1);
try{
$trans = $this->sConn->beginTransaction();
if(isset($class_data['teacher_id'])){
$this->sConn->createCommand("insert into class(`class_id`,`class_name`, `coach_id`, `semester_id`,`period`,`grade`,`level`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`add_time`,`class_type`,`teacher_id`) VALUES (".$classId.",'".$class_data['class_name']."',".$class_data['coach_id'].",".$class_data['semester_id'].",".$class_data['period'].",".$class_data['grade'].",".$class_data['level'].",".$class_data['wrong_book_type'].",".$class_data['improve_book_type'].",".$class_data['wb_isp_version'].",".$class_data['add_time'].",".$class_data['class_type'].",".$class_data['teacher_id'].")")->execute();
}else{
$this->sConn->createCommand("insert into class(`class_id`,`class_name`, `coach_id`, `semester_id`,`period`,`grade`,`level`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`add_time`,`class_type`) VALUES (".$classId.",'".$class_data['class_name']."',".$class_data['coach_id'].",".$class_data['semester_id'].",".$class_data['period'].",".$class_data['grade'].",".$class_data['level'].",".$class_data['wrong_book_type'].",".$class_data['improve_book_type'].",".$class_data['wb_isp_version'].",".$class_data['add_time'].",".$class_data['class_type'].")")->execute();
}
$this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
return $rs;
}
}
return false;
}
/**
* @param $semesterId
*
* @return bool
* 刘红伟
* 开发时间 2016-09-29
*
*/
public function insertStudentInfoAndStudentClass($userNames,$studnetIds,$realname_array,$userno,$_IDX_array,$sex_array,$school_id,$class_id,$is_insert = 1)
{
$trans = $this->sConn->beginTransaction();
$student_id_array = array();
$sql1 = '';
try {
if($is_insert)
{
$sql1='';
$sql='INSERT INTO `student_info`
(`student_id`,`realname`,`sex`,`school_id`,`class_id`,`add_time`)VALUES';
foreach($userNames as $username)
{
if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
{
$student_id_array[] = $studnetIds[$username];
$sql1.='('.$studnetIds[$username].',"'.(isset($realname_array[$username]) && !empty($realname_array[$username])?$sex_array[$username]:'').'",'.(isset($sex_array[$username]) && !empty($sex_array[$username])?$sex_array[$username]:0).','.$school_id.','.$class_id.','.time().'),';
}
}
$sql .= substr($sql1,0,-1).';';
$this->sConn->createCommand($sql)->execute();
}else
{
foreach($userNames as $username)
{
if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
{ $student_id_array[] = $studnetIds[$username];
$sql = 'update `student_info` set realname="'.$realname_array[$username].'",sex='.$sex_array[$username].',class_id='.$class_id.',update_time='.time().' where student_id='.$studnetIds[$username].';';
$this->sConn->createCommand($sql)->execute();
}
}
}
$sql1 = '';
$sql = '';
$this->sConn->createCommand("delete from student_class_relation where class_id =".$class_id." and student_id in (".implode(',',$student_id_array).")")->execute();
$sql = 'INSERT INTO `student_class_relation`
(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`)VALUES';
foreach($userNames as $username)
{
if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
{
$sql1 .= '(' . $class_id . ',' . $studnetIds[$username] . ',0,' . $_IDX_array[$username] . ',"' . $userno[$username] . '",' . time() . '),';
}
}
$sql .= substr($sql1,0,-1).';';
$this->sConn->createCommand($sql)->execute();
$trans->commit();
} catch (Exception $e) {
$trans->rollBack();
return false;
}
return true;
}
public function getClassByClassIds($classIds)
{
if(!$classIds)
{
return false;
}
$rs = $this->sConn->createCommand("
select *
from class
where class_id in(".implode(',',$classIds).") ")->queryAll();
if($rs)
{
return $rs;
}
return false;
}
public function updateStudentClassByClassIdAndStudentID($class_id,$student_ids)
{
$trans = $this->sConn->beginTransaction();
try {
$sql='update `student_class_relation` set status = 1 where class_id= '.$class_id;
$this->sConn->createCommand($sql)->execute();
$sql='update `student_info` set class_id = 0 where class_id= '.$class_id;
$this->sConn->createCommand($sql)->execute();
$sql='update `student_class_relation` set status = 1 where student_id in ('.implode(',',$student_ids).')';
$this->sConn->createCommand($sql)->execute();
$trans->commit();
} catch (Exception $e) {
$trans->rollBack();
return false;
}
return true;
}
public function getStudentByStudentIds($studentIds){
if($studentIds && is_array($studentIds))
{
$rs = $this->sConn->createCommand("select * from student_info where student_id in(".implode(',',$studentIds).")")->queryAll();
if($rs)
{
return $rs;
}
}
return false;
}
/**
* @param $studentsIds
* @param $paper_id
* @param $exam_id
*
*/
public function getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id)
{
$data = array();
$criteria = new CDbCriteria();
$criteria->addCondition('paper_id=:paper_id');
$criteria->addCondition('exam_id=:exam_id');
$criteria->addInCondition('student_id',$studentsIds);
$criteria->addCondition('is_feedback=:is_feedback');
$criteria->addCondition('is_del=:is_del');
$criteria->params[':paper_id'] = $paper_id;
$criteria->params[':exam_id'] = $exam_id;
$criteria->params[':is_feedback'] = 1;
$criteria->params[':is_del'] = 0;
$rs = SStudentPaperRelation::model()->findAll($criteria);
if($rs){
foreach($rs as $v)
{
$data[] = $v->attributes;
}
return $rs;
}
return false;
}
public function delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id)
{
$rs=false;
$trans = $this->sConn->beginTransaction();
try {
$this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."' ")->execute();
$this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."'")->execute();
// $this->sConn->createCommand("DELETE FROM student_paper_relation_property where student_id in(".implode(',',$studentsIds).") and paper_id=".$paper_id." ")->execute();
$trans->commit();
return true;
} catch (Exception $e) {
$trans->rollBack();
return false;
}
return false;
}
/**
* 获取班级学生
* @param $class_id
*
* @return array|bool|\CDbDataReader
*/
public function getClassStudentByClassId($class_id)
{
$rs = $this->sConn->createCommand("select * from student_class_relation where class_id=".$class_id." and status=0")->queryAll();
if($rs){
return $rs;
}
return false;
}
public function getClassPaperByClassAndPaper($class_id,$paper_id,$status=0)
{
$rs = $this->sConn->createCommand("select student_id,paper_id,class_id,exam_id from student_paper_relation where class_id=".$class_id." and paper_id=".$paper_id." and is_del=".$status)->queryAll();
if($rs){
return $rs;
}
return false;
}
public function getClassStudentInfoByClassId($class_id){
$sql="select scr.student_id,realname,scr.class_id from student_class_relation scr join student_info si on si.student_id=scr.student_id where scr.class_id='".$class_id."' and scr.status=0";
//$rs = $this->sConn->createCommand("select student_id,realname,class_id from student_info where class_id=".$class_id)->queryAll();
$rs = $this->sConn->createCommand($sql)->queryAll();
if($rs){
return $rs;
}
return false;
}
public function getStudentByStudentIdsAndParperId($studentsIds,$paper_id,$is_del=0)
{
$rs = $this->sConn->createCommand("select student_id from student_paper_relation where student_id in(".$studentsIds.") and paper_id=".$paper_id." and is_del=".$is_del)->queryAll();
if($rs){
return $rs;
}
return false;
}
public function getStudentsByStudentIdsAndExam_ids($exam_ids,$studentsIds)
{
if($exam_ids && $studentsIds)
{
$rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in ( ".$exam_ids." ) and student_id in(".$studentsIds.") and is_del=0")->queryAll();
if($rs){
return $rs;
}
}
return false;
}
public function addAndUpdateStudentPaper($class_id,$add_student,$exam_id,$semester_id,$paper_id,$student_cards=array(),$school_student_cards=array(),$exam_ids=array(),$grade=array() )
{
$trans = $this->sConn->beginTransaction();
$sql = 'insert into `student_paper_relation` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`student_card`,`school_student_card`,`studytrend_exam_name`)VALUES';
$sql1 = '';
$sqlProperty = 'insert into `student_paper_relation_property` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`create_time`) VALUES';
$sqlPV = '';
try {
if($add_student)
{
$criteria = new CDbCriteria();
$criteria->addCondition('exam_id=:exam_id');
$criteria->addCondition('paper_id = :paper_id');
$criteria->addInCondition('student_id',$add_student);
$criteria->params[':exam_id'] = $exam_id;
$criteria->params[':paper_id'] = $paper_id;
SStudentPaperRelation::model()->deleteAll($criteria);
SStudentPaperRelationProperty::model()->deleteAll($criteria);
foreach($add_student as $student_id)
{
$school_student_card = 0;
$student_card = 0;
if(isset($school_student_cards[$student_id]) && !empty($school_student_cards[$student_id]))
{
$school_student_card = $school_student_cards[$student_id];
}
if(isset($student_cards[$student_id]) && !empty($student_cards[$student_id]))
{
$student_card = $student_cards[$student_id];
$sql1 .= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.$student_card.',"'.$school_student_card.'",""),';
$sqlPV.= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.time().'),';
}
}
$sql .= substr($sql1,0,-1).';';
$sqlProperty .= substr($sqlPV,0,-1).';';
$this->sConn->createCommand($sql)->execute();
$this->sConn->createCommand($sqlProperty)->execute();
}
$trans->commit();
} catch (Exception $e) {
$trans->rollBack();
return false;
}
return true;
}
/**
* 刘红伟 end
*/
public function semesterAllowToChange($semesterId){
if($semester = $this->getSemester($semesterId)){
if(is_numeric($semester["start_time"]) && ($semester["start_time"] - time()) <= $this->semesterAllowToChangeTime)
return true;
}
return false;
}
public function semesterExists($semesterId){
if(!$semesterId)
return false;
$rs = $this->sConn->createCommand("select exists(select * from semester where semester_id = '{$semesterId}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function changeSemester($semesterId){
$code = 1001;
if($semesterId){
$code = array();
if($this->role !== ROLE_SU){
if($this->isPreviousSemester($semesterId))
$code[] = 2001;
if(!$this->semesterAllowToChange($semesterId)){
$code[] = 2002;
}
}
if($code)
return $this->rs($code, __FUNCTION__);
try{
if($this->semesterExists($semesterId)){
$trans = $this->sConn->beginTransaction();
$this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
$this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
$trans->commit();
$rs = true;
}
else
$rs = false;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
if($rs){
if($this->isFutureSemester($semesterId))
$this->activateSemesterClassesStudentsRelations($semesterId);
}
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function getClassesTeachers($classesIds){
$teachers = array();
if($classesIds){
$classesIds = implode(",", $classesIds);
$rs = $this->sConn->createCommand("
select t.teacher_name , tcr.class_id, c.level,t.subjects
from teacher_class_relation as tcr
join teacher as t on t.teacher_id = tcr.teacher_id
join class as c on c.class_id = tcr.class_id
where tcr.class_id in({$classesIds})
")->queryAll();
if($rs)
foreach ($rs as $val){
if(isset(Yii::app()->params['subjectId'][$val['subjects']])){
$teachers[(string)$val['class_id']][]=$val['teacher_name'].'('.Yii::app()->params['subjectId'][$val['subjects']].')';
}else{
$teachers[(string)$val['class_id']][]=$val['teacher_name'];
}
}
}
return $teachers;
}
public function getTeachersByclassIdsAndteacherName($classesIds,$teacher_name){
$teachers = array();
if($classesIds){
$classesIds = implode(",", $classesIds);
$rs = $this->sConn->createCommand("
select group_concat(t.teacher_name) as teachers_names, tcr.class_id, c.level
from teacher_class_relation as tcr
join teacher as t on t.teacher_id = tcr.teacher_id
join class as c on c.class_id = tcr.class_id
where tcr.class_id in({$classesIds}) AND t.teacher_name LIKE '%{$teacher_name}%'
group by tcr.class_id
")->queryAll();
if($rs)
$teachers = $rs;
}
return $teachers;
}
public function getClassPreviousStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
$rs = $this->buildEmptyPagingStruct();
if($classId){
$condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
group by student_id
order by scr.serial_number ASC ,stu.student_id desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getClassPreviousStudentsListre($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
$rs = $this->buildEmptyPagingStruct();
if($classId){
$condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id and scr.status = 0
join class as c on c.class_id = scr.class_id
{$condition}
group by student_id
order by scr.serial_number ASC ,stu.student_id desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getClassPreviousStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9){
$rs = $this->getClassPreviousStudentsList($classId, $condition, $pageSize, "ARR");
if($rs["rs"]){
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["username"] = "";
$rs["rs"][$key]["status"] = null;
}
$studentsIds = $this->grouping($rs["rs"], "student_id");
$studentsIds = implode("','", $studentsIds);
$studentsIds = "'{$studentsIds}'";
$accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
if($accounts){
foreach($accounts as $account){
foreach($rs["rs"] as $key => $val){
if($val["student_id"] && $val["student_id"] == $account["student_id"]){
$rs["rs"][$key]["username"] = $account["username"];
$rs["rs"][$key]["status"] = $account["status"];
}
}
}
}
}
return $rs;
}
public function getClass($classId){
$class = array();
if($classId){
$class = $this->sConn->createCommand("select * from class where class_id = '{$classId}'")->queryRow();
}
return $class;
}
public function getClassInfo($classId, $type = "ARR"){
$classInfo = null;
if($classId){
$classInfo = $this->sConn->createCommand("
select c.*, csr.subject_id, csr.material_id, csr.module_ids as modules_ids
from class as c
left join class_subject_relation as csr on csr.class_id = c.class_id
where c.class_id = '{$classId}'
")->queryRow();
if($type == "OBJ"){
$classInfo = Arr::toObj($classInfo);
}
}
return $classInfo;
}
public function getClassTeachersIds($classId){
$teachersIds = array();
if($classId){
$rs = $this->sConn->createCommand("
select * from teacher_class_relation where class_id = '{$classId}' group by teacher_id
")->queryAll();
if($rs)
$teachersIds = $this->grouping($rs, "teacher_id");
}
return $teachersIds;
}
public function semesterHasClass($semesterId){
if($semesterId){
$rs = $this->sConn->createCommand("select exists(select * from class where semester_id = '{$semesterId}')")->queryRow();
return current($rs) ? true : false;
}
return false;
}
public function classHasStudent($classId){
if(!($class = $this->getClass($classId)))
return false;
$condition = array("class_id = '{$classId}'");
if($this->isCurrentSemester($class["semester_id"]))
$condition = Arr::merge($condition, array("status = 0"));
$condition = $this->condition($condition);
$rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function classHasExam($classId){
if($classId){
$rs = $this->sConn->createCommand("select exam_id,exam_group_id from exam where class_id = '{$classId}'")->queryAll();
if($rs){
return $rs;
}
}
return false;
}
public function studentHasPaper($studentId){
if($studentId){
$rs = $this->sConn->createCommand("
select exists(select * from student_paper_relation where semester_id = '{$this->semester["id"]}' and student_id = '{$studentId}' and is_del=0)
")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
return false;
}
public function studentHasPaperInOtherSemesters($studentId){
if(!$studentId)
return false;
$rs = $this->sConn->createCommand("
select exists(select * from student_paper_relation where semester_id != '{$this->semester["id"]}' and student_id = '{$studentId}') and is_del=0
")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function teacherHasBindedClass($teacherId){
if($teacherId){
$rs = $this->sConn->createCommand("select count(*) from teacher_class_relation where teacher_id = '{$teacherId}'")->queryAll();
return current(current($rs)) > 0 ? true : false;
}
return false;
}
public function teacherHasCreatedExam($teacherId){
if($teacherId){
$rs = $this->sConn->createCommand("select count(*) from exam where teacher_id = '{$teacherId}'")->queryAll();
return current(current($rs)) > 0 ? true : false;
}
return false;
}
public function teacherHasMarkingTask($teacherId){
if($teacherId){
$rs = $this->sConn->createCommand("select count(*) from marking_task where teacher_id = '{$teacherId}' AND status=0" )->queryAll();
return current(current($rs)) > 0 ? true : false;
}
return false;
}
public function teacherHasProblemMark($teacherId){
if($teacherId){
$rs = $this->sConn->createCommand("select count(*) from marking_task where teacher_id = '{$teacherId}' AND status=1 AND is_problem=1 AND problem_status=0" )->queryAll();
return current(current($rs)) > 0 ? true : false;
}
return false;
}
public function delSemester($semesterId){
$code = 1001;
if($semesterId){
$code = array();
if($this->role !== ROLE_SU){
if($this->isCurrentSemester($semesterId))
$code[] = 2001;
if($this->semesterHasClass($semesterId))
$code[] = 2002;
}
if($code)
return $this->rs($code, __FUNCTION__);
$rs = $this->sConn->createCommand("delete from semester where semester_id = '{$semesterId}'")->execute();
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function CoachdelClass($classId){
$code = 1001;
$hasStudent=false;
$hasExam=false;
if($classId){
$code = array();
if($this->role !== ROLE_SU){
if($this->classHasStudent($classId)){
$hasStudent=true;
$code[] = 2001;
}
if($this->classHasExam($classId)){
$code[] = 2002;
$hasExam=true;
}
}
if($hasStudent){
return $this->rs($code, 'delClass');
}else{
try{
$trans = $this->sConn->beginTransaction();
//查询班级属性
$classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
if($hasExam){
//隐藏班级
$this->sConn->createCommand("UPDATE class SET is_hide = 1 WHERE class_id = '{$classId}'")->execute();
}else{
$this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
if($classInfo['class_type']==1){
//查询行政班学生
$classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
if($classStudent){
$studentIds=array();
foreach ($classStudent as $item){
$studentIds[]=$item['student_id'];
}
$this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
}
}else{
$this->sConn->createCommand("UPDATE student_class_relation SET status = 1 WHERE class_id = '{$classId}'")->execute();
}
$this->sConn->createCommand("delete from product_class_relation where class_id = '{$classId}'")->execute();
}
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
$code = $rs ? 0 : 1002;
}
}
return $this->rs($code, "global");
}
public function delClass($classId){
$code = 1001;
if($classId){
$code = array();
$exam_ids = array();
$exam_group_ids = array();
$paper_ids = array();
$_exam_group_ids = array();
$exam_group = array();
//查询班级属性
$classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
if($this->role !== ROLE_SU){
$class_exam = $this->classHasExam($classId);
if($class_exam)
{
if(count($class_exam)>2){
$code[] = 2002;
}else
{
foreach($class_exam as $v)
{
$exam_ids[$v['exam_id']] = $v['exam_id'];
$exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
}
$papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
if($papers)
{
foreach($papers as $v)
{
$paper_ids[$v['paper_id']] = $v['paper_id'];
}
}
$exams = $this->sConn->createCommand("select exam_id,exam_group_id from exam where exam_group_id IN (".implode(',',$exam_group_ids).")")->queryAll();
if($exams)
{
foreach ($exams as $v)
{
$exam_group[$v['exam_group_id']][] = $v;
}
foreach($exam_group_ids as $v)
{
if(isset($exam_group[$v]) && !empty($exam_group[$v]) && count($exam_group[$v])==1){
$_exam_group_ids[] = $v['exam_group_id'];
}
}
}
}
}
}
if($code)
return $this->rs($code, __FUNCTION__);
try{
$trans = $this->sConn->beginTransaction();
$this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
//$this->sConn->createCommand("UPDATE student_info SET class_id = 0 WHERE class_id = '{$classId}'")->execute();
if($classInfo['class_type']==1){
//查询行政班学生
$classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
if($classStudent){
$studentIds=array();
foreach ($classStudent as $item){
$studentIds[]=$item['student_id'];
}
$this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
}
}else{
$this->sConn->createCommand("UPDATE student_class_relation SET status = 1,operation=1 WHERE class_id = '{$classId}'")->execute();
}
$this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("delete from exam where class_id = '{$classId}'")->execute();
$this->sConn->createCommand("delete from student_paper_relation where class_id = '{$classId}'")->execute();
if($paper_ids)
{
$this->sConn->createCommand("delete from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).")")->execute();
}
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function delExam($examId, $type){
if($examId && $type){
return $this->sConn->createCommand("delete from exam where exam_id = '{$examId}' and type = '{$type}'")->execute();
}
return false;
}
public function studentHasBindedClass($studentId){
if(!$studentId)
return false;
$rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$studentId}' and status = 0)")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function studentAccountExists($studentId){
if(!$studentId)
return false;
$rs = $this->conn->createCommand("select exists(select * from student where student_id = '{$studentId}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function purgeStudent($studentId,$auth=0,$classId=0){
$code = 1001;
$msg = '删除成功';
if($auth==0)
{
$rs = true;
$authUsername = Yii::app()->session['coachInfo']["school_id"] . '_' . Yii::app()->session['coachInfo']["coach_name"];
$http = http('service/student-delete-perm','post', $authUsername, array($studentId));
$response = formatResponse($http);
if(isset($response['data']) && $response['data']){
if($response['data'][0]['hasOrder']==1){
$rs=false;
$code = 2001;
$msg = '无法操作,该学生已存在订单数据';
}
}
if($studentId && $rs){
if($classId){
$student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId." and class_id='".$classId."'")->queryRow();
}else{
$student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId)->queryRow();
}
if(!$student_paper_relation)
{
$trans1 = $this->sConn->beginTransaction();
try{
if($classId){
$this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
}else{
$this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
}
$trans1->commit();
}
catch(Exception $e){
$trans1->rollBack();
$rs = false;
$msg = '删除失败';
}
$code = $rs ? 0 : 1002;
}else
{
$code = 2001;
$msg = '无法操作,该学生已存在考试数据';
}
}else
{
$rs = false;
if(!$msg){
$msg = '删除失败';
}
$code = $rs ? 0 : 1002;
}
}else
{
$rs = true;
if($studentId){
$trans1 = $this->sConn->beginTransaction();
try{
if($classId){
$this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
}else{
$this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
}
$trans1->commit();
}
catch(Exception $e){
$trans1->rollBack();
$rs = false;
$msg = '删除失败';
}
}else
{
$rs = false;
$msg = '删除失败';
}
$code = $rs ? 0 : 1002;
}
return array('code'=>$code,'msg'=>$msg);
}
public function removeStudentClassRelation($studentId, $classId){
$code = 1001;
if($studentId && $classId){
if($this->role !== ROLE_SU){
if($this->studentHasPaper($studentId))
return $this->rs(2001, __FUNCTION__);
}
$rs = $this->sConn->createCommand("delete from student_class_relation where student_id = '{$studentId}' and class_id = '{$classId}'")->execute();
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function teacherAccountExists($teacherId){
if(!$teacherId)
return false;
$rs = $this->conn->createCommand("select exists(select * from xb_teacher where teacher_id = '{$teacherId}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function delTeacher($teacherId){
$code = 1001;
if($teacherId){
$code = array();
if($this->role !== ROLE_SU){
if($this->teacherHasBindedClass($teacherId))
$code[] = 2001;
if($this->teacherHasCreatedExam($teacherId))
$code[] = 2002;
}
if($code)
return $this->rs($code, __FUNCTION__);
try{
$trans1 = $this->sConn->beginTransaction();
$trans2 = $this->conn->beginTransaction();
$this->conn->createCommand("update xb_teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
$this->sConn->createCommand("update teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
$this->kickTeacher($teacherId);
$trans1->commit();
$trans2->commit();
$rs = true;
}
catch(Exception $e){
$trans1->rollBack();
$trans2->rollBack();
$rs = false;
}
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function purgeTeacher($teacherId){
$code = 1001;
if($teacherId){
$code = array();
$teacherAccountExists = $this->teacherAccountExists($teacherId);
if($this->role !== ROLE_SU && $teacherAccountExists){
if($this->teacherHasBindedClass($teacherId))
$code[] = 2001;
if($this->teacherHasCreatedExam($teacherId))
$code[] = 2002;
if ($this->teacherHasMarkingTask($teacherId))
$code[] = 2003;
if ($this->teacherHasProblemMark($teacherId))
$code[] = 2004;
}
if($code)
return $this->rs($code, __FUNCTION__);
try{
$trans1 = $this->sConn->beginTransaction();
$trans2 = $this->conn->beginTransaction();
if($teacherAccountExists){
$this->conn->createCommand("delete from xb_teacher where teacher_id = '{$teacherId}'")->execute();
}
$this->sConn->createCommand("delete from teacher where teacher_id = '{$teacherId}'")->execute();
$this->sConn->createCommand("delete from teacher_class_relation where teacher_id = '{$teacherId}'")->execute();
$this->kickTeacher($teacherId);
$trans1->commit();
$trans2->commit();
$rs = true;
}
catch(Exception $e){
$trans1->rollBack();
$trans2->rollBack();
$rs = false;
}
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function getSemesters($condition = array(), $orderBy = array("start_time desc"), $offset = 0, $limit = -1){
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$limit = $this->limit($offset, $limit);
$rs = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}{$limit}")->queryAll();
return $rs;
}
public function getSemestersList($condition = array(), $orderBy = array(), $pageSize = 20){
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getSemesterIdByClassId($classId){
$semesterId = null;
$class = $this->getClass($classId);
if(!empty($class["semester_id"]))
$semesterId = $class["semester_id"];
return $semesterId;
}
public function getSemester($semesterId){
$semester = array();
if($semesterId){
$semester = $this->sConn->createCommand("select * from semester where semester_id = '{$semesterId}'")->queryRow();
}
return $semester;
}
public function getTheYearLastSemester($year){
if(!$year)
return array();
return $this->sConn->createCommand("select * from semester where school_year = '{$year}' order by start_time desc limit 1")->queryRow();
}
public function getCurrSemester(){
return $this->sConn->createCommand("select * from semester where status = '1'")->queryRow();
}
public function isCurrentSemester($semesterId){
$semester = $this->getCurrSemester();
if($semester && $semester['semester_id']==$semesterId){
return true;
}
return false;
}
public function getClassExamsList($classId, $orderBy = array("exam_id desc"), $pageSize = 9){
$rs = $this->buildEmptyPagingStruct();
if($classId){
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select e.* from exam as e where e.class_id = '{$classId}' and e.semester_id = '{$this->semester["id"]}' and e.type = 2{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getExamRecordsList($examId, $orderBy = array("record_id asc"), $pageSize = 9){
$rs = array();
if($examId){
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select er.*, stu.realname
from exam_record as er
join student_info as stu on stu.student_id = er.student_id
where er.exam_id = '{$examId}'
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getExam($examId, $type = "ARR"){
$exam = array();
if($examId){
$exam = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryRow();
if($type == "OBJ"){
$exam = Arr::toObj($exam);
}
}
return $exam;
}
public function getExamClassId($examId){
if($exam = $this->getExam($examId))
return $exam["class_id"];
return null;
}
public function isClassExam($classId, $examId){
$rs = false;
if($classId && $examId){
$rs = $this->sConn->createCommand("select exists(select * from exam where exam_id = '{$examId}' and class_id = '{$classId}')")->queryRow();
$rs = current($rs) ? true : false;
}
return $rs;
}
public function studentBelongsToClass($studentId, $classId){
if($studentId && $classId){
$rs = $this->sConn->createCommand("select exists(select * from student_info where student_id = '{$studentId}' and class_id = '{$classId}')")->queryRow();
$rs = current($rs);
if($rs) return true;
}
return false;
}
public function getMyClassesIds(){
$ids = array();
$rs = $this->sConn->createCommand("select * from class where coach_id = '{$this->coachId}'")->queryAll();
if($rs){
$ids = $this->grouping($rs, "class_id");
}
return $ids;
}
public function isMyClass($classId){
if($classId){
$myClassesIds = $this->getMyClassesIds();
if(in_array($classId, $myClassesIds))
return true;
}
return false;
}
public function getExamClassesIds($examId){
$ids = array();
if($examId){
$rs = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryAll();
$ids = $this->grouping($rs, "class_id");
}
return $ids;
}
public function getParentsList($orderBy = array(), $pageSize = 9){
$handle = $this->conn->createCommand("
select pa.*
from student as stu
join parent_student_relation as psr on psr.student_id = stu.student_id
join `parent` as pa on pa.parent_id = psr.parent_id and pa.status != 2
where stu.school_id = '{$this->schoolId}'
group by pa.parent_id
")->query();
$rs = $this->paging($this->conn, $handle, $pageSize);
return $rs;
}
public function delParentsStudentsRelations($parentsIds){
if($parentsIds){
if(!is_array($parentsIds)){
$parentsIds = array($parentsIds);
}
$ids = "";
foreach($parentsIds as $key => $val){
$ids .= ",'{$val}'";
}
$ids = substr($ids, 1);
try{
$trans = $this->sConn->beginTransaction();
$this->sConn->createCommand("delete from parent_student_relation where parent_id in({$ids})")->execute();
$trans->commit();
return true;
}
catch(Exception $e){
$trans->rollBack();
return false;
}
}
return false;
}
public function updateParent($parentId, $parentData){
$updateKeys = array("phone_number", "password", "realname", "sex", "age", "status", "last_login_time");
$insertKeys = array("phone_number");
foreach($parentData as $key => $val){
switch($key){
case "phone_number":
if(!Filter::testPhoneNumber($val))
return false;
break;
case "password":
if(strlen($val) > 18)
return false;
$parentData[$key] = md5(sha1($val));
break;
case "realname":
if(strlen($val) > 10)
return false;
break;
case "sex":
if(!in_array($val, array("0", "1", "2")))
return false;
break;
case "age":
if(!is_numeric($val) || $val < 1 || $val > 100)
return false;
break;
case "status":
if(!in_array($val, array("0", "1", "2")))
return false;
break;
case "last_login_time":
if(!is_numeric($val) || strlen($val) > 10)
return false;
break;
default:
break;
}
}
if($parentId){
$pattern = "";
foreach($parentData as $key => $val){
if(!in_array($key, $updateKeys))
continue;
$pattern .= ",`{$key}` = '{$val}'";
}
$pattern = substr($str, 1);
if($pattern)
return $this->conn->createCommand("update parent set {$pattern} where parent_id = '{$parentId}'")->execute();
}
else{
$fields = "";
$values = "";
$keys = array();
foreach($parentData as $key => $val){
if(!in_array($key, $allowKeys))
continue;
$keys[] = $key;
$fields .= ",`{$key}`";
$values .= ",'{$val}'";
}
if(array_diff($requiredKeys, $keys))
return false;
$fields .= ",`signup_time`";
$values .= ",'".time()."'";
$fields = substr($fields, 1);
$values = substr($values, 1);
return $this->conn->createCommand("insert into parent({$fields}) values({$values})")->execute();
}
return false;
}
public function addParent($parentData){
return $this->updateParent(null, $parentData);
}
public function getStudentInfo($studentId, $type = "ARRAY"){
$studentInfo = array();
if($studentId){
$studentInfo = $this->sConn->createCommand("
select stu.student_id, stu.realname, stu.sex, stu.family_tel, stu.telephone, stu.student_phone, stu.picture, stu.signature, stu.add_time,
stu.update_time,stu.is_outer, scr.userno, scr.serial_number, c.class_name, c.class_id,stu.id_number,stu.field_1,stu.field_2,stu.field_3,stu.field_4,stu.field_5
from student_info as stu
join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
join class as c on c.class_id = scr.class_id
where stu.student_id = '{$studentId}'
")->queryRow();
if($type == "OBJ")
$studentInfo = Arr::toObj($studentInfo);
}
return $studentInfo;
}
public function getStudentInfoByUsername($username){
$studentInfo = array();
if($username){
$rs = $this->conn->createCommand("select * from student where username = '{$username}'")->queryAll();
if($rs){
$rs = current($rs);
$studentInfo = $this->getStudentInfo($rs["student_id"]);
}
}
return $studentInfo;
}
public function getStudentParents($studentId){
$parents = array();
if($studentId){
$parents = $this->conn->createCommand("
select pa.*, pwor.openid
from parent_student_relation as psr
join parent as pa on pa.parent_id = psr.parent_id
join parent_wechat_openid_relation as pwor on pwor.parent_id = psr.parent_id
where psr.student_id = '{$studentId}'
group by pa.parent_id
limit 0, 10
")->queryAll();
}
return $parents;
}
public function insertExamRecord($recordData, $xls){
if((empty($recordData["exam_id"]) && !isset($_FILES)) || empty($recordData["name"]) || empty($recordData["class_id"]))
return false;
$time = time();
if(isset($xls["error"]) && $xls["error"] == 0){
$xls = $xls["file"];
$excel = new Excel();
$sheetData = $excel->read($xls);
$studentsCount = 0;
$students = array();
$studentsIds = array();
$notExistStudents = array();
$notExistStudentsCount = 0;
$incomplete = array();
$incompleteCount = 0;
$notBelongsToClass = array();
$notBelongsToClassCount = 0;
$studentsExist = array();
$studentsExistCount = 0;
foreach($sheetData as $key => $val){
$chinese = $val["B"];
$math = $val["C"];
$english = $val["D"];
$physics = $val["E"];
$chemistry = $val["F"];
$biology = $val["G"];
$politics = $val["H"];
$history = $val["I"];
$geography = $val["J"];
$classRank = $val["K"];
$gradeRank = $val["L"];
if(Str::isBlank($chinese) && Str::isBlank($math)&& Str::isBlank($english)&& Str::isBlank($physics)&& Str::isBlank($chemistry)&& Str::isBlank($biology)&& Str::isBlank($politics)&& Str::isBlank($history)&& Str::isBlank($geography)&& Str::isBlank($classRank)&& Str::isBlank($gradeRank)){
continue;
}
if(Str::isBlank($chinese) || Str::isBlank($math)|| Str::isBlank($english)|| Str::isBlank($physics)|| Str::isBlank($chemistry)|| Str::isBlank($biology)|| Str::isBlank($politics)|| Str::isBlank($history)|| Str::isBlank($geography)|| Str::isBlank($classRank)|| Str::isBlank($gradeRank)){
$studentsCount++;
$incompleteCount++;
continue;
}
$studentsCount++;
$username = (string)$val["A"];
$studentInfo = $this->getStudentInfoByUsername($username);
$studentId = $studentInfo ? $studentInfo["student_id"] : null;
if(!$studentId){
$notExistStudents[] = $username;
$notExistStudentsCount++;
continue;
}
if(!$this->studentBelongsToClass($studentId, $recordData["class_id"])){
$notBelongsToClass[] = $username;
$notBelongsToClassCount++;
continue;
}
if(in_array($studentId, $studentsIds)){
$studentsExist[] = $username;
$studentsExistCount++;
continue;
}
$studentsIds[] = $studentId;
$chinese = is_numeric($val["B"]) && $val["B"] ? $val["B"] : 0;
$math = is_numeric($val["C"]) && $val["C"] ? $val["C"] : 0;
$english = is_numeric($val["D"]) && $val["D"] ? $val["D"] : 0;
$physics = is_numeric($val["E"]) && $val["E"] ? $val["E"] : 0;
$chemistry = is_numeric($val["F"]) && $val["F"] ? $val["F"] : 0;
$biology = is_numeric($val["G"]) && $val["G"] ? $val["G"] : 0;
$politics = is_numeric($val["H"]) && $val["H"] ? $val["H"] : 0;
$history = is_numeric($val["I"]) && $val["I"] ? $val["I"] : 0;
$geography = is_numeric($val["J"]) && $val["J"] ? $val["J"] : 0;
$classRank = is_numeric($val["K"]) && $val["K"] ? $val["K"] : 0;
$gradeRank = is_numeric($val["L"]) && $val["L"] ? $val["L"] : 0;
$totalScore = $chinese + $math + $english + $physics + $chemistry + $biology + $politics + $history + $geography;
$students[$studentId]["student_id"] = $studentId;
$students[$studentId]["subject_chinese"] = $chinese;
$students[$studentId]["subject_math"] = $math;
$students[$studentId]["subject_english"] = $english;
$students[$studentId]["subject_physics"] = $physics;
$students[$studentId]["subject_chemistry"] = $chemistry;
$students[$studentId]["subject_biology"] = $biology;
$students[$studentId]["subject_history"] = $history;
$students[$studentId]["subject_politics"] = $politics;
$students[$studentId]["subject_geography"] = $geography;
$students[$studentId]["total_score"] = $totalScore;
$students[$studentId]["class_rank"] = $classRank;
$students[$studentId]["grade_rank"] = $gradeRank;
}
$failedCount = $notExistStudentsCount + $incompleteCount + $notBelongsToClassCount + $studentsExistCount;
$successCount = $studentsCount - $failedCount;
$result["global"]["msg"] = "从Excel读取了{$studentsCount}条记录,其中{$successCount}导入成功,{$failedCount}条导入失败";
$result["errors"][0]["type"] = "数据信息不完整";
$result["errors"][0]["count"] = $incompleteCount;
$result["errors"][0]["msg"] = "共有{$incompleteCount}行数据不完整,请检查";
$result["errors"][1]["type"] = "不存在该用户名的学生";
$result["errors"][1]["count"] = $notExistStudentsCount;
$notExistStudents = implode(",", $notExistStudents);
$result["errors"][1]["msg"] = "用户名为{$notExistStudents}的学生无法导入";
$result["errors"][2]["type"] = "该学生不属于本班级";
$result["errors"][2]["count"] = $notBelongsToClassCount;
$notBelongsToClass = implode(",", $notBelongsToClass);
$result["errors"][2]["msg"] = "用户名为{$notBelongsToClass}的学生无法导入";
$result["errors"][3]["type"] = "表格中有重复的学生";
$result["errors"][3]["count"] = $studentsExistCount;
$studentsExist = implode(",", $studentsExist);
$result["errors"][3]["msg"] = "用户名为{$studentsExist}的学生无法导入";
if($failedCount == $studentsCount){
$result["global"]["result"] = "失败";
return $result;
}
else if($successCount == $studentsCount){
$result["global"]["result"] = "全部成功";
unset($result["errors"][0]);
}
else{
$result["global"]["result"] = "部分成功";
}
$fields = "";
$values = array();
if($students){
if(!empty($recordData["exam_id"]))
$examId = $recordData["exam_id"];
else{
// $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
// $examId = current(current($uuid));
$examId=getUniqueId($this->schoolId);
}
$student = current($students);
foreach($student as $key => $val){
$fields .= ",`{$key}`";
}
$fields .= ",`record_id`";
$fields .= ",`exam_id`";
$fields .= ",`coach_id`";
$fields .= ",`add_time`";
$fields = "(".substr($fields, 1).")";
foreach($students as $studentId => $student){
$values[$studentId] = "";
foreach($student as $key => $val){
$values[$studentId] .= ",'{$val}'";
}
$uuid=getUniqueId($this->schoolId);
$values[$studentId] .= ",'{$uuid}'";
$values[$studentId] .= ",'{$examId}'";
$values[$studentId] .= ",'{$this->coachId}'";
$values[$studentId] .= ",'{$time}'";
$values[$studentId] = "(".substr($values[$studentId], 1).")";
}
if($values){
$values = implode(",", $values);
$sql = "insert into exam_record{$fields} values{$values}";
}
else{
$sql = "";
}
try{
$trans = $this->sConn->beginTransaction();
if(isset($recordData["exam_id"]) && $recordData["exam_id"]){
if(isset($recordData["name"]) && $recordData["name"])
$this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
if($sql){
$this->sConn->createCommand("delete from exam_record where exam_id = '{$examId}'")->execute();
$this->sConn->createCommand($sql)->execute();
}
}
else if($sql){
$this->sConn->createCommand("
insert into exam(`exam_id`, `class_id`, `name`, semester_id, `type`, `status`, `create_time`)
values('{$examId}', '{$recordData["class_id"]}', '{$recordData["name"]}', '{$this->semester["id"]}', 2, 2, '{$time}')
")->execute();
$this->sConn->createCommand($sql)->execute();
}
$trans->commit();
if($students){
foreach($students as $student){
if($parents = $this->getStudentParents($student["student_id"])){
$student = $this->getStudentInfo($student["student_id"]);
$studentName = $student ? $student["realname"] : "";
$msg = "您的孩子{$studentName}综合排名有了新的数据, 点击查看";
$redirectionPath = "home/examrecord?studentId={$student["student_id"]}";
foreach($parents as $parent){
$this->writeParentNotification($parent["parent_id"], $msg, 1, $redirectionPath);
if($parent["openid"])
send_weixin($parent["openid"], $msg, $this->parentNotificationHost."/home/examrecord?studentId={$student["student_id"]}");
}
}
}
}
return $result;
}
catch(Exception $e){
$trans->rollBack();
return false;
}
}
else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"])
return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
return false;
}
else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"]){
return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
}
return false;
}
public function getOrdersList($orderBy = array(), $pageSize = 9){
$orderBy = $this->orderBy($orderBy);
$handle = $this->conn->createCommand("
select ord.*
from order_school_relation as osr
join `order` as ord on ord.order_id = osr.order_id
where osr.school_id = '{$this->schoolId}'
{$orderBy}
")->query();
$rs = $this->paging($this->conn, $handle, $pageSize);
return $rs;
}
public function writeParentNotification($parentId, $content, $type = null, $redirectionPath = ""){
if($parentId && $content){
$time = time();
$fields = "`parent_id`, `content`, `time`";
$values = "'{$parentId}', '{$content}', '{$time}'";
if($type){
$fields .= ", `type`";
$values .= ", '{$type}'";
if($type == 1 && $redirectionPath){
$fields .= ",`redirection_path`";
$values .= ",'{$redirectionPath}'";
}
}
$sql = "insert into parent_notification({$fields}) values({$values})";
return $this->conn->createCommand($sql)->execute();
}
return false;
}
public function getClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
$rs = $this->buildEmptyPagingStruct();
if($classId){
$condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
order by serial_number asc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getInClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
$rs = $this->buildEmptyPagingStruct();
if($classId){
$condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 0"), $condition);
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
order by serial_number asc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
public function getStudents($studentsIds = array()){
$students = array();
if($studentsIds){
$studentsIds = "'".implode("','", $studentsIds)."'";
$students = $this->sConn->createCommand("
select stu.*, scr.serial_number, scr.userno
from student_info as stu
left join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
where stu.student_id in({$studentsIds})
order by serial_number asc
")->queryAll();
}
return $students;
}
public function getClassStudents($classId, $condition = array(), $type = "OBJ"){
$students = array();
if($classId){
$condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
$condition = $this->condition($condition);
$students = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
order by serial_number asc
")->queryAll();
}
if($type == "OBJ")
$students = Arr::toObj($students);
return $students;
}
public function getClassStudentsListWithAccounts1($classId, $condition = array(), $pageSize = 9,$where=''){
$student_ids = array();
if(empty($where))
{
if(is_array($classId)){
$rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
}else{
$rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
}
}else
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryRow();
if($accounts)
{
$condition= array("stu.student_id=" . $accounts['student_id']);
if(is_array($classId)){
$rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
}else{
$rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
}
}else
{
$rs["rs"] =array();
$rs['pager'] = (object)array();
$rs['pager']->rowsCount = 0;
}
}
if($rs["rs"]){
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["username"] = "";
$rs["rs"][$key]["status"] = null;
}
$studentsIds = $this->grouping($rs["rs"], "student_id");
$studentsIds = implode("','", $studentsIds);
$studentsIds = "'{$studentsIds}'";
if($where)
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
if($accounts){
foreach($accounts as $account){
foreach($rs["rs"] as $key => $val){
if($val["student_id"] && $val["student_id"] == $account["student_id"]){
$rs["rs"][$key]["username"] = $account["username"];
$rs["rs"][$key]["student_card"] = $account["student_card"];
$rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
if(isset($account["zhixue_student_card"]))
{
$rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
}
$rs["rs"][$key]["status"] = $account["status"];
}else
{
unset($rs["rs"][$key]);
$rs['pager']->rowsCount = 0;
}
}
}
}else
{
foreach($rs["rs"] as $key => $val){
unset($rs["rs"][$key]);
}
$rs['pager']->rowsCount = 0;
}
}else
{
$accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
if($accounts){
foreach($accounts as $account){
foreach($rs["rs"] as $key => $val){
if($val["student_id"] && $val["student_id"] == $account["student_id"]){
$rs["rs"][$key]["username"] = $account["username"];
$rs["rs"][$key]["student_card"] = $account["student_card"];
$rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
if(isset($account["zhixue_student_card"]))
{
$rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
}
$rs["rs"][$key]["status"] = $account["status"];
}
}
}
}
}
}
return $rs;
}
public function getClassStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9,$where=''){
$student_ids = array();
if(empty($where))
{
if(is_array($classId)){
$rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
}else{
$rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
}
}else
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
if($accounts)
{
$studentIdOr=array();
foreach ($accounts as $v){
$studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
}
$condition= array(" (".implode(' OR ',$studentIdOr).") ","c.class_type=1");
if(is_array($classId)){
$rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
}else{
$rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
}
}else
{
$rs["rs"] =array();
$rs['pager'] = (object)array();
$rs['pager']->rowsCount = 0;
}
}
//debug($rs["rs"]);
if($rs["rs"]){
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["username"] = "";
$rs["rs"][$key]["status"] = null;
}
$studentsIds = $this->grouping($rs["rs"], "student_id");
$studentsIds = implode("','", $studentsIds);
$studentsIds = "'{$studentsIds}'";
if($where)
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
if($accounts){
$b_student_status = array();
$b_student_card = array();
$b_student_username = array();
$b_school_student_card = array();
$b_zhixue_student_card = array();
foreach($accounts as $v)
{
$b_student_card[$v['student_id']] = $v['student_card'];
$b_student_status[$v['student_id']] = $v['status'];
$b_student_username[$v['student_id']] = $v['username'];
$b_school_student_card[$v['student_id']] = $v['school_student_card'];
$b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
}
foreach($rs["rs"] as $key => $val){
if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
$rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
$rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
$rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
if(isset($b_zhixue_student_card[$val["student_id"]]))
{
$rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
}
$rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
}else
{
unset($rs["rs"][$key]);
$rs['pager']->rowsCount = 0;
}
}
}else
{
foreach($rs["rs"] as $key => $val){
unset($rs["rs"][$key]);
}
$rs['pager']->rowsCount = 0;
}
}else
{
$accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
if($accounts){
$b_student_status = array();
$b_student_card = array();
$b_student_username = array();
$b_school_student_card = array();
$b_zhixue_student_card = array();
foreach($accounts as $v)
{
$b_student_card[$v['student_id']] = $v['student_card'];
$b_student_status[$v['student_id']] = $v['status'];
$b_student_username[$v['student_id']] = $v['username'];
$b_school_student_card[$v['student_id']] = $v['school_student_card'];
$b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
}
foreach($rs["rs"] as $key => $val){
if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
$rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
$rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
$rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
if(isset($b_zhixue_student_card[$val["student_id"]]))
{
$rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
}
$rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
}
}
}
}
}
return $rs;
}
public function classExamHasPaperRs($examId, $classId){
if($examId){
$rs = $this->sConn->createCommand("
select exists(
select *
from exam as e
join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
join student_info as stu on stu.student_id = spr.student_id
join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
where e.exam_id = '{$examId}' and (spr.scoring > 0 or spr.lost_score > 0) and spr.is_del=0
)
")->queryRow();
$rs = current($rs);
if($rs) return true;
}
return false;
}
public function isPreviousSemester($semesterId){
if(($semester = $this->getSemester($semesterId)) && ($currSemester = $this->getCurrSemester())){
if($semester["start_time"] < $currSemester["start_time"])
return true;
}
return false;
}
public function isFutureSemester($semesterId){
return !$this->isCurrentSemester($semesterId) && !$this->isPreviousSemester($semesterId) ? true : false;
}
public function kickTeacher($teacherId){
if($teacherId){
return Redist::del(Yii::app()->session->sessionID);
}
return false;
}
public function teacherPhoneNumberExists($phoneNumber){
if($phoneNumber){
$count = $this->conn->createCommand("select exists(select * from xb_teacher where phone_number = '{$phoneNumber}')")->queryRow();
$count = current($count);
return $count ? true : false;
}
return false;
}
public function getExamRsByClass($examId, $classId, $orderBy = array(), $type = ""){
if(!$orderBy)
$orderBy = array("--scr.serial_number asc", "stu.realname asc");
$orderBy = $this->orderBy($orderBy);
$rs = $this->sConn->createCommand("
select stu.student_id, stu.realname, stu.sex, stu.class_id, scr.userno, scr.serial_number, e.exam_id as exam_id, e.name as exam_name, p.paper_name,
spr.scoring, p.score, p.paper_id, spr.wrong_count, spr.partial_right_count
from exam as e
join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
join student_info as stu on stu.student_id = spr.student_id
join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
where e.exam_id = '{$examId}' and spr.is_del=0
{$orderBy}
")->queryAll();
if($rs){
Arr::sortByField($rs, "scoring", "DESC");
$previousRecord = 0;
$previousRank = 1;
foreach($rs as $key => $val){
if($val["scoring"] && $val["score"]){
$rs[$key]["right_rate"] = $val["scoring"] / $val["score"];
$rs[$key]["right_rate"] = sprintf("%.2f", $rs[$key]["right_rate"]);
}
else
$rs[$key]["right_rate"] = 0;
if($val["scoring"] && $val["score"]){
$rs[$key]["scoring_rate"] = $val["scoring"] / $val["score"];
$rs[$key]["scoring_rate"] = sprintf("%.2f", $rs[$key]["scoring_rate"]);
}
else
$rs[$key]["scoring_rate"] = 0;
$rs[$key]["wrong_count"] = $val["wrong_count"] + $val["partial_right_count"];
if($val["scoring"] == $previousRecord){
$rs[$key]["rank"] = $previousRank;
}
else{
$rs[$key]["rank"] = $key + 1;
}
$previousRecord = $val["scoring"];
$previousRank = $rs[$key]["rank"];
}
Arr::sortByField($rs, "serial_number");
}
if($type === "EXCEL"){
$array = array();
foreach($rs as $key => $val){
$array[$key] = array(
$val["serial_number"],
$val["realname"],
$val['exam_name'] . ($val["paper_name"] ? ' '.$val['paper_name'] : ''),
$val["scoring"],
$val["score"],
($val["scoring_rate"] * 100)."%",
$val["rank"],
$val["wrong_count"],
);
}
$title = array("编号", "姓名", "试卷", "得分", "总分", "得分率", "班级名次", "错题");
array_unshift($array, $title);
$rs = $array;
}
return $rs;
}
public function serialNumberExistsInClass($serialNumber, $classId, $studentId = null){
if($serialNumber && $classId){
$condition = array("class_id = '{$classId}'", "serial_number = '{$serialNumber}'", "status = 0");
if($studentId)
$condition = Arr::merge($condition, array("student_id != '{$studentId}'"));
$condition = $this->condition($condition);
$rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
return false;
}
public function getPrintTask($examId, $classId, $type){
if(!$examId || !$classId || !is_numeric($type))
return array();
return $this->sConn->createCommand("select * from class_exam_printer where exam_id = '{$examId}' and class_id = '{$classId}' and `type` = '{$type}'")->queryRow();
}
//获取班级多个考试
public function getClassExamAc($condition = array(), $orderBy = array("add_time desc")){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_topwb_html,cep.*, c.class_name, csr.subject_id, e.name as exam_name, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,
p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->queryAll();
return $handle;
}
public function getPrintListre($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_fine_paper,e.is_topwb_html,cep.*, c.class_name, csr.subject_id, e.name as exam_name, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,
p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id,eg.is_third,c.grade,e.status,eg.is_tagging,eg.qxk_paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1){
$examsStudentsCount[$examId]["is_complete_count"]++;
}
$examsStudentsCount[$examId]["is_uploaded_count"]++;
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
}
$tplData = json_decode($val["tpl_data"], true);
$paperSize = null;
$examDate = null;
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "12":
$paperSize = "A3";
break;
case "13":
$paperSize = "A4";
break;
case "14":
$paperSize = "8K";
break;
case "15":
$paperSize = "16K";
break;
case "2012":
$paperSize = "A3";
break;
case "2013":
$paperSize = "A4";
break;
case "2014":
$paperSize = "8K";
break;
case "2015":
$paperSize = "16K";
break;
case "2016":
$paperSize = "A3";
break;
case "2017":
$paperSize = "A4";
break;
case "2018":
$paperSize = "8K";
break;
case "2019":
$paperSize = "16K";
break;
case "1012":
$paperSize = "A3";
break;
case "1013":
$paperSize = "A4";
break;
case "1014":
$paperSize = "8K";
break;
case "1015":
$paperSize = "16K";
break;
case "1016":
$paperSize = "A3";
break;
case "1017":
$paperSize = "A4";
break;
case "1018":
$paperSize = "8K";
break;
case "1019":
$paperSize = "16K";
break;
case "3012":
$paperSize = "A3";
break;
case "3016":
$paperSize = "A3";
break;
}
}
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "16":
$paperSize = "A3";
break;
case "3016":
$paperSize = "A3";
break;
case "3007":
$paperSize = "A3";
break;
case "3012":
$paperSize = "A3";
break;
case "17":
$paperSize = "A4";
break;
case "18":
$paperSize = "8K";
break;
case "19":
$paperSize = "16K";
break;
}
}
if($tplData){
if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
$examDate = $val["create_time"];
if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
$paperSize = "A3";
$rs["rs"][$key]["topic_count"] = isset($tplData['totals'])?$tplData['totals']:0;
}
if($examDate === null)
$examDate = $val["create_time"];
if($paperSize === null)
$paperSize = "A4";
$time = time();
$expireTime = $examDate + (3600 * 24 * 2);
if($time > $expireTime){
$rs["rs"][$key]["is_expired"] = true;
}
else{
$rs["rs"][$key]["is_expired"] = false;
}
$rs["rs"][$key]["exam_time"] = $examDate;
$rs["rs"][$key]["paper_size"] = $paperSize;
}
return $rs;
}
//获取下载班级
public function getDownloadClassWb($condition = array(), $orderBy = array("add_time desc")){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$rs['rs'] = $this->sConn->createCommand("
select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.upload_status, e.create_time, e.is_display,eg.upload_status as group_upload_status, eg.mark_type, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->queryAll();
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
{
$examsStudentsCount[$examId]["is_complete_count"]++;
}
if($v["is_feedback"] == 1)
{
$examsStudentsCount[$examId]["is_uploaded_count"]++;
}
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
}
}
return $rs["rs"];
}
public function getPrintList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display,eg.upload_status as group_upload_status, eg.mark_type, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
{
$examsStudentsCount[$examId]["is_complete_count"]++;
}
if($v["is_feedback"] == 1)
{
$examsStudentsCount[$examId]["is_uploaded_count"]++;
}
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
}
$tplData = json_decode($val["tpl_data"], true);
$paperSize = null;
$examDate = null;
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "12":
$paperSize = "A3";
break;
case "13":
$paperSize = "A4";
break;
case "14":
$paperSize = "8K";
break;
case "15":
$paperSize = "16K";
break;
case "2012":
$paperSize = "A3";
break;
case "2013":
$paperSize = "A4";
break;
case "2014":
$paperSize = "8K";
break;
case "2015":
$paperSize = "16K";
break;
case "2016":
$paperSize = "A3";
break;
case "2017":
$paperSize = "A4";
break;
case "2018":
$paperSize = "8K";
break;
case "2019":
$paperSize = "16K";
break;
case "1012":
$paperSize = "A3";
break;
case "1013":
$paperSize = "A4";
break;
case "1014":
$paperSize = "8K";
break;
case "1015":
$paperSize = "16K";
break;
case "1016":
$paperSize = "A3";
break;
case "1017":
$paperSize = "A4";
break;
case "1018":
$paperSize = "8K";
break;
case "1019":
$paperSize = "16K";
break;
case "3016":
$paperSize = "A3";
break;
case "3012":
$paperSize = "A3";
break;
case "3013":
$paperSize = "A4";
break;
case "3017":
$paperSize = "A4";
break;
}
}
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "16":
$paperSize = "A3";
break;
case "3016":
$paperSize = "A3";
break;
case "3017":
$paperSize = "A4";
break;
case "3013":
$paperSize = "A4";
break;
case "3007":
$paperSize = "A3";
break;
case "17":
$paperSize = "A4";
break;
case "18":
$paperSize = "8K";
break;
case "19":
$paperSize = "16K";
break;
}
}
if($tplData){
if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
$examDate = $val["create_time"];
if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
$paperSize = "A3";
}
if($examDate === null)
$examDate = $val["create_time"];
if($paperSize === null)
$paperSize = "A4";
$time = time();
$expireTime = $examDate + (3600 * 24 * 2);
if($time > $expireTime){
$rs["rs"][$key]["is_expired"] = true;
}
else{
$rs["rs"][$key]["is_expired"] = false;
}
$rs["rs"][$key]["exam_time"] = $examDate;
$rs["rs"][$key]["paper_size"] = $paperSize;
}
return $rs;
}
public function getExamList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select c.class_name,e.exam_id,eg.exam_group_id,e.class_id, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, e.status, eg.mark_type, eg.mark_status,
p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id,eg.import_score_type
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by e.class_id, e.exam_id, e.`type`
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select paper_id,exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf,student_img_paper from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
$examsSprs = array();
$paperExamIds=array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
$paperExamIds[$val["exam_id"]]=$val["paper_id"];
}
$importScoretype=$this->grouping($rs["rs"], "import_score_type", true);
//判断上传成绩方式
$student_answer_img_num=array();
//导入方式,读取实际上传数量
foreach($paperExamIds as $eid =>$paperId){
$student_answer_img_num[$eid]=$this->getUpAnswerStudent($paperId,array(),true);
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"student_img_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
'student_img_up_num'
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
{
$examsStudentsCount[$examId]["is_complete_count"]++;
}
if($v["is_feedback"] == 1)
{
$examsStudentsCount[$examId]["is_uploaded_count"]++;
}
if(trim($v["student_img_paper"]))
{
$examsStudentsCount[$examId]["student_img_count"]++;
}
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
if(isset($student_answer_img_num[$examId])){
$examsStudentsCount[$examId]["student_img_up_num"]=$student_answer_img_num[$examId];
}else{
$examsStudentsCount[$examId]["student_img_up_num"]=0;
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["student_img_count"] = $examsStudentsCount[$val["exam_id"]]["student_img_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
$rs["rs"][$key]["student_img_up_num"] = $examsStudentsCount[$val["exam_id"]]["student_img_up_num"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["student_img_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
$rs["rs"][$key]["student_img_up_num"] = 0;
}
$tplData = json_decode($val["tpl_data"], true);
$paperSize = null;
$examDate = null;
if($tplData){
if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
$examDate = $val["create_time"];
if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
$paperSize = "A3";
}
if($examDate === null)
$examDate = $val["create_time"];
if($paperSize === null)
$paperSize = "A4";
$time = time();
$expireTime = $examDate + (3600 * 24 * 2);
if($time > $expireTime){
$rs["rs"][$key]["is_expired"] = true;
}
else{
$rs["rs"][$key]["is_expired"] = false;
}
$rs["rs"][$key]["exam_time"] = $examDate;
$rs["rs"][$key]["paper_size"] = $paperSize;
}
return $rs;
}
public function getThirdPrintList($condition = array(), $orderBy = array("e.create_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$sql="select eg.*,e.exam_id,e.school_card_status,e.school_card_length, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, eg.mark_type, eg.mark_status,e.subject_id,e.class_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled, p.labelled_type,p.paper_id
from exam_group as eg
left join exam as e on eg.exam_group_id = e.exam_group_id
left join paper as p on p.exam_id = e.exam_id
{$condition}
group by eg.exam_group_id
{$orderBy}
";
$handle = $this->sConn->createCommand($sql)->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
//获取下载班级
public function getDownloadClassIpf($condition = array(), $orderBy = array("add_time desc")){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$rs['rs'] = $this->sConn->createCommand("
select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.upload_status, e.create_time,e.complete_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->queryAll();
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds})")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
{
$examsStudentsCount[$examId]["is_complete_count"]++;
}
$examsStudentsCount[$examId]["is_uploaded_count"]++;
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
}
}
return $rs["rs"];
}
public function getPrintList_ipf($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.complete_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf,is_wrongbook_download,is_two_isp_download,is_three_isp_download from student_paper_relation where exam_id in({$examsIds})")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
"wrongbook_download_count" => 0,
"wbisp_download_count" => 0,
"isp_download_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
{
$examsStudentsCount[$examId]["is_complete_count"]++;
}
$examsStudentsCount[$examId]["is_uploaded_count"]++;
if($v["is_wrongbook_pdf"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
}
if($v["is_wbisp_pdf"] == 1)
{
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
}
if($v["is_isp_pdf"] == 1)
{
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
if($v["is_wrongbook_download"] == 1)
{
$examsStudentsCount[$examId]["wrongbook_download_count"]++;
}
if($v["is_two_isp_download"] == 1)
{
$examsStudentsCount[$examId]["isp_download_count"]++;
}
if($v["is_three_isp_download"] == 1)
{
$examsStudentsCount[$examId]["wbisp_download_count"]++;
}
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
$rs["rs"][$key]["wrongbook_download_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_download_count"];
$rs["rs"][$key]["isp_download_count"] = $examsStudentsCount[$val["exam_id"]]["isp_download_count"];
$rs["rs"][$key]["wbisp_download_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_download_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
$rs["rs"][$key]["wrongbook_download_count"] = 0;
$rs["rs"][$key]["isp_download_count"] = 0;
$rs["rs"][$key]["wbisp_download_count"] = 0;
}
$tplData = json_decode($val["tpl_data"], true);
$paperSize = null;
$examDate = null;
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "12":
$paperSize = "A3";
break;
case "13":
$paperSize = "A4";
break;
case "14":
$paperSize = "8K";
break;
case "15":
$paperSize = "16K";
break;
case "2012":
$paperSize = "A3";
break;
case "2013":
$paperSize = "A4";
break;
case "2014":
$paperSize = "8K";
break;
case "2015":
$paperSize = "16K";
break;
case "2016":
$paperSize = "A3";
break;
case "2017":
$paperSize = "A4";
break;
case "2018":
$paperSize = "8K";
break;
case "2019":
$paperSize = "16K";
break;
case "1012":
$paperSize = "A3";
break;
case "1013":
$paperSize = "A4";
break;
case "1014":
$paperSize = "8K";
break;
case "1015":
$paperSize = "16K";
break;
case "1016":
$paperSize = "A3";
break;
case "1017":
$paperSize = "A4";
break;
case "1018":
$paperSize = "8K";
break;
case "1019":
$paperSize = "16K";
break;
}
}
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "16":
$paperSize = "A3";
break;
case "17":
$paperSize = "A4";
break;
case "18":
$paperSize = "8K";
break;
case "19":
$paperSize = "16K";
break;
}
}
if($tplData){
if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
$examDate = $val["create_time"];
if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
$paperSize = "A3";
}
if($examDate === null)
$examDate = $val["create_time"];
if($paperSize === null)
$paperSize = "A4";
$time = time();
$expireTime = $examDate + (3600 * 24 * 2);
if($time > $expireTime){
$rs["rs"][$key]["is_expired"] = true;
}
else{
$rs["rs"][$key]["is_expired"] = false;
}
$rs["rs"][$key]["exam_time"] = $examDate;
$rs["rs"][$key]["paper_size"] = $paperSize;
}
return $rs;
}
public function getPrintListOfCoach($coachId, $condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$rs = $this->buildEmptyPagingStruct();
if($coachId){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
from class as c
join class_subject_relation as csr on csr.class_id = c.class_id
join exam as e on e.class_id = c.class_id
join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
join paper as p on p.exam_id = e.exam_id
{$condition}
group by class_id, exam_id, type
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$examsIds = $this->grouping($rs["rs"], "exam_id", true);
$examsIds = "'".implode("','", $examsIds)."'";
$sprs = $this->sConn->createCommand("select * from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
$examsSprs = array();
foreach($sprs as $key => $val){
if(!isset($examsSprs[$val["exam_id"]]))
$examsSprs[$val["exam_id"]] = array();
$examsSprs[$val["exam_id"]][] = $val;
}
$examsStudentsCount = array();
foreach($examsSprs as $examId => $sprs){
$examsStudentsCount[$examId] = array(
"is_complete_count" => 0,
"is_uploaded_count" => 0,
"wrongbook_pdf_count" => 0,
"wbisp_pdf_count" => 0,
"isp_pdf_count" => 0,
);
$examsStudentsCount[$examId]["students_count"] = count($sprs);
foreach($sprs as $k => $v){
if($v["is_complete"] == 1)
$examsStudentsCount[$examId]["is_complete_count"]++;
if($v["is_feedback"] == 1)
$examsStudentsCount[$examId]["is_uploaded_count"]++;
if($v["is_wrongbook_pdf"] == 1)
$examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
if($v["is_wbisp_pdf"] == 1)
$examsStudentsCount[$examId]["wbisp_pdf_count"]++;
if($v["is_isp_pdf"] == 1)
$examsStudentsCount[$examId]["isp_pdf_count"]++;
}
}
foreach($rs["rs"] as $key => $val){
if(isset($examsStudentsCount[$val["exam_id"]])){
$rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
$rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
$rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
$rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
$rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
$rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
}
else{
$rs["rs"][$key]["students_count"] = 0;
$rs["rs"][$key]["is_complete_count"] = 0;
$rs["rs"][$key]["is_uploaded_count"] = 0;
$rs["rs"][$key]["wrongbook_pdf_count"] = 0;
$rs["rs"][$key]["wbisp_pdf_count"] = 0;
$rs["rs"][$key]["isp_pdf_count"] = 0;
}
$tplData = json_decode($val["tpl_data"], true);
$paperSize = null;
$examDate = null;
if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
switch($val["tpl_index"]){
case "12":
$paperSize = "A3";
break;
case "13":
$paperSize = "A4";
break;
case "14":
$paperSize = "8K";
break;
case "15":
$paperSize = "16K";
break;
case "2012":
$paperSize = "A3";
break;
case "2013":
$paperSize = "A4";
break;
case "2014":
$paperSize = "8K";
break;
case "2015":
$paperSize = "16K";
break;
case "2016":
$paperSize = "A3";
break;
case "2017":
$paperSize = "A4";
break;
case "2018":
$paperSize = "8K";
break;
case "2019":
$paperSize = "16K";
break;
case "1012":
$paperSize = "A3";
break;
case "1013":
$paperSize = "A4";
break;
case "1014":
$paperSize = "8K";
break;
case "1015":
$paperSize = "16K";
break;
case "1016":
$paperSize = "A3";
break;
case "1017":
$paperSize = "A4";
break;
case "1018":
$paperSize = "8K";
break;
case "1019":
$paperSize = "16K";
break;
case "3013":
$paperSize = "A4";
break;
case "3017":
$paperSize = "A4";
break;
}
}
if($tplData){
if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
$examDate = $val["create_time"];
if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
$paperSize = "A3";
}
if($examDate === null)
$examDate = $val["create_time"];
if($paperSize === null)
$paperSize = "A4";
$time = time();
$expireTime = $examDate + (3600 * 24 * 2);
if($time > $expireTime){
$rs["rs"][$key]["is_expired"] = true;
}
else{
$rs["rs"][$key]["is_expired"] = false;
}
$rs["rs"][$key]["exam_time"] = $examDate;
$rs["rs"][$key]["paper_size"] = $paperSize;
}
}
return $rs;
}
public function getClassesByCoachId($coachId,$grade=''){
$classes = array();
if($coachId){
if(in_array($grade, array("1", "2", "3"))) {
$classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}' and grade='{$grade}'")->queryAll();
} else {
$classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}'")->queryAll();
}
}
return $classes;
}
public function getClassesIdsByCoachId($coachId){
$rs = $this->getClassesByCoachId($coachId);
$ids = $this->grouping($rs, "class_id");
return $ids;
}
/**
* 获取学期的班级
* @param $semesterId
*
* @return array|\CDbDataReader
*/
public function getSemesterClasses($semesterId){
$classes = array();
if($semesterId){
$classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
}
return $classes;
}
public function getSemesterClassesStudent($semesterId){
$classes = array();
if($semesterId){
$classes = $this->sConn->createCommand("
select c.*
from class as c
left join student_class_relation as scr on scr.class_id = c.class_id
where c.semester_id = ".$semesterId ." and scr.status = 0 and c.is_hide=0
group by scr.class_id ")->queryAll();
}
return $classes;
}
public function getSemesterStudents($semesterId){
$students = array();
if($semesterId){
$students = $this->sConn->createCommand("
select stu.student_id, stu.realname, scr.class_id, scr.userno, scr.serial_number
from class as c
join student_class_relation as scr on scr.class_id = c.class_id and scr.status = 1
join student_info as stu on stu.student_id = scr.student_id
where c.semester_id = '{$semesterId}'
group by stu.student_id
")->queryAll();
}
return $students;
}
public function activateSemesterClassesStudentsRelations($semesterId){
$rs = false;
if($semesterId){
$students = $this->getSemesterStudents($semesterId);
$classes = $this->getSemesterClasses($semesterId);
if($students && $classes){
$studentsIds = $this->grouping($students, "student_id");
$studentsIds = "'".implode("','", $studentsIds)."'";
$classesIds = $this->grouping($classes, "class_id");
$classesIds = "'".implode("','", $classesIds)."'";
try{
$trans = $this->sConn->beginTransaction();
$this->sConn->createCommand("update student_class_relation set status = '1' where student_id in({$studentsIds}) and status = 0")->execute();
$this->sConn->createCommand("update student_class_relation set status = '0' where student_id in({$studentsIds}) and class_id in({$classesIds}) and status = 1")->execute();
foreach($students as $student){
$this->sConn->createCommand("update student_info set class_id = '{$student["class_id"]}' where student_id = '{$student["student_id"]}'")->execute();
}
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
}
}
return $rs;
}
public function getExamPaper($examId){
$paper = array();
if($examId){
$paper = $this->sConn->createCommand("select * from paper where exam_id = '{$examId}'")->queryRow();
}
return $paper;
}
public function setPrintTransChecked($classId, $examId){
if($classId && $examId){
$rs = $this->sConn->createCommand("select exists(select * from class_exam_printer where class_id = '{$classId}' and exam_id = '{$examId}' and type = '2' and is_checked = 1)")->queryRow();
$isChecked = current($rs) > 0 ? true : false;
if($isChecked)
$rs = true;
else{
$rs = $this->sConn->createCommand("update class_exam_printer set is_checked = '1' where class_id = '{$classId}' and exam_id = '{$examId}' and type = '2'")->execute();
}
return $rs ? true : false;
}
return false;
}
public function setStudentIspChecked($planId){
if($planId){
$rs = $this->sConn->createCommand("select exists(select * from student_improve_score_plan where plan_id = '{$planId}' and is_checked = 1)")->queryRow();
$isChecked = current($rs) > 0 ? true : false;
if($isChecked)
$rs = true;
else{
$rs = $this->sConn->createCommand("update student_improve_score_plan set is_checked = '1' where plan_id = '{$planId}'")->execute();
}
return $rs ? true : false;
}
return false;
}
public function getClassStudentsIspsList($classId, $examId, $orderBy = array("scr.serial_number asc", "stu.realname asc"), $pageSize = 9){
$isps = $this->buildEmptyPagingStruct();
/*if($examId && $classId){
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
where scr.class_id = '{$classId}' and sisp.is_created=1 and scr.status = 0
{$orderBy}
")->query();
$isps = $this->paging($this->sConn, $handle, $pageSize);
}*/
if($examId && $classId){
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
where scr.class_id = '{$classId}' and sisp.is_created=1
{$orderBy}
")->query();
$isps = $this->paging($this->sConn, $handle, $pageSize);
}
return $isps;
}
public function getIspInfo($planId){
$isp = array();
if($planId){
$isp = $this->sConn->createCommand("
select sisp.*, p.difficulty, p.score, spr.class_id
from student_improve_score_plan as sisp
join paper as p on p.paper_id = sisp.paper_id
join student_paper_relation as spr on spr.student_id = sisp.student_id and spr.paper_id = sisp.paper_id
where sisp.plan_id = '{$planId}' and spr.is_del=0
")->queryRow();
}
return $isp;
}
//获取题目难度描述
public function getTopicDifficultyDescription($key){
$key = (string)$key;
$description = array(
"1" => "容易",
"2" => "中等",
"3" => "困难",
);
return isset($description[$key]) ? $description[$key] : "";
}
//从接口获取题目信息
public function getTopics($topicsIds = array(), $detial = false,$subject=0,$params=array()){
$topics = array();
$array = array();
$cachedTopics = array();
if($topicsIds){
foreach($topicsIds as $val){
if(!$val)
continue;
$array[$this->topicField][] = $val;
}
if($subject && $subject!=8){
$array['subjectId']=$subject;
}
if($params){
$array['params']=$params;
}
if($array){
$topics = Curl::post($this->topicUrl, $array);
$topics = json_decode($topics, true);
if(isset($topics["status"]))
{
// unset($array['subjectId']);
// unset($array['params']);
// $topics = Curl::post($this->topicUrl, $array);
// $topics = json_decode($topics, true);
// if(isset($topics["status"])) $topics = array();
$topics = array();
}
}
}
return $topics;
}
public function getTopic($topicId){
$topic = array();
if($topicId){
$rs = $this->getTopics(array($topicId));
if($rs) $topic = current($rs);
}
return $topic;
}
public function getTopicsByIspRecords($plan, $topicsRs, $paperTopicsRecords){
$topics = array();
if(Arr::isAvailable($plan) && Arr::isAvailable($topicsRs) && Arr::isAvailable($paperTopicsRecords)){
$topicsIds = array();
$schoolTopicsIds = array();
foreach($topicsRs as $topicRs){
foreach($paperTopicsRecords as $paperTopicRecord){
$topicsIds[] = $topicRs["topic_id"];
}
}
$schoolTopicsIds = array_unique($schoolTopicsIds);
$topicsIds = array_unique($topicsIds);
$schoolTopicsIds = "'".implode("','", $schoolTopicsIds)."'";
$topics = $this->getTopics($topicsIds);
}
return $topics;
}
public function getTopicsRecordsFromStudentIsp($planId, $type = "ALL"){
$rs = array();
if($planId){
$condition = array("plan_id = '{$planId}'");
if($type === "IMPROVE")
$condition = Arr::merge($condition, array("is_template = 0"));
$condition = $this->condition($condition);
$rs = $this->sConn->createCommand("select * from student_improve_score_plan_topics{$condition}")->queryAll();
}
return $rs;
}
public function getIspTopics($planId){
$topics = array();
if($isp = $this->getIspInfo($planId)){
$topicsRecords = $this->getTopicsRecordsFromStudentIsp($planId);
$paperTopicsRecords = $this->getPaperTopicsRecords($isp["paper_id"]);
$topics = $this->getTopicsByIspRecords($isp, $topicsRecords, $paperTopicsRecords);
foreach($topics as $key => $topic){
foreach($topicsRecords as $k => $v){
if($topic["id"] == $v["topic_id"]){
$topics[$key]["is_source"] = $v["is_template"];
$topics[$key]["source_id"] = $v["template_id"];
}
}
}
foreach($topics as $key => $topic){
foreach($paperTopicsRecords as $k => $topicRecord){
if($topic["id"] == $topicRecord["topic_id"])
$topics[$key]["number"] = $topicRecord["no"];
}
}
}
return $topics;
}
public function getIspTopicsIds($planId){
$ids = array();
if($rs = $this->getTopicsRecordsFromStudentIsp($planId)){
$ids = $this->grouping($rs, "topic_id");
}
return $ids;
}
public function getPaperTopicsRecords($paperId){
$records = array();
if($paperId){
$records = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paperId}' order by type asc, `order` asc")->queryAll();
}
return $records;
}
public function getPaperTopics($paperId,$subject=0,$params=array(),$onlySlave=0){
if(!($ptrs = $this->getPaperTopicsRecords($paperId)))
return array();
$schoolTopicsIds = array();
$topicsIds = array();
foreach($ptrs as $ptr){
if($onlySlave==1){
$topicsIds[] = $ptr["topic_id"];
}else{
if(isset($ptr['stem_id']) && $ptr['stem_id']){
$topicsIds[] = $ptr["stem_id"];
}else{
$topicsIds[] = $ptr["topic_id"];
}
}
}
$topics = $this->getTopics($topicsIds,false,$subject,$params);
return $topics;
}
public function getPaperTopicsIds($paperId){
if(!($topicsRecords = $this->getPaperTopicsRecords($paperId)))
return array();
return $this->grouping($topicsRecords, "topic_id");
}
public function composeIspTopics($planId, $topics){
$sections = array(
"选择题" => array(
"type_id" => 1,
"type_name" => "单选题",
"wrong_topics" => array(),
"wrong_topics_count" => 0,
"correct_topics" => array(),
"correct_topics_count" => 0,
"order" => $this->topicTypesOrder["选择题"],
),
"填空题" => array(
"type_id" => 5,
"type_name" => "填空题",
"wrong_topics" => array(),
"wrong_topics_count" => 0,
"correct_topics" => array(),
"correct_topics_count" => 0,
"order" => $this->topicTypesOrder["填空题"],
),
"解答题" => array(
"type_id" => 7,
"type_name" => "简答题",
"wrong_topics" => array(),
"wrong_topics_count" => 0,
"correct_topics" => array(),
"correct_topics_count" => 0,
"order" => $this->topicTypesOrder["解答题"],
),
);
if($topics){
$topicsOrder = array();
$topicNum = 1;
foreach($sections as $key => $val){
foreach($topics as $k => $topic){
if($topic["type_id"] == $val["type_id"]){
if($topic["is_source"]){
$sections[$key]["wrong_topics"][$topic["id"]] = $topic;
}
else{
$sections[$key]["correct_topics"][$topic["source_id"]][$topic["id"]] = $topic;
$sections[$key]["correct_topics_count"]++;
}
}
}
$sections[$key]["wrong_topics_count"] = count($sections[$key]["wrong_topics"]);
foreach($sections[$key]["wrong_topics"] as $wrongTopicId => $wrongTopic){
if(!isset($wrongTopic["kps"]))
$wrongTopic["kps"] = array();
$kps = $wrongTopic["kps"];
$kpsNames = $this->grouping($kps, "kp_name");
$kpsNamesStr = implode("; ", $kpsNames);
$sections[$key]["wrong_topics"][$wrongTopicId]["kps"] = $kps;
$sections[$key]["wrong_topics"][$wrongTopicId]["kps_names_str"] = $kpsNamesStr;
$sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"] = array();
$wrongTopicMethodsNames = array();
if(!empty($wrongTopic["specials"])){
foreach($wrongTopic["specials"] as $method){
$wrongTopicMethodsNames[] = $method["method_name"];
if($method["method_id"])
$sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"][] = $method["method_id"];
}
}
$sections[$key]["wrong_topics"][$wrongTopicId]["methods_names_str"] = implode("; ", $wrongTopicMethodsNames);
unset($wrongTopicMethodsNames);
if(!empty($sections[$key]["correct_topics"][$wrongTopic["id"]])){
foreach($sections[$key]["correct_topics"][$wrongTopic["id"]] as $correctTopicId => $correctTopic){
if(!isset($correctTopic["kps"]))
$correctTopic["kps"] = array();
$kps = $correctTopic["kps"];
$kpsNames = $this->grouping($kps, "kp_name");
$kpsNamesStr = implode("; ", $kpsNames);
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps"] = $kps;
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps_names_str"] = $kpsNamesStr;
//过滤掉图片float样式
/*$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace_callback(
"/float\s*?:\s*?[a-zA-Z]*?\s*?(;|\"|\')/i",
function($matches){
return $matches[0] == "\"" || $matches[0] == "'" ? $matches[0] : "";
},
$correctTopic["title"]
);
//将题干相对路径转换为绝对路径
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace(
"/src\s*?\=\s*?\"\s*?(\/.*)\.((?:gif)|(?:jpg)|(?:png))(.*?)\"/i",
"src=\"{$this->topicHost}$1.$2$3$4\"",
$correctTopic["title"]
);*/
$topicsOrder[$correctTopicId] = $topicNum;
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"] = array();
$correctTopicMethodsNames = array();
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = 0;
if(isset($correctTopic["specials"])){
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = count($correctTopic["specials"]);
foreach($correctTopic["specials"] as $tsm){
if($tsm["method_id"]){
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"][] = $tsm["method_id"];
$correctTopicMethodsNames[] = $tsm["method_name"];
}
}
}
$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_names_str"] = implode("; ", $correctTopicMethodsNames);
unset($correctTopicMethodsNames);
$topicNum++;
}
Arr::sortByField($sections[$key]["correct_topics"][$wrongTopic["id"]],'');
}
}
Arr::sortByField($sections[$key]["wrong_topics"], "number", "ASC");
if(!$this->ispTopicsOrderSeted($planId))
$this->setIspTopicsOrder($planId, $topicsOrder);
}
Arr::sortByField($sections,'', "ASC", "NATURAL", true);
}
return $sections;
}
public function ispTopicsOrderSeted($planId){
if($topics = $this->getTopicsRecordsFromStudentIsp($planId, "IMPROVE")){
return true;
}
return false;
}
public function setIspTopicsOrder($planId, $order = array()){
if($planId && $order){
try{
$trans = $this->sConn->beginTransaction();
foreach($order as $key => $val){
$this->sConn->createCommand("update student_improve_score_plan_topics set `order` = '{$val}' where plan_id = '{$planId}' and topic_id = '{$key}'")->execute();
}
$trans->commit();
return true;
}
catch(Exception $e){
$trans->rollBack();
return false;
}
}
return false;
}
public function ispTopicExists($topicId, $planId){
if($topicId && $planId){
$rs = $this->sConn->createCommand("select exists(select * from student_improve_score_plan_topics where topic_id = '{$topicId}' and plan_id = '{$planId}' and is_template = 0)")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
return false;
}
public function getIspTopic($planId, $topicId){
$topic = array();
if($planId && $topicId){
$topic = $this->sConn->createCommand("select * from student_improve_score_plan_topics where topic_id = '{$topicId}' and plan_id = '{$planId}' and is_template = 0")->queryRow();
}
return $topic;
}
public function replaceIspTopic($planId, $previousTopicId, $newTopicId){
$code = 1001;
if($previousTopicId && $newTopicId){
$code = array();
if($previousTopicId == $newTopicId)
$code[] = 2001;
if(!$this->ispTopicExists($previousTopicId, $planId))
$code[] = 2002;
if($this->ispTopicExists($newTopicId, $planId))
$code[] = 2003;
if($code)
return $this->rs($code, __FUNCTION__);
$rs = $this->sConn->createCommand("update student_improve_score_plan_topics set topic_id = '{$newTopicId}' where topic_id = '{$previousTopicId}' and plan_id = '{$planId}' and is_template = 0")->execute();
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
public function changeExamStatus($examId, $status){
if($examId){
$rs = $this->sConn->createCommand("update exam set status = '{$status}' where exam_id = '{$examId}'")->execute();
return $rs ? true : false;
}
return false;
}
public function getStudentByIspId($planId){
$student = array();
if($planId){
$student = $this->sConn->createCommand("
select stu.*
from student_improve_score_plan as sisp
join student_info as stu on stu.student_id = sisp.student_id
where sisp.plan_id = '{$planId}'
")->queryRow();
}
return $student;
}
public function getStudentIdByIspId($planId){
$studentId = null;
if($student = $this->getStudentByIspId($planId)){
$studentId = $student["student_id"];
}
return $studentId;
}
public function getClassVacationHomeworkList($classId, $pageSize = 9){
if(!$classId)
return $this->buildEmptyPagingStruct();
$handle = $this->sConn->createCommand("
select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
from class_vacation_homework as cvh
join class as c on c.class_id = cvh.class_id
join semester as seme on seme.semester_id = cvh.semester_id
where cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'
order by cvh.generate_time desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getClassesVacationHomeworkList($pageSize = 9){
$handle = $this->sConn->createCommand("
select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
from class_vacation_homework as cvh
join class as c on c.class_id = cvh.class_id
join semester as seme on seme.semester_id = cvh.semester_id
where cvh.semester_id = '{$this->semester["id"]}'
order by cvh.generate_time desc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getClassVhStudents($classId,$realname = NULL, $pageSize = 9){
if(!$classId)
return $this->buildEmptyPagingStruct();
$where = '';
// debug($realname);
if (!empty($realname)) {
$where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}' and stu.realname like '%{$realname}%'";
} else {
$where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'";
}
$handle = $this->sConn->createCommand("
select c.class_name, c.class_id, stu.realname, cvh.semester_id, vh.is_generated, stu.student_id
from class_vacation_homework as cvh
join vacation_homework as vh on vh.class_id = cvh.class_id and vh.semester_id = cvh.semester_id
join student_info as stu on stu.student_id = vh.student_id
join class as c on c.class_id = cvh.class_id
where {$where}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getMaterialChapters($materialId){
$chapters = array();
if($materialId){
if(!($module = Yii::app()->cache->get("material_{$materialId}"))){
$module = Curl::post($this->moduleUrl, array($this->moduleField => $materialId));
$module = json_decode($module, true);
if($module)
Yii::app()->cache->set("material_{$materialId}", $module, $this->chapterCacheTime);
}
if(isset($module["chapters"]) && $module["chapters"]){
foreach($module["chapters"] as $chapter){
$chapters[$chapter["chapter_id"]] = $chapter;
if($chapter["chapter_id"] && !Yii::app()->cache->get("chapter_{$chapter["chapter_id"]}"))
Yii::app()->cache->set("chapter_{$chapter["chapter_id"]}", $chapter, $this->chapterCacheTime);
}
}
}
return $chapters;
}
public function getSchoolInfo(){
return $this->conn->createCommand("select * from school where school_id = '{$this->schoolId}'")->queryRow();
}
public function getArea($areaId){
if(!$areaId)
return array();
return $this->conn->createCommand("select region_id as area_id, region_code as area_code, region_name as area_name from region where region_id = '{$areaId}'")->queryRow();
}
public function getSchoolAreaFromSchoolInfo($schoolInfo){
$schoolArea = array(
"province_id" => null,
"province_name" => null,
"city_id" => null,
"city_name" => null,
"district_id" => null,
"district_name" => null,
);
$municipalitiesIds = array(2, 3, 10, 23);
if(!Arr::isAvailable($schoolInfo, array("province_id", "city_id", "area_id")))
return $schoolArea;
if($area = $this->getArea($schoolInfo["province_id"])){
$schoolArea["province_id"] = $area["area_id"];
$schoolArea["province_name"] = $area["area_name"];
}
if($area = $this->getArea($schoolInfo["city_id"])){
$schoolArea["city_id"] = $area["area_id"];
$schoolArea["city_name"] = $area["area_name"];
}
if($area = $this->getArea($schoolInfo["area_id"])){
$schoolArea["district_id"] = $area["area_id"];
$schoolArea["district_name"] = $area["area_name"];
}
if(in_array($schoolArea["province_id"], $municipalitiesIds))
$schoolArea["city_name"] = $schoolArea["province_name"];
return $schoolArea;
}
public function getCoachIdByClassId($classId){
if(!$classId)
return null;
$rs = $this->sConn->createCommand("select coach_id from `class` where class_id = '{$classId}'")->queryRow();
return $rs ? current($rs) : null;
}
public function getCoachClassRelationByClassId($classId, $type = "ARR"){
if(!$classId)
return array();
$rs = $this->sConn->createCommand("select coach_id, class_id from `class` where class_id = '{$classId}'")->queryRow();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getCoachClassesRelations($coachId, $type = "ARR"){
if(!$coachId)
return array();
$rs = $this->sConn->createCommand("select coach_id, class_id from class where coach_id = '{$coachId}'")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getExamClasses($examId){
if(!$examId)
return array();
return $this->sConn->createCommand("
select c.class_id, c.class_name
from exam as e
join class as c on c.class_id = e.class_id
where e.exam_id = '{$examId}'
")->queryAll();
}
public function changeExamUploadStatus($examId, $uploadStatus){
if(!$examId || !$uploadStatus)
return false;
return $this->sConn->createCommand()->update("exam", array("upload_status" => $uploadStatus), "exam_id = '{$examId}'");
}
public function ExamStatusAndUploadStatus($examId,$status,$upload_status){
if($examId){
$rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status= ".$status." and upload_status = ".$upload_status)->queryRow();
if($rs)
{
return $rs;
}
}
return false;
}
public function ExamStatusAndUploadStatusArr($examId,$statusArr,$upload_status){
if($examId){
$rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status in(".implode(',',$statusArr).") and upload_status = ".$upload_status)->queryRow();
if($rs)
{
return $rs;
}
}
return false;
}
public function getExamClassesRelations($examId, $type = "ARR"){
if(!$examId)
return array();
$rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}'")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getExamClassesRelationsFilteredByUploadStatus($examId, $uploadStatus, $type = "ARR"){
if(!$examId || !$uploadStatus)
return array();
$rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}' and upload_status = '{$uploadStatus}'")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getExamsByExamGroupId($examGroupId, $type = "ARR"){
if(!$examGroupId)
return array();
$rs = $this->sConn->createCommand("select * from exam where exam_group_id = '{$examGroupId}'")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getExamsIdsByExamGroupId($examGroupId){
if(!$examGroupId)
return array();
$rs = $this->sConn->createCommand("select exam_id from exam where exam_group_id = '{$examGroupId}'")->queryAll();
return $this->grouping($rs, "exam_id");
}
public function getExamGroupIdByExamId($examId){
if(!($exam = $this->getExam($examId)))
return null;
return $exam["exam_group_id"];
}
public function getStudentsPaperRs($paperId, $studentsIds, $type = "ARR"){
if(!$paperId || !is_array($studentsIds) || !$studentsIds)
return array();
$studentsIds = "'".implode("','", $studentsIds)."'";
$orderBy = array("scoring DESC", "right_count ASC", "student_id ASC");
$orderBy = $this->orderBy($orderBy);
$rs = $this->sConn->createCommand("select * from student_paper_relation where paper_id = '{$paperId}' and student_id in({$studentsIds}) and (scoring > 0 or lost_score > 0) and is_del=0 {$orderBy}")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getStudentsPdfsPaths($paperId, $studentsIds, $check = "", $type = "OBJ"){
if(!$paperId || !is_array($studentsIds) || !$studentsIds)
return array();
$studentsIds = "'".implode("','", $studentsIds)."'";
$condition = array("paper_id = '{$paperId}'", "student_id in({$studentsIds})", "(scoring > 0 or lost_score > 0)");
if($check == "WB"){
$condition[] = "is_wrongbook_pdf = 1";
}
else if($check == "ISP"){
$condition[] = "is_isp_pdf = 1";
}
else if($check == "WB_ISP"){
$condition[] = "is_wbisp_pdf = 1";
}
$condition[] = "is_del = 0";
$condition = $this->condition($condition);
$rs = $this->sConn->createCommand("select wrongbook_pdf_path, isp_pdf_path, wbisp_pdf_path from student_paper_relation{$condition}")->queryAll();
if($type == "OBJ"){
$rs = Arr::toObj($rs);
}
return $rs;
}
public function getThisYearSemesterDictionary($year){
if(!$year)
return array();
return $this->conn->createCommand("select * from semester_refer where code like '{$year}%'")->queryAll();
}
public function getThisYearSemesterName($semester_name){
if(!$semester_name)
return array();
return $this->conn->createCommand("select * from semester_refer where `name` = '".$semester_name."'")->queryRow();
}
public function classSubjectExists($classId){
if(!$classId)
return false;
$rs = $this->sConn->createCommand("select exists(select * from class_subject_relation where class_id = '{$classId}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function getSemesterNameByCode($code){
if(!$code)
return null;
$rs = $this->conn->createCommand("select `name` from semester_refer where `code` = '{$code}'")->queryRow();
if(!$rs)
return null;
return current($rs);
}
public function getPaperWithTopicsDetails($paperId, $type = "JSON"){
if(!$paperId)
return array();
$rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
if($type == "ARR" && $rs){
$rs = json_decode($rs, true);
}
return $rs;
}
public function getPaperWithTopicsDetails_v2($paperId, $type = "JSON"){
if(!$paperId)
return array();
$rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
if($type == "ARR" && $rs){
$rs = json_decode($rs, true);
}
return $rs;
}
public function getSubjectIdByTopic($topic){
return isset($topic["subject_id"]) ? $topic["subject_id"] : 0;
}
public function getSubjectIdByTplData($tplData){
return isset($tplData["subjectId"]) ? $tplData["subjectId"] : 0;
}
public function checkExamAnswers($examId){
if(!$examId)
return false;
$rs = $this->sConn->createCommand("
select stu.realname
from paper as p
join student_paper_relation as spr on spr.paper_id = p.paper_id
join student_paper_topic_rs as sptr on sptr.student_id = spr.student_id and sptr.paper_id = spr.paper_id
join student_info as stu on stu.student_id = spr.student_id
where p.exam_id = '{$examId}' and spr.is_feedback = 1 and spr.is_del=0 and (sptr.answer = '' and sptr.answer_url = '')
group by spr.student_id
")->queryAll();
if(!$rs)
return array();
$studentsNames = array();
foreach($rs as $student){
$studentsNames[] = $student["realname"];
}
return $studentsNames;
}
// 操作周周练显示状态
public function oprateExamDisplay($exam_groupId, $flag=0){
if($exam_groupId){
$rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_groupId}'")->execute();
return $rs ? true : false;
}
return false;
}
// 操作周周练显示状态
public function oprateExamExportDisplay($exam_Id, $flag=0){
if($exam_Id){
if($this->sConn->createCommand("UPDATE `exam` SET `export_dispaly` = '{$flag}' where `exam_id` = '{$exam_Id}'")->execute())
{
return true;
}
}
return false;
}
public function ThirdOprateExamDisplay($exam_group_id, $flag=0){
if($exam_group_id){
$rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_group_id}'")->execute();
return $rs ? true : false;
}
return false;
}
// 根据年级获取当前学期班级
public function getSchoolByGrade($grade,$semesterId) {
return $this->sConn->createCommand("select class_id,class_name from class where grade = '{$grade}' and semester_id='{$semesterId}'")->queryAll();
}
/**
* 刘红伟
*/
public function getPaperByExamId($exam_id){
if(!$exam_id)
return false;
$rs = $this->sConn->createCommand("select * from paper where `exam_id` = '{$exam_id}'")->queryRow();
if(!$rs)
return false;
return $rs;
}
public function getxuekeStatus($semester_id,$is_third = 0)
{
$subject_exam_data = array();
$class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semester_id));
$class_array = array();
if($class_data)
{
foreach($class_data as $v)
{
$class_array[$v->class_id] = $v->class_id;
}
}
$criteria = new CDbCriteria();
$criteria->addInCondition('class_id',$class_array);
$criteria->addCondition('is_new=:is_new');
$criteria->params[':is_new'] = 0;
$exam_data = Exam::model()->findAll($criteria);
unset($criteria);
$exam_group_id = array();
if($exam_data)
{
foreach($exam_data as $v)
{
$exam_group_id[$v->exam_group_id] = $v->exam_group_id;
$subject_exam_data[$v->exam_group_id][$v->subject_id][$v->exam_id] = $v->exam_id;
}
}
$subject = array();
$criteria = new CDbCriteria();
$criteria->addInCondition('exam_group_id',$exam_group_id);
$criteria->addCondition('is_third=:is_third');
$criteria->params[':is_third'] = $is_third;
$exam_group_data = ExamGroup::model()->findAll($criteria);
if($exam_group_data)
{
foreach($exam_group_data as $v)
{
if(isset($subject_exam_data[$v->exam_group_id]))
{
foreach($subject_exam_data[$v->exam_group_id] as $k=>$s)
{
$subject[$k] = $s;
}
}
}
}
return $subject;
}
public function getStudentProduct($class_ids,$subject_id=3){
if(!$class_ids) return false;
$sql = "select student_id,class_id from student_class_relation where class_id in (".implode(',',$class_ids).") and `status` = 0";
$res = $this->sConn->createCommand($sql)->queryAll();
$student_rel_class = array();
if($res){
foreach ($res as $v){
if(!isset($student_rel_class[$v['class_id']])){
$student_rel_class[$v['class_id']] = array();
}
$student_rel_class[$v['class_id']][] = $v['student_id'];
}
}
unset($res);
$rs_is_pdf = array();
$rs_is_download = array();
$class_buti=array();
//查询补题状态
$sql="select rpc.status,category,rpc.class_id from review_product_class rpc ";
$sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id ";
$sql.=" where rpps.semester_id = {$this->semester['id']} and rpps.subject_id='{$subject_id}' and rpc.status=5";
$res = $this->sConn->createCommand($sql)->queryAll();
if($res){
foreach ($res as $v){
$class_buti[(string)$v['class_id']][$v['category']]=1;
}
}
if($student_rel_class){
$create_num = array();
foreach ($student_rel_class as $class_id => $student_ids){
if(!$student_ids){
continue;
}
$__sql = "select student_id,is_download,type,product_type,rpc.status as rpc_status from student_product sp";
$__sql.=" left join review_product_class rpc on rpc.rpc_id=sp.plan_id";
$__sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id";
$__sql.= " where sp.semester_id = {$this->semester['id']} and student_id in(".implode(',',$student_ids).") and `type` >0 and rpps.subject_id='{$subject_id}'";
$sql = $__sql.' and is_pdf_created = 1 ';
$res = $this->sConn->createCommand($sql)->queryAll();
if($res){
foreach ($res as $v){
if(!isset($create_num[$class_id])){
$create_num[$class_id] = array();
}
if(!isset($create_num[$class_id][$v['product_type']])){
$create_num[$class_id][$v['product_type']] = 0;
}
$create_num[$class_id][$v['product_type']]++;
$rs_is_pdf[] = array(
'class_id' => $class_id,
'class_name' => '',
'is_download' => $v['is_download'],
'type' => $v['type'],
'student_id' => $v['student_id'],
'student_sum' => $create_num[$class_id][$v['product_type']],
'product_type'=>$v['product_type'],
'rpc_status'=>$v['rpc_status']
);
}
}
unset($res);
$sql = $__sql.' and is_download = 1 ';
$res = $this->sConn->createCommand($sql)->queryAll();
if($res){
$student_sum = count($student_ids);
foreach ($res as $v){
$rs_is_download[] = array(
'class_id' => $class_id,
'class_name' => '',
'is_download' => $v['is_download'],
'type' => $v['type'],
'student_id' => $v['student_id'],
'student_sum' => $student_sum,
'product_type'=>$v['product_type'],
);
}
}
unset($res);
}
}
return array($rs_is_pdf,$rs_is_download,$class_buti);
}
// public function getStudentProduct($condition = array()){
// $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
// $condition = $this->condition($condition);
// //后面需要优化
//
// $rs = $this->sConn->createCommand("
// select * from (SELECT
// c.class_name,
// c.class_id,
// p.is_download,
// p.`type`,
// p.student_id,
// COUNT(p.student_id) as student_sum
// FROM
// class AS c
// LEFT JOIN student_class_relation cr ON
// c.class_id = cr.class_id
// AND cr.`status` = 0
//
// LEFT JOIN student_product AS p ON p.student_id = cr.student_id
// {$condition} and p.semester_id = {$this->semester['id']}
// GROUP BY c.class_id,p.type ORDER BY c.grade asc,c.class_id asc)as gc WHERE `type` >0")->queryAll();
//
//
// if($rs)
// {
// return $rs;
// }
// return false;
// }
public function getPadSchool($school_ids)
{
$school_data = array();
if($school_ids){
$school_data = $this->conn->createCommand("
select s.*,sp.*
from school_project as sp
left join school as s on sp.school_id = s.school_id
WHERE s.school_id in (".implode(',',$school_ids).")
")->queryAll();
}
return $school_data;
}
//根据学校Id读取学生数据
public function getStudentBySchool($school_id){
$sql=" select student_id from student where school_id='".$school_id."' and status=1 ";
$Arr = $this->conn->createCommand($sql)->queryAll();
return $Arr;
}
//读取学生信息扩展字段设置
public function getStudentExtend(){
$sql="select * from student_info_extend ";
$Arr = $this->sConn->createCommand($sql)->queryAll();
$result=array();
if($Arr){
foreach ($Arr as $val){
$result[$val['field_name']]=array(
'field_mean'=>$val['field_mean'],
'is_enable'=>$val['is_enable']
);
}
}
return $result;
}
//默认设置扩展
public function setDefaultStudentExtend(){
$result=array();
$insert="insert into student_info_extend(`field_name`,`field_mean`,`is_enable`) values ('field_1','智学网考号',1)";
$this->sConn->createCommand($insert)->execute();
$result['field_1']=array(
'field_mean'=>'智学网考号',
'is_enable'=>1
);
return $result;
}
//切换学期,保留班级,保留学生
public function changeSemesterByStudentAndClass($semesterId,$oldSemesterId,$IsRetainClass=false,$IsGraduation=false,$classNewNameArr=array(),$gradeDirector=1){
if($semesterId && $oldSemesterId){
$code = array();
if($this->role !== ROLE_SU){
if($this->isPreviousSemester($semesterId))
$code[] = 2001;
if(!$this->semesterAllowToChange($semesterId)){
$code[] = 2002;
}
}
if($code)
return $this->rs($code, __FUNCTION__);
$class_r_class=array(); //新旧班级对应关系
$classSql="";
$classTeacherSql="";
$classSubjectSql='';
$classStudentSql='';
$updateStudentInfoSql=array();
$updateClassStudentSql='';
$updateClassProgressSql=array();
$classTypeArr=array();
$classifiedValues=array();
$classifiedSql='';
$updateTeacherSql=array(); //年级主任同步升班
$cancelClassSubjectId=array(); //不同步升级年级主任,则删除对应科目
$classesModel = new ClassModel();
$classes_old = $this->getSemesterClassesGraduation($oldSemesterId,$IsGraduation); //读取所有原班级
//判断是否保留班级
if($IsRetainClass){
if($classes_old){
$classValues=array();
$classTeacherValues=array();
$classSubjectValues=array();
foreach($classes_old as $val){
$classTypeArr[$val['class_id']]=$val['class_type'];
$checkCreatedClass=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$val['class_name']));
if ($checkCreatedClass)
{
$class_r_class[$val['class_id']]=$checkCreatedClass['class_id'];
continue;
}else{
//$classId = getUUID();
$classId = getUniqueId($this->schoolId);
if (empty($classId)) {
$code[]=2003;
return $this->rs($code, __FUNCTION__);
}
$class_r_class[$val['class_id']]=$classId;
$teacherIds=$this->getTeachersByClassesIds(array($val['class_id']));
$grade=$val['grade'];
$className=$val['class_name'];
if(isset($classNewNameArr[(string)$val['class_id']])){
$grade=$grade+1;
$className=$classNewNameArr[(string)$val['class_id']];
}
$classValues[]="('".$classId."','".$className."','".$val['level']."','".$grade."','".$semesterId."','".$val['period']."','".time()."','".$this->coachId."','".$val['wrong_book_type']."','".$val['improve_book_type']."','".$val['wb_isp_version']."','".$val['sort']."','".$val['arts_science']."','".$val['teacher_id']."','".$val['class_type']."')";
// $sql_teacher="select * from teacher_class_relation where class_id = '{$val['class_id']}';";
// $classTeacher=$this->sConn->createCommand($sql_teacher)->queryAll();
if($teacherIds){
foreach($teacherIds as $tid){
//读取教师岗位
if($classNewNameArr && $tid['posts']==3){
if($gradeDirector==1){
//同步升级
$updateTeacherSql[]="update teacher set grade='".$grade."' where teacher_id='".$tid['teacher_id']."'";
$classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
}elseif($gradeDirector==2){
//不同步,取消班级教师关联
$cancelClassSubjectId[$tid['subjects']]=$tid['subjects'];
}
}else{
$classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
}
}
}
//班级科目
$sql_subject="select * from class_subject_relation where class_id = '{$val['class_id']}';";
$classSubject=$this->sConn->createCommand($sql_subject)->queryAll();
if($classSubject){
foreach ($classSubject as $v){
if(!$cancelClassSubjectId || !isset($cancelClassSubjectId[$v['subject_id']])){
$classSubjectValues[]="('".$classId."','".$v['subject_id']."','".$v['material_id']."','".$v['module_ids']."')";
}
}
}
//更新教学进度
$updateClassProgressSql[]="update teach_progress_class set class_id = {$classId} where class_id = '{$val['class_id']}'";
}
}
//走班设置
$classified="select * from classified where semester_id='{$oldSemesterId}'";
$classifiedData=$this->sConn->createCommand($classified)->queryAll();
if($classifiedData){
foreach ($classifiedData as $value){
$classifiedValues[]="('".$value['grade']."','".$value['subject_id']."','".$value['status']."','".$semesterId."')";
}
}
//组装sql
if($classValues){
$classSql="insert into class(`class_id`,`class_name`,`level`,`grade`,`semester_id`,`period`,`add_time`,`coach_id`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`sort`,`arts_science`,`teacher_id`,`class_type`) values";
$classSql.=implode(',',$classValues);
if($classTeacherValues){
$classTeacherSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values";
$classTeacherSql.=implode(',',$classTeacherValues);
}
if($classSubjectValues){
$classSubjectSql="insert into class_subject_relation(`class_id`,`subject_id`,`material_id`,`module_ids`) values";
$classSubjectSql.=implode(',',$classSubjectValues);
}
}
if($classifiedValues){
$classifiedDel="delete from classified where semester_id='{$semesterId}'";
$classifiedSql='insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ';
$classifiedSql.=implode(',',$classifiedValues);
}
//学生处理
$classStudentSql="";
$classStudentValues=array();
$classIds=array();
if($class_r_class){
foreach ($class_r_class as $key=>$val){
//查询原班学生
$classStudent=$this->sConn->createCommand("select student_id,serial_number,userno,class_type from student_class_relation where class_id='".$key."' and status=0 ")->queryAll();
$studentIds=array();
if($classStudent){
$classIds[]=$key;
$classType=isset($classTypeArr[$key])?$classTypeArr[$key]:$v['class_type'];
foreach ($classStudent as $v){
$studentIds[]=$v['student_id'];
$classStudentValues[]="('".$val."','".$v['student_id']."',0,'".$v['serial_number']."','".$v['userno']."','".time()."',0,'".$classType."')";
}
$updateStudentInfoSql[]="update student_info set class_id='".$val."' where student_id in(".implode(',',$studentIds).") ;";
}
}
if($classStudentValues){
$classStudentSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
$classStudentSql.=implode(',',$classStudentValues);
}
}
if($classIds){
$updateClassStudentSql="update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$classIds).") and status=0; ";
}
}
}
//执行
$trans = $this->sConn->beginTransaction();
try{
if($this->semesterExists($semesterId)){
//切表
$inciseTables = $this->inciseTables;
$oldSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$oldSemesterId."'")->queryRow();
$newSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$semesterId."'")->queryRow();
foreach ($inciseTables as $inciseTable) {
$newTableName = $inciseTable . '_' . $newSemester['refer_code']; //新学期表名
$oldTableName= $inciseTable . '_' . $oldSemester['refer_code']; //旧学期(当前学期)需要改的名字
$existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow(); //查询新学期表是否存在
if($existTable){
//修改当前的表名
$existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
if($existOldTable){
//throw new Exception('3001');
//重复表进行重命名
$bakTableName=$oldTableName.'_'.date('YmdHis');
$this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
}
$this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
//修改新学期表名
$this->sConn->createCommand("ALTER TABLE ".$newTableName." RENAME TO ".$inciseTable)->execute();
}else{
//修改当前的表名
$existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
if($existOldTable){
//throw new Exception('3001');
//重复表进行重命名
$bakTableName=$oldTableName.'_'.date('YmdHis');
$this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
}
$this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
//创建新学期表
$this->sConn->createCommand('CREATE TABLE '.$inciseTable.' LIKE '.$oldTableName)->execute();
}
}
if($classSql){
$this->sConn->createCommand($classSql)->execute();
if($classTeacherSql){
$this->sConn->createCommand($classTeacherSql)->execute();
}
if($classSubjectSql){
$this->sConn->createCommand($classSubjectSql)->execute();
}
if($updateTeacherSql){
foreach ($updateTeacherSql as $sql){
$this->sConn->createCommand($sql)->execute();
}
}
}
if($classStudentSql){
$this->sConn->createCommand($classStudentSql)->execute();
if($updateClassStudentSql){
$this->sConn->createCommand($updateClassStudentSql)->execute();
}
if($updateStudentInfoSql){
foreach($updateStudentInfoSql as $query){
$this->sConn->createCommand($query)->execute();
}
}
}
if(isset($classifiedSql) && $classifiedSql ){
$this->sConn->createCommand($classifiedDel)->execute();
$this->sConn->createCommand($classifiedSql)->execute();
}
if($updateClassProgressSql){
foreach($updateClassProgressSql as $query){
$this->sConn->createCommand($query)->execute();
}
}
//处理毕业班学生
if($IsGraduation){
$classGraduation= $this->sConn->createCommand("select class_id from class where semester_id = '{$oldSemesterId}' and (grade=3 or grade=9)")->queryAll();
if($classGraduation){
$gClassId=array();
foreach ($classGraduation as $item){
$gClassId[]=$item['class_id'];
}
$this->sConn->createCommand("update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$gClassId).") and status=0; ")->execute();
}
}
$this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
$this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
$trans->commit();
$rs = true;
}
else
$rs = false;
}
catch(Exception $e){
$trans->rollBack();
if($e->getMessage()=='3001'){
$code[] = 3001;
return $this->rs($code, __FUNCTION__);
}else{
debug($e->getMessage());
$rs = false;
}
}
$code = $rs ? 0 : 1002;
}
return $this->rs($code, "global");
}
//前一学期待分班学生数量
public function getWaitStudent(){
$nowSemester=$this->getCurrSemester();
$count=0;
//前一学期
$sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
$prevSemester=$this->sConn->createCommand($sql)->queryRow();
$sql_student="select count(*) as count from student_class_relation scr ";
$sql_student.=" join class c on c.class_id=scr.class_id ";
$sql_student.=" where c.semester_id='".$prevSemester['semester_id']."' and scr.status=2 ";
$studentCount=$this->sConn->createCommand($sql_student)->queryRow();
if($studentCount){
$count=$studentCount['count'];
}
return $count;
}
//获取上一学期id
public function getPrevSemesterId(){
$nowSemester=$this->getCurrSemester();
$count=0;
//前一学期
$sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
$prevSemester=$this->sConn->createCommand($sql)->queryRow();
if($prevSemester){
return $prevSemester['semester_id'];
}
return 0;
}
//读取上学期班级
public function getClassesBySemesterId($semesterId){
$classes = array();
$condition = array();
$condition= array("semester_id = '{$semesterId}'");
$condition = $this->condition($condition);
$orderBy = $this->orderBy(array("class_id asc", "class_name asc"));
$classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
return $classes;
}
public function getPrevSemesterClassStudentsList($classId, $condition = array(), $pageSize = 9,$where=''){
$student_ids = array();
if(empty($where))
{
$rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
}else
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
if($accounts)
{
$studentIdOr=array();
foreach ($accounts as $v){
$studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
}
$condition= array(" (".implode(' OR ',$studentIdOr).") ");
$rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
}else
{
$rs["rs"] =array();
$rs['pager'] = (object)array();
$rs['pager']->rowsCount = 0;
}
}
if($rs["rs"]){
foreach($rs["rs"] as $key => $val){
$rs["rs"][$key]["username"] = "";
$rs["rs"][$key]["status"] = null;
}
$studentsIds = $this->grouping($rs["rs"], "student_id");
$studentsIds = implode("','", $studentsIds);
$studentsIds = "'{$studentsIds}'";
if($where)
{
$accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
if($accounts){
$b_student_status = array();
$b_student_card = array();
$b_student_username = array();
$b_school_student_card = array();
$b_zhixue_student_card = array();
foreach($accounts as $v)
{
$b_student_card[$v['student_id']] = $v['student_card'];
$b_student_status[$v['student_id']] = $v['status'];
$b_student_username[$v['student_id']] = $v['username'];
$b_school_student_card[$v['student_id']] = $v['school_student_card'];
$b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
}
foreach($rs["rs"] as $key => $val){
if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
$rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
$rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
$rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
if(isset($b_zhixue_student_card[$val["student_id"]]))
{
$rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
}
$rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
}else
{
unset($rs["rs"][$key]);
$rs['pager']->rowsCount = 0;
}
}
}else
{
foreach($rs["rs"] as $key => $val){
unset($rs["rs"][$key]);
}
$rs['pager']->rowsCount = 0;
}
}else
{
$accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
if($accounts){
$b_student_status = array();
$b_student_card = array();
$b_student_username = array();
$b_school_student_card = array();
$b_zhixue_student_card = array();
foreach($accounts as $v)
{
$b_student_card[$v['student_id']] = $v['student_card'];
$b_student_status[$v['student_id']] = $v['status'];
$b_student_username[$v['student_id']] = $v['username'];
$b_school_student_card[$v['student_id']] = $v['school_student_card'];
$b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
}
foreach($rs["rs"] as $key => $val){
if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
$rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
$rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
$rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
if(isset($b_zhixue_student_card[$val["student_id"]]))
{
$rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
}
$rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
}
}
}
}
}
return $rs;
}
public function getPrevSemesterClassRelation($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
$rs = $this->buildEmptyPagingStruct();
if($classId){
if(is_array($classId)){
$condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 2"), $condition);
}else{
$condition = Arr::merge(array("scr.class_id =".$classId, "scr.status = 2"), $condition);
}
$condition = $this->condition($condition);
$handle = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
order by serial_number asc
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
}
return $rs;
}
//读取导入学生模板
public function getImportStudentTemplate(){
$sql="select * from import_student_template ";
$Arr = $this->sConn->createCommand($sql)->queryRow();
$result=array();
if($Arr){
$result=$Arr['tpl_data'];
}
return $result;
}
//判断班级是否存在
public function classNameExists($className,$semesterIds,$class_type=1){
if(!$semesterIds || !$className)
return false;
if(is_array($semesterIds)){
$rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id in(".implode(',',$semesterIds).") and class_type='".$class_type."' and is_hide=0")->queryRow();
}else{
$rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id='".$semesterIds."' and class_type='".$class_type."' and is_hide=0 ")->queryRow();
}
if($rs){
return $rs['class_id'];
}
return false;
}
//根据班级,姓名 读取行政班学生数据
public function getStudentByNameClass($studentName,$semesterIds,$idNumber=false){
if(!$studentName || !$semesterIds){
return null;
}
$sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name FROM `student_info` si ";
$sql.="join student_class_relation scr on scr.student_id=si.student_id ";
$sql.="join class c on c.class_id = scr.class_id ";
$sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=1";
if(is_array($semesterIds)){
$sql.=" and semester_id in(".implode(',',$semesterIds).")";
}else{
$sql.=" and semester_id ='{$semesterIds}'";
}
if($idNumber){
$sql.=" and si.id_number='".$idNumber."'";
}
$student=$this->sConn->createCommand($sql)->queryAll();
return $student;
}
//核验身份证号是否存在
public function checkStudentIdNumber($id){
if(!$id) return false;
$rs = $this->sConn->createCommand("select exists(select student_id from student_info where id_number = '{$id}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
//读取匹配成功数据
public function getNormalStudent($condition,$pageSize){
$where='';
if($condition){
$where=" where ".implode(' and ',$condition);
}
$handle = $this->sConn->createCommand("select student_name,class_name,sex,modify_name,extend,id_number,student_card from import_student_temp {$where} order by id asc ")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
public function getSemesterClassesGraduation($semesterId,$Graduation=false)
{
$classes = array();
if ($semesterId) {
if ($Graduation) {
$classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and grade<>3 and grade<>9 and is_hide=0")->queryAll();
} else {
$classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
}
}
return $classes;
}
//根据班级读取分组
public function getTeamByClass($class_id,$get="team"){
if(!$class_id){
return null;
}
$sql="select * from class_team where class_id='".$class_id."'";
$teamData=$this->sConn->createCommand($sql)->queryAll();
$student_ids=array();
if($teamData){
foreach($teamData as $key=>$val){
$studentSql="select cst.student_id,cst.student_card,cst.real_name from class_student_team cst ";
$studentSql.="join student_class_relation scr on scr.student_id=cst.student_id and scr.class_id=cst.class_id ";
$studentSql.="where cst.team_id='".$val['team_id']."' and scr.status=0";
$student=$this->sConn->createCommand($studentSql)->queryAll();
if($student){
foreach($student as $v){
$student_ids[$v['student_id']]=$val['team_name'];
}
$teamData[$key]['student']=$student;
}else{
$teamData[$key]['student']=null;
}
}
}
if($get=='team'){
return $teamData;
}elseif($get=='student'){
return $student_ids;
}else{
return null;
}
}
//根据班级读取学生列表
public function getStudentByClassId($get_id){
if(!$get_id) return null;
$condition = array("scr.class_id = '{$get_id}'", "scr.status = 0");
$condition = $this->condition($condition);
$get_list = $this->sConn->createCommand("
select stu.*, scr.userno, scr.serial_number, c.class_name
from student_class_relation as scr
join student_info as stu on stu.student_id = scr.student_id
join class as c on c.class_id = scr.class_id
{$condition}
order by serial_number asc
")->queryAll();
$student_ids = array();
$result=array();
if($get_list)
{
foreach($get_list as $k=> $v)
{
$student_ids[$v['student_id']] = $v['student_id'];
$result[$v['student_id']]=$v;
}
if($student_ids){
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$student_ids);
$b_student_data = BusinessStudent::model()->findAll($criteria);
if($b_student_data)
{
foreach($b_student_data as $v)
{
$result[$v->student_id]['student_card'] = $v->student_card;
$result[$v->student_id]['school_student_card'] = (string)$v->school_student_card;
}
}
}
}
return $result;
}
//读取督学卡上传数量
public function getSuperviseStudentByExamId($examIds){
if(!$examIds) return 0;
$data=$this->sConn->createCommand("select count(*) as count from supervise_card where exam_id in(".implode(',',$examIds).")")->queryRow();
if($data){
return $data['count'];
}
return 0;
}
//判断智学网号是否存在
public function checkZhiXueNumber($id){
if(!$id) return false;
$rs = $this->conn->createCommand("select exists(select student_id from student where zhixue_student_card = '{$id}')")->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
//读取全部学生id
public function delStudentPaperByExamIds($examIds){
if(!$examIds || !is_array($examIds)) return false;
$rs = $this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
return $rs;
}
//删除student_paper_relation 同步删除student_paper_relation_property
public function delStudentPaperPropertyByExamIds($examIds,$studentIds){
if(!$examIds || !is_array($examIds)) return false;
if(!$studentIds || !is_array($studentIds)) return false;
$trans = $this->sConn->beginTransaction();
try{
$this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
//$this->sConn->createCommand("delete from student_paper_relation_property where exam_id in(".implode(',',$examIds).") and student_id in(".implode(',',$studentIds).") ")->execute();
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
return $rs;
}
//读取全部学生id
public function getStudentPaperByExamIds($examIds){
if(!$examIds || !is_array($examIds)) return false;
$rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_feedback=0 and is_del=0 ")->queryAll();
return $rs;
}
//读取一条学期数据,判断是否新学校
public function getOneSemester(){
$semester= $this->sConn->createCommand("select semester_id from semester limit 1")->queryRow();
return $semester;
}
//根据学校准考证号读取学生数据
public function getStudentInfoBySchoolCard($schoolStudentCard,$schoolId,$semesterId){
$students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
$result=array();
if($students){
foreach ($students as $key => $val){
$sql="SELECT si.student_id,si.realname,scr.class_id FROM `student_info` si ";
$sql.="join student_class_relation scr on scr.student_id=si.student_id ";
$sql.="join class c on c.class_id = scr.class_id ";
$sql.="where scr.status=0 and si.student_id='".$val['student_id']."' and c.semester_id='".$semesterId."' ";
$data=$this->sConn->createCommand($sql)->queryRow();
if($data){
$result[]=$data;
}
}
}
return $result;
}
//根据学校准考证号读取学生数据
public function getStudentIdBySchoolCard($schoolStudentCard,$schoolId){
$students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
return $students;
}
//获取教学进度
public function getTeachProgress($sql = '', $pageSize = 10){
$handle = $this->sConn->createCommand($sql)->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs["rs"]){
}
return $rs;
}
//根据班级id,统计学生数量
public function getStudentIdByClassId($classId){
if(!$classId) return 0;
$result=array();
$data=$this->sConn->createCommand("select `student_id` from student_class_relation where class_id='".$classId."' and `status`=0 ")->queryAll();
if($data){
foreach ($data as $val){
$result[]=$val['student_id'];
}
}
return $result;
}
//统计家长绑定数量
public function countBindStudentIds($studentIds,$schoolId){
if(!$studentIds || !is_array($studentIds)) return false;
if(!$schoolId) return false;
$sql="select count(parent_id) as count from wx_parent_student where student_id in(".implode(',',$studentIds).") and school_id ='".$schoolId."' ";
$sql="SELECT * from (SELECT parent_id,student_id,school_id from wx_parent_student where school_id='".$schoolId."' and student_id in(".implode(',',$studentIds).") ) t group by student_id;";
$data=Yii::app()->db251->createCommand($sql)->queryAll();
return count($data);
}
//根据学生id,读取家长信息
public function getParentByStudentIds($studentIds,$schoolId){
if(!$studentIds || !is_array($studentIds)) return false;
if(!$schoolId) return false;
$result=array();
$sql="select pt.student_id,pu.mobile,pt.create_time,pt.type,pt.parent_id,pt.bind_type from `wx_parent_student` pt join wx_parent_user pu on pt.parent_id=pu.user_id ";
$sql.=" where pt.school_id='".$schoolId."' and pt.student_id in (".implode(',',$studentIds).") order by `type` asc";
$data=Yii::app()->db251->createCommand($sql)->queryAll();
if($data){
foreach ($data as $val){
$val['mobile']=substr_replace($val['mobile'],'****',3,4);
$result[$val['student_id']][]=$val;
}
}
return $result;
}
//家长端解除绑定
public function UnbindZl($parentId,$studentId,$schoolId){
if(!$parentId || !$schoolId || !$studentId) return false;
$sql="delete from `wx_parent_student` where school_id='".$schoolId."' and parent_id='".$parentId."' and student_id='".$studentId."'";
if(Yii::app()->db251->createCommand($sql)->execute()){
return true;
}
return false;
}
//加载教师
public function loadTeacher($keyword,$subject){
$where=array();
$where[]="status=0 ";
if($subject){
$where[]=" subjects='{$subject}'";
}
if($keyword){
$where[]=" teacher_name like '".$keyword."%' ";
}
$sql="select teacher_id,teacher_name,subjects,posts from `teacher` where ".implode(' and ',$where);
$data=$this->sConn->createCommand($sql)->queryAll();
return $data;
}
//获取教师信息
public function getTeachersByTeacherIds($teachersIds){
if(!is_array($teachersIds) || !$teachersIds)
return array();
$teachersIds = "'".implode("','", $teachersIds)."'";
return $this->sConn->createCommand("select teacher_name,subjects,status from teacher where teacher_id in({$teachersIds})")->queryAll();
}
//读取学校报名数据
public function getSignUpBySchoolIdTaskId($schoolId,$taskId){
if(!$schoolId || !$taskId) return null;
return $this->conn->createCommand("select uesn_id,teacher_id,school_id,user_name,mobile from united_exam_signup where school_id='".$schoolId."' and tk_exam_id='".$taskId."'")->queryRow();
}
//报名
public function SignUp($data){
if(!$data || !is_array($data)) return false;
$sql="insert into united_exam_signup set ";
$setValue=array();
foreach ($data as $field => $value){
$setValue[]="`{$field}` = '".$value."'";
}
$sql.=implode(',',$setValue);
return $this->conn->createCommand($sql)->execute();
}
//退出 报名
public function SignOutBySchoolIdTaskId($schoolId,$taskId){
if(!$schoolId || !$taskId) return null;
return $this->conn->createCommand("delete from united_exam_signup where school_id='".$schoolId."' and tk_exam_id='".$taskId."'")->execute();
}
//根据考试id,读取联考数据
public function getUnitedByExamGroupId($exam_group_id){
if(!$exam_group_id) return false;
$sql="SELECT uea.paper_template_url,uea.answer_template_url,uea.apply_deadline,uea.branch FROM `united_exam` ue ";
$sql.=" join united_exam_apply uea on uea.task_exam_id=ue.tk_exam_id";
$sql.=" where ue.exam_group_id='".$exam_group_id."'";
return $this->conn->createCommand($sql)->queryRow();
}
//查询是否有联考数据
public function getUnitedList($apply_setting_type){
$time=time();
if($apply_setting_type==1){
$sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_deadline>'".$time."' and apply_setting_type=1";
}else{
$sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_deadline>'".$time."' ";
}
return $this->conn->createCommand($sql)->queryAll();
}
//查询联考
public function getUnitedByTaskExamId($task_exam_id){
if(!$task_exam_id) return false;
$sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where task_exam_id='".$task_exam_id."'";
return $this->conn->createCommand($sql)->queryRow();
}
//根据联考id,查询是否创建考试
public function getExamByTaskId($task_exam_id){
if(!$task_exam_id) return false;
$sql="select exam_group_id from united_exam where tk_exam_id='".$task_exam_id."' limit 1";
return $this->conn->createCommand($sql)->queryRow();
}
//查询是否有联考数据
public function getAllUnitedList($apply_setting_type){
$time=time();
if($apply_setting_type==1){
$sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_setting_type=1";
}else{
$sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply ";
}
return $this->conn->createCommand($sql)->queryAll();
}
//按学生准考证长度判断
public function getStudentByCardLength($studentIds,$cardLength){
if(!$studentIds || !is_array($studentIds)) return false;
if(!is_numeric($cardLength)) return false;
$sql="select student_id from student where student_id in(".implode(',',$studentIds).") and char_length(school_student_card)<>".$cardLength." limit 1";
return $this->conn->createCommand($sql)->queryRow();
}
public function UUID_SHORT($length = 20)
{
$query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
$result = $query['UUID_SHORT'];
if ($length AND is_int($length))
{
$result = substr($result, ($length * -1));
}
return $result;
}
public function getZlExamList($condition = array(), $orderBy = array("zl_create_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select c.class_name,e.zl_exam_id,eg.zl_exam_group_id,e.zl_class_id, eg.zl_exam_name as exam_name, e.zl_tpl_data, eg.zl_create_time, eg.zl_is_display
from class as c
join zl_exam as e on e.zl_class_id = c.class_id
JOIN zl_exam_group eg ON eg.zl_exam_group_id = e.zl_exam_group_id
{$condition}
group by e.zl_class_id, e.zl_exam_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
$ZlStudentExamRelation=new ZlStudentExamRelation();
$ZlStudentExamRs=new ZlStudentExamRs();
if($rs['rs']){
foreach($rs['rs'] as $key => $val){
$allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
$allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
$rs['rs'][$key]['is_uploaded_count']=$allStudentRs;
$rs['rs'][$key]['students_count']=$allStudent;
}
}
return $rs;
}
public function getEnglishWeek($condition = array(), $orderBy = array("ew.create_time desc"), $pageSize = 10){
$condition = Arr::merge($condition, array("ew.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select ew.week_id,ew.set_id,ew.`name`,c.class_name,ew.week_group_id,ews.is_new_version from english_week ew join english_week_setting ews on ews.id=ew.set_id join class c on ew.class_id = c.class_id
{$condition}
group by ew.week_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
foreach($rs['rs'] as $k=>$v){
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$week_id = $v['week_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_week_student where student_id > 0 and week_id = '{$week_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if($countArr){
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
}
$sql = "select week_download_time from english_week_student where student_id > 0 and week_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if($isDownArr){
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
}
}
}
return $rs;
}
public function getEnglishMonth($condition = array(), $orderBy = array("em.create_time desc"), $pageSize = 10){
$condition = Arr::merge($condition, array("em.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select em.month_id,em.`name`,c.class_name from english_month em join class c on em.class_id = c.class_id
{$condition}
group by em.month_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
foreach($rs['rs'] as $k=>$v){
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$month_id = $v['month_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_month_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_month_student where month_id = '{$month_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if($countArr){
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
}
$sql = "select download_time from english_month_student where month_id = '{$month_id}' and is_download = 1 order by download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if($isDownArr){
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['download_time'])?date("Y-m-d H:i",$isDownArr['download_time']):'';
}
}
}
return $rs;
}
//导出报告列表
public function getExportList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
$condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_topwb_html, e.name as exam_name, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,e.subject_id,
eg.is_third,c.grade,e.status
from exam as e
join class as c on e.class_id=c.class_id
JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
{$condition}
group by exam_group_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
return $rs;
}
//读取班级列表
public function getExportClassByExamGroupId($examGroupId){
if(!$examGroupId) return false;
$sql="SELECT e.is_topwb_pdf,e.class_id,class_name,e.exam_id,e.name,e.status,e.upload_status FROM `exam` e join class c on c.class_id=e.class_id where e.exam_group_id='{$examGroupId}'";
return $this->sConn->createCommand($sql)->queryAll();
}
//获取试卷大题关联表数据
public function getPaperLargeTopicsRecords($paperId){
$records = array();
if($paperId){
$records = $this->sConn->createCommand("select * from paper_topic_large where paper_id = '{$paperId}'")->queryAll();
}
return $records;
}
//读取走班设置
public function getClassShift($semester,$subjectId=0){
if(!$semester) return null;
if($subjectId){
$sql="select grade,subject_id,status from classified where semester_id='{$semester}' and subject_id='{$subjectId}'";
}else{
$sql="select grade,subject_id,status from classified where semester_id='{$semester}'";
}
return $this->sConn->createCommand($sql)->queryAll();
}
//查询走班设置
public function getClassifiedBySubject($grade,$subject,$semester){
if(!$semester || !$grade || !$subject) return null;
$sql="select grade,subject_id,status from classified where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
return $this->sConn->createCommand($sql)->queryRow();
}
//添加走班记录
public function insertClassified($data){
if(!$data || !is_array($data)) return false;
$sql="insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ";
$values=array();
foreach ($data as $val){
$values[]="('".$val['grade']."','".$val['subject_id']."','".$val['status']."','".$val['semester_id']."')";
}
$sql.=implode(',',$values);
return $this->sConn->createCommand($sql)->execute();
}
//更新记录状态
public function updateClassifiedBySubject($grade,$subject,$semester,$type){
if(!$semester || !$grade || !$subject || !$type) return false;
if($type=='enable'){
$sql="update classified set status=1 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
}elseif($type=='disable'){
$sql="update classified set status=0 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
}else{
return false;
}
return $this->sConn->createCommand($sql)->execute();
}
//根据年级查询学科
public function getSubjectByGrade($grade=0,$subjectId=0,$semester){
if(!$semester) return null;
if($grade){
if($subjectId){
$sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
}else{
$sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1";
}
}else{
if($subjectId){
$sql="select subject_id from classified where semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
}else{
$sql="select subject_id from classified where semester_id='{$semester}' and status=1 ";
}
}
return $this->sConn->createCommand($sql)->queryAll();
}
public function DelClassSubject($classId){
if(!$classId)
return false;
return $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
}
//读取班级科目
public function getSubjectByClass($classId,$type='Name'){
if(!$classId) return null;
$sql="select subject_id from class_subject_relation where class_id='{$classId}' ";
$data = $this->sConn->createCommand($sql)->queryAll();
$result=array();
if($data){
foreach ($data as $val){
if($val['subject_id']){
if($type=='Name'){
$result[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
}else{
$result[]=$val['subject_id'];
}
}
}
}
return $result;
}
//获取已走班学生
public function getStudentBySubjects($subjects,$grade,$semester){
if(!$subjects || !$semester || !$grade) return null;
$studentIds=array();
$classSql="SELECT c.class_id,c.class_name FROM `class` c ";
$classSql.=" left join class_subject_relation csr on csr.class_id= c.class_id ";
$classSql.=" where c.class_type=2 and csr.subject_id in(".implode(',',$subjects).") and semester_id='".$semester."' and grade='{$grade}'";
$classData=$this->sConn->createCommand($classSql)->queryAll();
$classIds=array();
if($classData){
foreach ($classData as $v){
$classIds[$v['class_id']]=$v['class_id'];
}
$sql="select student_id from student_class_relation where class_id in(".implode(',',$classIds).") and status=0";
$studentData=$this->sConn->createCommand($sql)->queryAll();
if($studentData){
foreach ($studentData as $val){
$studentIds[]=(string)$val['student_id'];
}
}
}
return $studentIds;
}
//根据姓名,查询未走班学生
public function getClassifiedStudentByName($realName,$subjects,$grade,$semester){
if(!$subjects || !$semester || !$grade || !$realName) return null;
$result=array();
$studentData=$this->sConn->createCommand("select student_id,realname from student_info where realname like '%".$realName."%'")->queryAll();
if($studentData){
foreach ($studentData as $val){
//查询班级
$classData=$this->sConn->createCommand("select class_id,class_type from student_class_relation where student_id ='".$val['student_id']."' and status=0 ")->queryAll();
if($classData){
$flag=true;
foreach ($classData as $v){
$classInfo= $this->getClassInfo($v['class_id']);
if(strcmp($semester,$classInfo['semester_id'])!=0){
$flag=false;
break;
}
if($grade!=$classInfo['grade']){
$flag=false;
break;
}
if($v['class_type']==2){
$classSubjects=$this->getSubjectByClass($v['class_id']);
foreach ($classSubjects as $subjectId =>$subjectName){
if(in_array($subjectId,$subjects)){
$flag=false;
break;
}
}
}
}
if($flag){
//查询系统准考证
$studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$val['student_id']}'")->queryRow();
if($studentInfo){
$val['realname']=$val['realname'].'('.$studentInfo['student_card'].')';
}
$result[]=$val;
}
}
}
}
return $result;
}
//查询指定班级内相似姓名学生
public function searchStudentByClassIdsStudentName($classIds,$studentName,$excludeStudentIds=array()){
if(!$classIds || !is_array($classIds) || !$studentName) return null;
$sql="select si.student_id,si.realname,scr.class_id from student_info si ";
$sql.=" join student_class_relation scr on scr.student_id=si.student_id ";
$sql.=" where scr.class_id in(".implode(',',$classIds).") and si.realname like '%".$studentName."%'";
$result=array();
$data=$this->sConn->createCommand($sql)->queryAll();
if($data){
foreach ($data as $val){
if($excludeStudentIds && in_array((string)$val['student_id'],$excludeStudentIds,true)){
continue;
}
$studentCard=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow();
if($studentCard){
$result[$val['student_id']]=array(
'realname'=>$val['realname'].'('.$studentCard['student_card'].')',
'class_id'=>$val['class_id'],
'student_id'=>$val['student_id']
);
}
}
}
return $result;
}
//添加走班学生
public function addClassifiedStudent($studentIds,$classId){
$subjects=$this->getSubjectByClass($classId); //本班级科目
$sql="replace into student_class_relation(`class_id`,`serial_number`,`student_id`,`status`,`update_time`,`operation`,`class_type`) values ";
$values=array();
$serialNumber=array();
foreach ($studentIds as $student_id){
//查询已有走班记录
$classRelation=$this->sConn->createCommand("select class_id from student_class_relation where student_id='{$student_id}' and status=0 and class_type=2")->queryAll();
if($classRelation){
foreach ($classRelation as $class_id){
$classSubject=$this->getSubjectByClass($class_id,'ID');
if(array_intersect($classSubject,$subjects)){
//已经有相关科目的走班记录
return -1;
}
}
}
//查询新班级最大序号
if(!isset($serialNumber[$classId])){
$newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$classId}' order by serial_number desc limit 1")->queryRow();
if($newClass ){
$serialNumber[$classId]=intval($newClass['serial_number'])+1;
}else{
$serialNumber[$classId]=1;
}
}else{
$serialNumber[$classId]++;
}
$values[]="('".$classId."','".$serialNumber[$classId]."','".$student_id."',0,'".time()."',2,2)";
}
if($values){
$sql.=implode(',',$values);
$rs=$this->sConn->createCommand($sql)->execute();
}
return $rs;
}
//教学班转班
public function copyClassified($toClassId,$studentData){
if(!$toClassId || !$studentData) return false;
//查询目标班级
$classSubjects=$this->getSubjectByClass($toClassId,'ARR');
//取消原所在班级关系
$updateOldClass=array();
$insertNewClass=array();
//查询新班级最大序号
$serialNumber=1;
$newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$toClassId}' order by serial_number desc limit 1")->queryRow();
if($newClass){
$serialNumber=intval($newClass['serial_number'])+1;
}
foreach ($studentData as $studentId => $classId){
$updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='{$classId}' and student_id='{$studentId}'";
//查询学生原科目
$sql="select c.class_id,csr.subject_id,scr.student_id,scr.`status` from class c";
$sql.=" join class_subject_relation csr on csr.class_id=c.class_id ";
$sql.="join student_class_relation scr on scr.class_id=c.class_id";
$sql.=" where scr.`status`=0 and scr.student_id='{$studentId}' and csr.subject_id in(".implode(',',$classSubjects).") and c.class_type=2 ";
$repeatSubjectData=$this->sConn->createCommand($sql)->queryAll();
//取消学生原科目与目标班科目冲突关系
if($repeatSubjectData){
foreach ($repeatSubjectData as $v){
$updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='".$v['class_id']."' and student_id='{$studentId}'";
}
}
//加入新班级
$insertNewClass[]="('".$toClassId."','".$studentId."',0,'".$serialNumber."',0,'".time()."',2,2)";
$serialNumber++;
}
$trans = $this->sConn->beginTransaction();
try{
if($updateOldClass){
foreach ($updateOldClass as $v){
$this->sConn->createCommand($v)->execute();
}
}
if($insertNewClass){
$insertSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
$insertSql.=implode(',',$insertNewClass);
$this->sConn->createCommand($insertSql)->execute();
}
$trans->commit();
$rs = true;
}
catch(Exception $e){
$trans->rollBack();
$rs = false;
}
return $rs;
}
//根据班级,姓名 读取教学班学生数据
public function getStudentByNameClassified($studentName,$semesterIds){
if(!$studentName || !$semesterIds){
return null;
}
$sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name,c.grade FROM `student_info` si ";
$sql.="join student_class_relation scr on scr.student_id=si.student_id ";
$sql.="join class c on c.class_id = scr.class_id ";
$sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=2";
if(is_array($semesterIds)){
$sql.=" and semester_id in(".implode(',',$semesterIds).")";
}else{
$sql.=" and semester_id ='{$semesterIds}'";
}
$student=$this->sConn->createCommand($sql)->queryAll();
return $student;
}
//根据科目读取教学班
public function getClassifiedBySubjectId($grade,$subjectId,$semesterId){
$sql="select c.class_id,c.class_name from class c ";
$sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
$sql.=" where c.grade='".$grade."' and csr.subject_id='".$subjectId."' and c.semester_id='".$semesterId."'";
return $this->sConn->createCommand($sql)->queryAll();
}
public function getClassIdBySubjectId($subjectId,$semesterId=0){
$sql="select c.class_id,c.class_name from class c ";
$sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
$sql.=" where csr.subject_id='".$subjectId."'";
if($semesterId){
$sql.=" and c.semester_id='".$semesterId."'";
}
$classIds=array();
$data=$this->sConn->createCommand($sql)->queryAll();
if($data){
foreach ($data as $val){
$classIds[]=$val['class_id'];
}
}
return $classIds;
}
//
public function checkClassifiedSubject($subjectId,$classId){
if(!$subjectId || !$classId) return false;
$sql="select exists(select subject_id from class_subject_relation where class_id='{$classId}' and subject_id='{$subjectId}')";
$rs = $this->sConn->createCommand($sql)->queryRow();
$rs = current($rs);
return $rs ? true : false;
}
public function getMathWeek($condition = array(), $orderBy = array("mrs.create_time desc"), $pageSize = 10){
$condition = Arr::merge($condition, array("mrs.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select mrs.mr_id,special_id,name,c.grade,c.class_id,c.class_name from math_review_setting mrs join class c on mrs.class_id= c.class_id
{$condition}
group by mrs.mr_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
foreach($rs['rs'] as $k=>$v){
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$mr_id=$v['mr_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_review_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from math_review_student where mr_id = '{$mr_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if($countArr){
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
}
$sql = "select review_download_time from math_review_student where mr_id = '{$mr_id}' and is_review_download = 1 order by review_download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if($isDownArr){
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['review_download_time'])?date("Y-m-d H:i",$isDownArr['review_download_time']):'';
}
}
}
return $rs;
}
public function getStudentByExamIds($examsIds,$page,$pageSize){
if(!$examsIds) return null;
$offset=($page-1)*$pageSize;
$query=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryRow();
$total=$query['count'];
$pages=ceil($total/$pageSize);
$sprs = $this->sConn->createCommand("select student_id,student_card from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 limit {$offset},{$pageSize} ")->queryAll();
$data['pageTotal']=$pages;
$data['page']=$page;
$data['list']=$sprs;
$data['pageSize']=$pageSize;
return $data;
}
public function getAllStudentByExamIds($examsIds){
if(!$examsIds) return null;
$sprs = $this->sConn->createCommand("select student_id,student_card from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryAll();
if($sprs){
foreach($sprs as $key =>$val){
$StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow();
if($StudentInfo){
$sprs[$key]['realname']=$StudentInfo['realname'];
}
}
}
return $sprs;
}
//读取在线答题卡
public function getAnswerSheetOnline($examGroupId){
if(!$examGroupId || !is_numeric($examGroupId)){
return null;
}
$rs=$this->sConn->createCommand("select online_card,is_qrcode_online,file_path,multiplex_id from `third_answer_sheet` where exam_group_id='{$examGroupId}' and online_card=1")->queryRow();
return $rs;
}
/**
* 英语外刊美文产品列表
*/
public function getEnglishReading($condition = array(), $orderBy = array("er.create_time desc"), $pageSize = 10){
$condition = Arr::merge($condition, array("er.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select er.week_id,er.reading_id,er.`name`,c.class_name,ers.type,ers.level,ers.recommend_mode,ers.product_type from english_reading er join class c on er.class_id = c.class_id join english_reading_setting ers on er.reading_id = ers.reading_id
{$condition}
group by er.week_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
foreach($rs['rs'] as $k=>$v){
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$rs['rs'][$k]['type_name'] = '';
$rs['rs'][$k]['recommend_mode_name'] = '';
$rs['rs'][$k]['product_type_name'] = '';
if($v['recommend_mode']==1){
$rs['rs'][$k]['recommend_mode_name']='经典模式';
}elseif($v['recommend_mode']==2){
$rs['rs'][$k]['recommend_mode_name']='智能推荐模式';
}
if($v['product_type']==1){
$rs['rs'][$k]['product_type_name']='基础宝';
}elseif($v['product_type']==2){
$rs['rs'][$k]['product_type_name']='外刊宝';
}elseif($v['product_type']==3){
$rs['rs'][$k]['product_type_name']='热点宝';
}
if($v['type'] == 1){
$rs['rs'][$k]['type_name'] = '(个性外刊)';
}else if($v['type'] == 2){
if($v['level'] == 1){
$rs['rs'][$k]['type_name'] = '(共性外刊-尖子班)';
}else if($v['level'] == 2){
$rs['rs'][$k]['type_name'] = '(共性外刊-培优班)';
}else if($v['level'] == 3){
$rs['rs'][$k]['type_name'] = '(共性外刊-提高班)';
}
}
$week_id = $v['week_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_reading_student where week_id = '{$week_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if($countArr){
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
}
$sql = "select week_download_time from english_reading_student where week_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if($isDownArr){
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
}
}
}
return $rs;
}
/**
* 假期报告列表
*/
public function getHolidayReport($condition = array(), $orderBy = array("hrs.create_time desc"), $pageSize = 10){
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select hrs.report_id,hrs.report_group_id,c.class_name,hrs.semester_id,s.semester_name,hrs.create_time,hrs.reset_times,hrs.class_id,hrs.reset_time from holiday_report_setting hrs join class c on hrs.class_id = c.class_id join semester s on s.semester_id= hrs.semester_id
{$condition}
group by hrs.report_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
$rs['is_all_pdf'] = 1;//是否全部生成pdf
$rs['create_time'] = 0;//创建时间
$create_time_arr = array();
$reset_time_arr = array();
foreach($rs['rs'] as $k=>$v){
$rs['create_time'] = $v['create_time']?$v['create_time']:0;
if($v['create_time']){
$create_time_arr[] = $v['create_time'];
}
if($v['reset_time']){
$reset_time_arr[] = $v['reset_time'];
}
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$rs['rs'][$k]['report_name'] = $v['class_name'].$v['semester_name'].'假期总结报告';
$rs['rs'][$k]['create_time'] = $v['reset_time']?date('Y-m-d',$v['reset_time']):date('Y-m-d',$v['create_time']);
$report_id = $v['report_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_report_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from holiday_report_student where report_id = '{$report_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if($countArr){
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
}
if($rs['is_all_pdf']){
if($rs['rs'][$k]['totalCount'] && $rs['rs'][$k]['pdfCount'] != $rs['rs'][$k]['totalCount']){
$rs['is_all_pdf'] = 0;
}else{
$rs['is_all_pdf'] = 1;
}
}
$sql = "select report_download_time from holiday_report_student where `report_id` = '{$report_id}' and is_report_download = 1 order by report_download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if($isDownArr){
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['report_download_time'])?date("Y-m-d H:i",$isDownArr['report_download_time']):'';
}
}
if($reset_time_arr){
$rs['create_time'] = max($reset_time_arr);
}else{
if($create_time_arr){
$rs['create_time'] = max($create_time_arr);
}
}
}
return $rs;
}
/**
* 根据条件获取班级
*/
public function getClassesByCondition($condition = array(),$orderBy = array()){
$classes = array();
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
return $classes;
}
/**
* 批量插入假期报告学生
*/
public function batchInsetHolidayReport($schoolId,$semesterId,$is_current_semester,$is_qxk_school=0){
$data = array();
$data['status'] = 0;
$data['error'] = '创建失败';
$new_report_ids = array();
$time = time();
// $classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1','is_hide=0'),array());
$classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1'),array());
$is_qxk_school = $is_qxk_school?1:0;
if(!$classIds){
$data['error'] = '暂无班级';
return $data;
}else{
$class_count = count($classIds);
$report_ids = getBatchUuid($schoolId,$class_count);
if($report_ids){
$report_ids_values = array_values($report_ids);
if(count($classIds) != count($report_ids)){
$data['error'] = '班级数量不符合';
return $data;
}
$i = 0;
$classIds = array_values($classIds);
foreach($classIds as $k=>$v){
if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
$new_report_ids[$v["class_id"]] = $report_ids_values[$i];
}
$i++;
}
}else{
$data['error'] = 'Id错误';
return $data;
}
}
if($is_current_semester){
$sql = "select c.class_name,c.class_id,scr.student_id from class c join student_class_relation scr on c.class_id = scr.class_id where c.semester_id = '{$semesterId}' and c.class_type = 1 and scr.`status`=0 group by scr.student_id";
}else{
$sql = "select class_name,class_id,student_id from (select c.class_name,c.class_id,scr.student_id,scr.update_time from class c join student_class_relation scr on c.class_id = scr.class_id where c.semester_id = '{$semesterId}' and c.class_type = 1 order BY scr.update_time desc) a GROUP BY student_id order by update_time desc";
}
$student_data = $this->sConn->createCommand($sql)->queryAll();
if(!$student_data){
$data['error'] = '暂无学生';
return $data;
}
$trans = $this->sConn->beginTransaction();
try{
$report_group_id = getUniqueId($schoolId);
$insert_values = "";
foreach($classIds as $class){
if(isset($new_report_ids[$class["class_id"]]) && $new_report_ids[$class["class_id"]]){
$report_id = $new_report_ids[$class["class_id"]];
$insert_values .= "(".$report_group_id.",".$report_id.",".$class["grade"].",".$class["semester_id"].",".$class["class_id"].",".$time.",".$is_qxk_school."),";
}
}
if($insert_values){
$insert_sql = "insert into holiday_report_setting (report_group_id,report_id,grade,semester_id,class_id,create_time,is_qxk_school) values".substr($insert_values,0,-1).';';
$this->sConn->createCommand($insert_sql)->execute();
}
if($student_data){
$count = count($student_data);//需要插入的学生总数
$limit = 3000;
$page = ceil($count/$limit);
for ($i=0; $i < $page; $i++) {
$values = '';
for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
if($j > $count - 1){
continue;
}
if(isset($new_report_ids[$student_data[$j]['class_id']]) && $new_report_ids[$student_data[$j]['class_id']]){
//拼接values的值
$report_id_2 = $new_report_ids[$student_data[$j]['class_id']];
$values .= '('.$report_id_2.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
}
}
$values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
$this->sConn->createCommand($values)->execute();
}
}
$trans->commit();
$data['status'] = 1;
$data['error'] = '创建成功';
}
catch(Exception $e){
$trans->rollBack();
$data['status'] = 0;
$data['error'] = '创建失败';
}
return $data;
}
/**
* 重置假期报告
*/
public function resetReport($reportId,$classId,$is_current_semester,$is_qxk_school=0){
$time = time();
$status = false;
$is_qxk_school = $is_qxk_school?1:0;
$trans = $this->sConn->beginTransaction();
try{
//删除学生数据
$sql = "delete from holiday_report_student where report_id = '{$reportId}'";
$this->sConn->createCommand($sql)->execute();
//学生数据
if($is_current_semester){
$sql = "select c.class_name,c.class_id,scr.student_id from class c join student_class_relation scr on c.class_id = scr.class_id where c.class_id = '{$classId}' and scr.`status`=0 group by scr.student_id" ;
}else{
$sql = "select student_id,update_time,class_id from (select student_id,update_time,class_id from student_class_relation where class_id = '{$classId}' order by student_id desc) a GROUP BY student_id order by update_time desc" ;
}
$student_data = $this->sConn->createCommand($sql)->queryAll();
if($student_data){
$count = count($student_data);//需要插入的学生总数
$limit = 3000;
$page = ceil($count/$limit);
for ($i=0; $i < $page; $i++) {
$values = '';
for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
if($j > $count - 1){
continue;
}
$values .= '('.$reportId.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
}
$values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
$this->sConn->createCommand($values)->execute();
}
}
//更新设置表
$sql = "update holiday_report_setting set is_all_html=90,school_group_id=0,reset_time={$time},reset_times= reset_times + 1,is_qxk_school={$is_qxk_school} where report_id = '{$reportId}'";
$this->sConn->createCommand($sql)->execute();
//重置后清除已存在的下载任务
$this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= {$reportId} and product_type=8 and class_id={$classId} ")->execute();
$trans->commit();
$status = true;
}
catch(Exception $e){
$trans->rollBack();
}
return $status;
}
/**
* 批量重置
*/
public function batchResetReport($semesterId,$is_qxk_school=0){
$time = time();
$status = false;
$report_ids = array();
$is_qxk_school = $is_qxk_school?1:0;
$sql = "select report_id from holiday_report_setting where semester_id='$semesterId'";
$report_data = $this->sConn->createCommand($sql)->queryAll();
if($report_data){
foreach($report_data as $k=>$v){
$report_ids[] = $v['report_id'];
}
}
$trans = $this->sConn->beginTransaction();
try{
if($report_ids){
$sql = "update holiday_report_setting set is_all_html=90,reset_time={$time},school_group_id=0,is_qxk_school={$is_qxk_school} where semester_id = '{$semesterId}'";
$this->sConn->createCommand($sql)->execute();
$sql = "update holiday_report_student set is_report_html=90 where report_id in (".implode(",",$report_ids).")";
$this->sConn->createCommand($sql)->execute();
//重置后清除已存在的下载任务
$task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
$this->conn->createCommand($task_sql)->execute();
}
$trans->commit();
$status = true;
}catch(Exception $e){
$trans->rollBack();
}
return $status;
}
/**
* 假期报告获取班级
*/
public function getClassesByHolidayReport($condition = array(),$orderBy = array())
{
$classes = array();
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$classes = $this->sConn->createCommand("select c.* from class c right join holiday_report_setting hrs on c.class_id=hrs.class_id{$condition} group by class_id{$orderBy}")->queryAll();
return $classes;
}
//查询考试上传学生数量
public function getStudentCountByExamGroupId($examGroupId,$hasFeedback=0){
if(!$examGroupId){
return null;
}
$result=array();
$result['total']=0; //总数
$result['is_feedback']=0; // 已扫描
$result['is_del']=0; //缺考
$result['abnormal']=0; //异常总量
$result['complete']=0; //完成数量
$result['surplus']=0; //剩余量
$sql="select exam_id from exam where exam_group_id='{$examGroupId}'";
$data=$this->sConn->createCommand($sql)->queryAll();
$examIds=array();
if($data){
if($hasFeedback){
foreach ($data as $val){
$examIds[]=$val['exam_id'];
}
$studentSql="select student_id,is_feedback,is_del from student_paper_relation where exam_id in(".implode(',',$examIds).")";
$studentData=$this->sConn->createCommand($studentSql)->queryAll();
if($studentData){
foreach ($studentData as $val){
if($val['is_feedback']==1){
$result['is_feedback']++;
}
if($val['is_del']==1){
$result['is_del']++;
}else{
$result['total']++;
}
}
}
}
$abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}'";
$abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
if($abnormalData){
$result['abnormal']=count($abnormalData);
foreach ($abnormalData as $val){
if($val['status']==0){
$result['surplus']++;
}
if($val['status']==1){
$result['complete']++;
}
}
}
}
return $result;
}
//查询待处理数据
public function getSurplusDataByExamGroupId($examGroupId){
$abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}' and status=0";
$abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
$result=array();
if($abnormalData){
foreach ($abnormalData as $val){
$result[]=array(
'task_id'=>$val['task_id'],
'student'=>$val['data']
);
}
}
return $result;
}
/**
* 好题本
*/
public function getHtb($condition = array(), $orderBy = array("htb.create_time desc"), $pageSize = 10)
{
$condition = Arr::merge($condition, array("htb.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select htb.htb_id,htb.name,c.grade,c.class_id,c.class_name,htb.is_new_version,htb.htb_group_id from math_htb_setting htb join class c on htb.class_id= c.class_id
{$condition}
group by htb.htb_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if ($rs['rs']) {
foreach ($rs['rs'] as $k => $v) {
$rs['rs'][$k]['totalCount'] = 0;
$rs['rs'][$k]['pdfCount'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['downTime'] = '';
$htb_id = $v['htb_id'];
$sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_htb_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from math_htb_student where htb_id = '{$htb_id}'";
$countArr = $this->sConn->createCommand($sql)->queryRow();
if ($countArr) {
$rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
$rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
}
$sql = "select htb_download_time from math_htb_student where htb_id = '{$htb_id}' and is_htb_download = 1 order by htb_download_time desc limit 1";
$isDownArr = $this->sConn->createCommand($sql)->queryRow();
if ($isDownArr) {
$rs['rs'][$k]['isDown'] = 1;
$rs['rs'][$k]['downTime'] = isset($isDownArr['htb_download_time']) ? date("Y-m-d H:i", $isDownArr['htb_download_time']) : '';
}
}
}
return $rs;
}
/**
* 全学科获取题型(topic表中题型)
*/
public function getPaperTopicsRecordsByTopic($paperId)
{
$records = array();
if ($paperId) {
$sql = "select ptr.*,t.bank_type from paper_topic_relation ptr join topic t on ptr.topic_id = t.topic_id where ptr.paper_id = '{$paperId}' order by ptr.`order` asc";
$records = $this->sConn->createCommand($sql)->queryAll();
}
return $records;
}
//读取最新版本软件
public function getNewVersionBySoftwareId($id){
$sql="select file_url from client_software_version where software_id = '{$id}' order by id desc";
$data=$this->conn->createCommand($sql)->queryRow();
if($data){
return $data['file_url'];
}else{
return '';
}
}
//统计考试班级和人数
public function countExamsAndStudents($examGroupId){
if(!$examGroupId) return false;
$result=array();
$sql="select exam_id from exam where exam_group_id='".$examGroupId."'";
$exam=$this->sConn->createCommand($sql)->queryAll();
if($exam){
$examIds=array();
foreach ($exam as $val){
$examIds[]=$val['exam_id'];
}
$result['classes']=count($examIds);
$student=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0")->queryRow();
if($student){
$result['students']=$student['count'];
}
}
return $result;
}
//根据班级名称读取班级
public function getClassInfoByClassName($className,$semesterIds){
if(!$semesterIds || !$className)
return false;
$rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id='".$semesterIds."' and is_hide=0 ")->queryRow();
if($rs){
return $rs['class_id'];
}
return false;
}
//查询指定科目班级执教教师
public function getTeacherByClassSubject($classId,$subjectId){
if(!$classId || !$subjectId) return false;
if(in_array($subjectId,array(3,6,51))) $subjectId=3;
$rs = $this->sConn->createCommand("SELECT t.teacher_id,class_id FROM `teacher_class_relation` tcr join teacher t on t.teacher_id=tcr.teacher_id where t.subjects='{$subjectId}' and tcr.class_id='{$classId}';")->queryRow();
return $rs;
}
public function getExamName($examId)
{
if (!$examId) return null;
$sql = "select name from exam where exam_id ='{$examId}'";
$exam = $this->sConn->createCommand($sql)->queryRow();
if ($exam) {
return $exam['name'];
}
return null;
}
//读取未上传考生
public function getNoUploadStudentByGroupId($examGroupId,$page,$del=-1,$classId=0){
if(!$examGroupId) return false;
if(!$page) $page=1;
$result=array();
$pageLimit=10;
if($classId){
$sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."' and class_id='{$classId}'";
}else{
$sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."'";
}
$exam=$this->sConn->createCommand($sql)->queryAll();
if($exam) {
$examIds = array();
$classIds=array();
$className=array();
foreach ($exam as $val) {
$examIds[] = $val['exam_id'];
$classIds[]=$val['class_id'];
}
$classSql="select class_name,class_id from class where class_id in(".implode(',',$classIds).")";
$classes=$this->sConn->createCommand($classSql)->queryAll();
foreach ($classes as $val){
$className[(string)$val['class_id']]=$val['class_name'];
}
$condition=array();
$condition[]=" is_feedback=0 ";
$condition[]=" exam_id in(".implode(',',$examIds).") ";
$offset=($page-1)*$pageLimit;
if($del==-1) {
//全部
}elseif($del==0){
$condition[]=" is_del=0 ";
}elseif($del==1){
$condition[]=" is_del=1 ";
}
$countData=$this->sConn->createCommand("select count(*) as count from student_paper_relation where ".implode(' AND ',$condition))->queryRow();
$result['total']=$countData['count'];
$result['totalPage']=ceil($result['total']/$pageLimit);
$result['page']=$page;
$result['pageLimit']=$pageLimit;
$sql="select student_id,class_id,student_card,school_student_card,is_del,exam_id from student_paper_relation where ".implode(' AND ',$condition)." order by student_id limit {$offset},{$pageLimit} ";
$studentData=$this->sConn->createCommand($sql)->queryAll();
if($studentData){
foreach ($studentData as $key =>$val){
if(isset($className[(string)$val['class_id']])){
$studentData[$key]['class_name']= $className[(string)$val['class_id']];
}
$studentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
if($studentInfo){
$studentData[$key]['student_name']= $studentInfo['realname'];
}
if($val['is_del']==1){
$studentData[$key]['status']= '缺考';
}else{
$studentData[$key]['status']= '未上传';
}
}
}
$result['list']=$studentData;
$result['classes']=$className;
}
return $result;
}
//删除学生
public function delStudentPaperByStudentAndExamIds($studentsIds,$examId)
{
$trans = $this->sConn->beginTransaction();
try {
if(is_array($examId)){
$this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and exam_id in(".implode(',',$examId).") and is_feedback=0")->execute();
$this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id in(".implode(',',$examId).") ")->execute();
}else{
$this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and exam_id ='{$examId}' and is_feedback=0")->execute();
$this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id ='{$examId}' ")->execute();
}
$trans->commit();
return true;
} catch (Exception $e) {
$trans->rollBack();
return false;
}
}
//下载学生
public function getExcelStudent($studentIds,$examGroupId)
{
$array=array();
$sql = "select exam_id,class_id from exam where exam_group_id='" . $examGroupId . "'";
$exam = $this->sConn->createCommand($sql)->queryAll();
if ($exam) {
$examIds = array();
$classIds = array();
$className = array();
foreach ($exam as $val) {
$examIds[] = $val['exam_id'];
$classIds[] = $val['class_id'];
}
$classSql = "select class_name,class_id from class where class_id in(" . implode(',', $classIds) . ")";
$classes = $this->sConn->createCommand($classSql)->queryAll();
foreach ($classes as $val) {
$className[(string)$val['class_id']] = $val['class_name'];
}
$condition = array();
// $condition[] = " student_id in(" . implode(',', $studentIds) . ") ";
$condition[] = " exam_id in(" . implode(',', $examIds) . ") ";
$condition[] = " is_feedback=0 ";
$sql = "select student_id,class_id,student_card,school_student_card,is_del,exam_id from student_paper_relation where " . implode(' AND ', $condition) . " ";
$studentData = $this->sConn->createCommand($sql)->queryAll();
if ($studentData) {
foreach ($studentData as $key => $val) {
$studentInfo = $this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
$status='未上传';
if ($val['is_del'] == 1) {
$status = '缺考';
}
$array[]=array(
$studentInfo['realname'],
$val['student_card'],
$val['school_student_card'],
$className[(string)$val['class_id']],
$status
);
}
}
$title = array("姓名", "系统准考证号", "学校准考证号", "班级", "状态");
array_unshift($array, $title);
}
return $array;
}
public function getCyletStudentByExamIds($examIds,$classIds){
if(!$examIds || !is_array($examIds)) return null;
$studentIds=array();
$sql="select exam_group_id from exam where exam_id in(".implode(',',$examIds).")";
$data = $this->sConn->createCommand($sql)->queryAll();
foreach ($data as $datum){
$examGroupId[]=$datum['exam_group_id'];
$sql="select exam_id from exam where exam_group_id in(".implode(',',$examGroupId).") and class_id in(".implode(',',$classIds).")";
$studentExam=$this->sConn->createCommand($sql)->queryAll();
$studentExamIds=array();
foreach ($studentExam as $val){
$studentExamIds[]=$val['exam_id'];
}
if($studentExamIds){
$sql="select student_id from student_paper_relation where exam_id in(".implode(',',$studentExamIds).") and is_del=0";
$studentRs=$this->sConn->createCommand($sql)->queryAll();
if($studentRs){
foreach ($studentRs as $val){
$studentIds[(string)$val['student_id']]=$val['student_id'];
}
}
}
}
return array_values($studentIds);
}
//删除学生
public function delStudentPaperByExamGroupId($examId)
{
$trans = $this->sConn->beginTransaction();
try {
if(is_array($examId)){
$this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examId).") and is_feedback=0")->execute();
$this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id in(".implode(',',$examId).") ")->execute();
}else{
$this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id ='{$examId}' and is_feedback=0")->execute();
$this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id ='{$examId}' ")->execute();
}
$trans->commit();
return true;
} catch (Exception $e) {
$trans->rollBack();
return false;
}
}
//读取未上传考生
public function getStudentPaperByExamGroupId($examId)
{
if (is_array($examId)) {
$rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(" . implode(',', $examId) . ") and is_feedback=0")->queryAll();
} else {
$rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id ='{$examId}' and is_feedback=0")->queryAll();
}
$result = array();
if ($rs) {
foreach ($rs as $val) {
$result[(string)$val['student_id']] = $val['student_id'];
}
}
return $result;
}
//发送标注到教师端
public function sendLabelToTeacher($examGroupId,$type){
if(!$examGroupId || !in_array($type,array('send','cancel','resend')) ){
return false;
}
$examData=$this->getExamsIdsByExamGroupId($examGroupId);
if(!$examData){
return false;
}
$examIds=array();
foreach ($examData as $val){
$examIds[]=$val;
}
if($type=='send' || $type=='resend'){
$rs=$this->sConn->createCommand("update paper set is_labelled=2,labelled_type=2,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
}else{
$rs=$this->sConn->createCommand("update paper set is_labelled=4,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
}
return $rs;
}
//更新发送类型
public function updatePaperLabelledType($examGroupId,$type){
if(!$examGroupId ){
return false;
}
$examData=$this->getExamsIdsByExamGroupId($examGroupId);
if(!$examData){
return false;
}
$examIds=array();
foreach ($examData as $val){
$examIds[]=$val;
}
$rs=$this->sConn->createCommand("update paper set labelled_type='{$type}',send_labelled_time='".time()."',is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute();
return $rs;
}
/**
* 教师假期报告列表
*/
public function getTeacherHolidayReport($condition = array(), $orderBy = array("htrs.create_time desc"), $pageSize = 10){
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select htrs.report_id,htrs.report_group_id,htrs.semester_id,htrs.teacher_id,htrs.create_time,t.teacher_name from holiday_teacher_report_setting htrs join teacher t on t.teacher_id = htrs.teacher_id
{$condition}
group by htrs.report_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if($rs['rs']){
$rs['is_all_pdf'] = 1;//是否全部生成pdf
$rs['create_time'] = 0;//创建时间
$create_time_arr = array();
$reset_time_arr = array();
foreach($rs['rs'] as $k=>$v){
$teacher_id = $v['teacher_id'];
$report_id = $v['report_id'];
$semester_id = $v['semester_id'];
//获取教师登陆账号
$sql = "select phone_number from xb_teacher where teacher_id = '{$teacher_id}'";
$teacher_data = $this->conn->createCommand($sql)->queryRow();
if($teacher_data){
$rs['rs'][$k]['phone_number'] = $teacher_data['phone_number'];
}else{
$rs['rs'][$k]['phone_number'] = "";
}
//获取生成数量
$sql = "select count(1) count,report_pdf_time from holiday_report_teacher where report_id = '{$report_id}' and is_report_pdf = 1";
$pdf_data = $this->sConn->createCommand($sql)->queryRow();
if($pdf_data){
$rs['rs'][$k]['pdf_count'] = $pdf_data['count'];
$rs['rs'][$k]['build_time'] = $pdf_data['report_pdf_time']?date("Y-m-d",$pdf_data['report_pdf_time']):'';
}else{
$rs['rs'][$k]['pdf_count'] = 0;
$rs['rs'][$k]['build_time'] = '';
}
//获取执教班级
$sql = "select c.class_id,c.class_name from teacher_class_relation tcr join class c on tcr.class_id = c.class_id where tcr.semester_id ='{$semester_id}' and tcr.teacher_id = '{$teacher_id}'";
$class_data = $this->sConn->createCommand($sql)->queryAll();
if($class_data){
$class_name = "";
foreach($class_data as $v){
$class_name .= $v['class_name'].'、';
}
// $rs['rs'][$k]['class_name'] = mb_substr($class_name, 0, -1);
$rs['rs'][$k]['class_name'] = rtrim($class_name, "、");
}else{
$rs['rs'][$k]['class_name'] = '';
}
}
}
return $rs;
}
/**
* 批量插入教师假期报告
* @type 1-没数据全部插入 2-有教师补数据
*/
public function batchInsetHolidayTeacherReport($schoolId,$semesterId,$type){
$data = array();
$data['status'] = 0;
$data['error'] = '创建失败';
$teacher_ids = array();
$new_report_ids = array();
$insert_values_1 = "";//sql1
$insert_values_2 = "";//sql2
$time = time();
//获取教师执教班级信息
if($type == 1){
$sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
. "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
. "join class c on tcr.class_id = c.class_id "
. "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") GROUP BY t.teacher_id,c.grade";
}else if($type == 2){
$sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
. "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
. "join class c on tcr.class_id = c.class_id "
. "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") and t.teacher_id not in "
. "(select teacher_id from holiday_teacher_report_setting where semester_id = '{$semesterId}') "
. "GROUP BY t.teacher_id,c.grade";
}
$teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
if(!$teacher_class_data){
$data['error'] = '暂无教师班级信息';
return $data;
}else{
$report_group_id = getUniqueId($schoolId);
foreach($teacher_class_data as $k=>$v){
$teacher_ids[] = $v['teacher_id'];
}
$teacher_ids = array_unique($teacher_ids);
$teacher_count = count($teacher_ids);
$report_ids = getBatchUuid($schoolId,$teacher_count);
if($report_ids){
$report_ids_values = array_values($report_ids);
if(count($teacher_ids) != count($report_ids)){
$data['error'] = '教师数量不符合';
return $data;
}
$i = 0;
$teacher_ids = array_values($teacher_ids);
foreach($teacher_ids as $k=>$v){
if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
$new_report_ids[$v] = $report_ids_values[$i];
$report_id = $new_report_ids[$v];
$insert_values_1 .= "(".$report_group_id.",".$report_id.",".$v.",".$semesterId.",".$time."),";
$i++;
}
}
//组装插入sql语句
foreach($teacher_class_data as $v){
if(isset($new_report_ids[$v['teacher_id']]) && $new_report_ids[$v['teacher_id']]){
$report_id = $new_report_ids[$v['teacher_id']];
$insert_values_2 .= "(".$report_id.",".$v['teacher_id'].",".$v['grade']."),";
}
}
}
}
$trans = $this->sConn->beginTransaction();
try{
if($insert_values_1){
$insert_sql = "insert into holiday_teacher_report_setting (report_group_id,report_id,teacher_id,semester_id,create_time) values".substr($insert_values_1,0,-1).';';
$this->sConn->createCommand($insert_sql)->execute();
}
if($insert_values_2){
$insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values_2,0,-1).';';
$this->sConn->createCommand($insert_sql)->execute();
}
$trans->commit();
$data['status'] = 1;
$data['error'] = '创建成功';
}
catch(Exception $e){
$trans->rollBack();
$data['status'] = 0;
$data['error'] = '创建失败';
}
return $data;
}
/**
* 重置教师假期报告(单个)
*/
public function resetTeacherReport($reportId,$teacherId,$semesterId){
$time = time();
$status = false;
$insert_values = '';
$trans = $this->sConn->beginTransaction();
try{
//删除学生数据
$sql = "delete from holiday_report_teacher where report_id = '{$reportId}'";
$this->sConn->createCommand($sql)->execute();
//执教班级数据
$sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
. "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
. "join class c on tcr.class_id = c.class_id "
. "where t.teacher_id = '{$teacherId}' and tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") GROUP BY t.teacher_id,c.grade";
$teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
if($teacher_class_data){
foreach($teacher_class_data as $k=>$v){
$insert_values .= "(".$reportId.",".$v['teacher_id'].",".$v['grade']."),";
}
if($insert_values){
$insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values,0,-1).';';
$this->sConn->createCommand($insert_sql)->execute();
}
}
//更新设置表
$sql = "update holiday_teacher_report_setting set is_all_html=90,school_group_id=0,reset_time={$time},reset_times= reset_times + 1 where report_id = '{$reportId}'";
$this->sConn->createCommand($sql)->execute();
//重置后清除已存在的下载任务
// $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= {$reportId} and product_type=8 and class_id={$classId} ")->execute();
$trans->commit();
$status = true;
}
catch(Exception $e){
$trans->rollBack();
}
return $status;
}
/**
* 批量重置教师假期报告
*/
public function batchResetTeacherReport($semesterId)
{
$time = time();
$status = false;
$report_ids = array();
$sql = "select report_id from holiday_teacher_report_setting where semester_id='$semesterId'";
$report_data = $this->sConn->createCommand($sql)->queryAll();
if ($report_data) {
foreach ($report_data as $k => $v) {
$report_ids[] = $v['report_id'];
}
}
$trans = $this->sConn->beginTransaction();
try {
if ($report_ids) {
$sql = "update holiday_teacher_report_setting set is_all_html=90,reset_time={$time},school_group_id=0 where semester_id = '{$semesterId}'";
$this->sConn->createCommand($sql)->execute();
$sql = "update holiday_report_teacher set is_report_html=90,is_report_pdf=0 where report_id in (" . implode(",", $report_ids) . ")";
$this->sConn->createCommand($sql)->execute();
//重置后清除已存在的下载任务
// $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
// $this->conn->createCommand()->execute($task_sql);
}
$trans->commit();
$status = true;
} catch (Exception $e) {
$trans->rollBack();
}
return $status;
}
//读取全部考生
public function getAllStudentPaperByExamIds($examIds,$studentIds=array())
{
if($studentIds){
$rs = $this->sConn->createCommand("select spr.class_id,si.student_id,si.realname,student_card,school_student_card,is_feedback,exam_id,paper_id,student_img_paper from student_paper_relation spr left join student_info si on spr.student_id=si.student_id where exam_id in(" . implode(',', $examIds) . ") and spr.student_id in(".implode(',',$studentIds).") and is_del=0")->queryAll();
}else{
$rs = $this->sConn->createCommand("select spr.class_id,si.student_id,si.realname,student_card,school_student_card,is_feedback,exam_id,paper_id,student_img_paper from student_paper_relation spr left join student_info si on spr.student_id=si.student_id where exam_id in(" . implode(',', $examIds) . ") and is_del=0")->queryAll();
}
return $rs;
}
//读取走班,根据学生id
public function getAllClassByStudentId($studentIds){
$sql="select c.class_id,c.class_name,student_id from student_class_relation scr
join class c on c.class_id=scr.class_id
where status=0 and c.class_type=2 and student_id in(".implode(',',$studentIds).")";
$rs = $this->sConn->createCommand($sql)->queryAll();
$result=array();
if($rs){
foreach ($rs as $v){
$subject=$this->sConn->createCommand("select subject_id from class_subject_relation where class_id='{$v['class_id']}'")->queryAll();
$subjectList=array();
if($subject){
foreach ($subject as $item){
$subjectList[]=Yii::app()->params['subjectId'][$item['subject_id']];
}
}
$result[$v['student_id']][]=array(
'class_name'=>$v['class_name'],
'subject'=>$subjectList
);
}
}
return $result;
}
//全学科题库获取题型
public function getAllSubjectTopicType($subject){
$topics = array();
$array = array();
$array['subjectId']=$subject;
$url= $this->apiUrl.'/all_subject/topic_type';
$topics = Curl::post($url, $array);
$topics=json_decode($topics,true);
if(isset($topics['status']) && $topics['status']==1 ){
return $topics['data'];
}
return null;
}
//全学科题库获取题型
public function getAllSubjectBasicType(){
$topics = array();
$array = array();
$url= $this->apiUrl.'/all_subject/basic_topic_type';
$topics = Curl::post($url, $array);
$topics=json_decode($topics,true);
if(isset($topics['status']) && $topics['status']==1 ){
return $topics['data'];
}
return null;
}
//查询上传答案图片学生
public function getUpAnswerStudent($paperId,$studentIds=array(),$count=true){
if(!$paperId ){
return null;
}
if($count){
if($studentIds){
$sql="select count(DISTINCT student_id) as count from student_paper_topic_rs where paper_id='{$paperId}' and student_id in(".implode(',',$studentIds).") and answer_url<>'' ";
}else{
$sql="select count(DISTINCT student_id) as count from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
}
$rs=$this->sConn->createCommand($sql)->queryRow();
return $rs['count'];
}else{
if($studentIds){
$sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and student_id in(".implode(',',$studentIds).") and answer_url<>'' ";
}else{
$sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
}
$rs=$this->sConn->createCommand($sql)->queryALl();
return $rs;
}
}
//读取在线答题卡
public function getAnswerSheet($examGroupId){
if(!$examGroupId || !is_numeric($examGroupId)){
return null;
}
$sql="select online_card,tas.is_qrcode_online,tas.file_path,tas.multiplex_id,ocm.marking_papers,ocm.paper_size from `third_answer_sheet` tas ";
$sql.=" left join online_card_multiplex ocm on ocm.multiplex_id=tas.multiplex_id ";
$sql.=" where tas.exam_group_id='{$examGroupId}' ";
$rs=$this->sConn->createCommand($sql)->queryRow();
return $rs;
}
//更新标注期望完成时间
public function updateEstimateTime($examGroupId,$tplData)
{
if (!$examGroupId || !is_numeric($examGroupId) || !$tplData) {
return null;
}
$rs = $this->sConn->createCommand("update exam set tpl_data='" . $tplData . "' where exam_group_id='{$examGroupId}'")->execute();
return $rs;
}
//保存考试全流程节点时间
public function saveExamProcess($examGroupId,$actionType,$actionTime,$examId=0,$classId=0){
if(!$examGroupId || !is_numeric($examGroupId)) return false;
$model=new SExamProcess();
$model->exam_group_id=$examGroupId;
$model->exam_id=$examId;
$model->class_id=$classId;
$model->action_type=$actionType;
$model->action_time=$actionTime;
if($model->save()){
return true;
}
return false;
}
// 批量保存考试全流程节点时间
public function saveExamProcessBatch($examGroupId,$batchData){
if(!$examGroupId || !is_numeric($examGroupId)) return false;
$sql="insert into exam_process(`exam_group_id`,`exam_id`,`class_id`,`action_type`,`action_time`) values ";
$valueData=array();
foreach ($batchData as $val){
if(!in_array($val['action_type'],array(1,2,3,4,5,6,7,8,9,10,11,12))){
return false;
}
if(!isset($val['exam_id']) || !isset($val['class_id']) || !isset($val['action_type']) || !isset($val['action_time'])){
return false;
}
$valueData[]="('{$examGroupId}','{$val['exam_id']}','{$val['class_id']}','{$val['action_type']}','{$val['action_time']}')";
}
if($this->sConn->createCommand($sql.implode(',',$valueData))->execute()){
return true;
}
return false;
}
//删除指定班级未上传考生
public function delStudentPaperByExamId($examIds){
if(!$examIds || !is_array($examIds)) return false;
$sql="update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0";
if($this->sConn->createCommand($sql)->execute()){
return true;
}
return false;
}
//查询导出考试数据白名单
public function getExportExamWhiteList($schoolId){
if(!$schoolId || !is_numeric($schoolId)) return false;
$sql="select id from school_download_exam_whitelist where school_id='".$schoolId."'";
$rs= $this->conn->createCommand($sql)->queryRow();
if($rs){
return 1;
}else{
return 0;
}
}
//读取在线答题卡
public function getOnlineCardMultiplex($multiplexId){
if(!$multiplexId){
return null;
}
$sql="select marking_papers from `online_card_multiplex` ";
$sql.=" where multiplex_id='{$multiplexId}' ";
$rs=$this->sConn->createCommand($sql)->queryRow();
return $rs;
}
//获取全学科试卷结构
public function getQxkPaperTopics($topicIds){
$rs = http('/qxk/topic/list','POST',$this->schoolId,array('topicList'=>array_values($topicIds)),'cgi');
$rs=json_decode($rs,true);
if(isset($rs['errCode']) && $rs['errCode']=='00'){
return $rs['data'];
}
return null;
}
//读取学校省份
public function getProvince($pid){
if(!$pid) return null;
$sql="select region_name from region where region_id='{$pid}'";
$data=$this->conn->createCommand($sql)->queryRow();
if($data){
return $data['region_name'];
}
return null;
}
//读取在线答题卡
public function getOnlineCardMultiplexByGroupId($groupId){
if(!$groupId){
return null;
}
$sql="select marking_papers,is_download,exam_group_id from `online_card_multiplex` ";
$sql.=" where exam_group_id='{$groupId}' ";
$rs=$this->sConn->createCommand($sql)->queryRow();
return $rs;
}
/**
* 校本纠错本
*/
public function getCorrect($condition = array(), $orderBy = array("create_time desc"), $pageSize = 10)
{
$condition = Arr::merge($condition, array("gps.semester_id = '{$this->semester["id"]}'"));
$condition = $this->condition($condition);
$orderBy = $this->orderBy($orderBy);
$handle = $this->sConn->createCommand("
select gps.gp_group_id,`name`,gps.grade,gps.create_time,status,setting,gp.reset_times from general_product_setting gps LEFT JOIN general_product gp on gp.gp_group_id=gps.gp_group_id
{$condition}
group by gps.gp_group_id
{$orderBy}
")->query();
$rs = $this->paging($this->sConn, $handle, $pageSize);
if ($rs['rs']) {
foreach ($rs['rs'] as $k => $v) {
$rs['rs'][$k]['totalClass'] = 0;
$rs['rs'][$k]['isDown'] = 0;
$rs['rs'][$k]['isCreate'] = 0;
$rs['rs'][$k]['isAllCreate'] = 1;
$rs['rs'][$k]['abnormal']='';
$rs['rs'][$k]['examGroupIdCount']=0;
$sql="select gp_id from general_product where gp_group_id='{$v['gp_group_id']}'";
$classCount=$this->sConn->createCommand($sql)->queryAll();
$rs['rs'][$k]['totalClass'] = count($classCount);
$gpIds=array();
foreach ($classCount as $item){
$gpIds[]=$item['gp_id'];
}
$sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=1 ";
$isCreate=$this->sConn->createCommand($sql)->queryRow();
if($isCreate){
$rs['rs'][$k]['isCreate'] = 1;
}
$sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=0";
$noCreate=$this->sConn->createCommand($sql)->queryRow();
if($noCreate){
$rs['rs'][$k]['isAllCreate'] = 0;
}
$sql="select distinct gp_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_download=1";
$isDownArr = $this->sConn->createCommand($sql)->queryAll();
$rs['rs'][$k]['isDown'] = count($isDownArr);
//查询异常
$setting=json_decode($v['setting'],1);
if(isset($setting['no_exam_class']) && $setting['no_exam_class']){
$names=array();
$classNames=$this->sConn->createCommand("select class_name from class where class_id in(".implode(',',$setting['no_exam_class']).")")->queryAll();
foreach ($classNames as $cname){
$names[]=$cname['class_name'];
}
$rs['rs'][$k]['abnormal'] = implode(',',$names);
}
if(isset($setting['exam_group_ids'])){
$rs['rs'][$k]['examGroupIdCount']=count($setting['exam_group_ids']);
}
}
}
return $rs;
}
}