schoolManager->getTeachers(array("add_time DESC"));
$teacherNames = array();
$_teachers = array();
if ($teachers) {
foreach ($teachers as $v) {
if($this->subjectId==3)
{
if($v['subjects']==$this->subjectId || $v['subjects']==6)
{
$teacherNames[$v['teacher_id']] = $v['teacher_name'];
$_teachers[] = $v;
}
}else
{
if($v['subjects']==$this->subjectId)
{
$teacherNames[$v['teacher_id']] = $v['teacher_name'];
$_teachers[] = $v;
}
}
}
}
$data['teachers'] = $_teachers;
$data['teacherNames'] = $teacherNames;
$papers = $this->schoolManager->getUploadPaperList(array("add_time DESC", "id DESC"),$this->subjectId);
$data['papers'] = $papers["rs"];
$data['pages'] = $papers["pager"];
$data['pageTotal'] = $papers["pager"]->rowsCount;
//$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
//["subject"] = $subject_exam_data;
$this->render('index', $data);
}
public function actionView()
{
$data = array();
$error = array();
$id = (int)Yii::app()->request->getParam('id');
if ($id <= 0) {
$error[] = '请指定参数 Id';
} else {
$detail = $this->sConn->createCommand("SELECT * FROM upload_paper WHERE id={$id}")->query()->read();
if (! $detail) {
$error[] = '未找到数据';
} elseif (empty($detail['json_data'])) {
$error[] = 'JSON 数据未记录';
} else {
$zipPath = $detail['zip_path'];
$jsonObj = json_decode($detail['json_data'], true);
$apiUrl = Yii::app()->params['api_host'];
$zipDir = pathinfo($zipPath, PATHINFO_DIRNAME);
$zipName = pathinfo($zipPath, PATHINFO_FILENAME);
$imgUrl = $apiUrl .'/'. $zipDir .'/'. $zipName .'/result/';
$data['examName'] = $jsonObj['formtitle'];
$items = array(
1 => array(),
5 => array(),
7 => array()
);
foreach ((array)$jsonObj['items'] as $key => $val) {
$typeName = $val['type'];
switch ($typeName) {
case '选择':
$typeId = 1;
break;
case '填空':
$typeId = 5;
break;
case '简答':
$typeId = 7;
break;
default:
continue;
}
$arr = array();
$arr['title'] = $this->replaceImgSrc($this->replaceMathtex($val['stem']), $imgUrl);
$arr['analysis'] = isset($val['analysis']) ? $this->replaceImgSrc($this->replaceMathtex($val['analysis']), $imgUrl) : '';
$arr['key'] = $this->replaceImgSrc($this->replaceMathtex($val['key']), $imgUrl);
if ($typeId == 1) {
$arr['options'] = array();
$answer = strtoupper(trim(strip_tags($val['key'])));
$answerNum = letterToNum($answer);
foreach ($val['options'] as $optionIndex => $optionContent) {
$arr['options'][] = array(
'content' => $this->replaceImgSrc($this->replaceMathtex($optionContent), $imgUrl),
'correct' => ($answerNum == $optionIndex ? 1 : 0),
);
}
if ($val['optionlines'] == 1) {
$arr['listType'] = 1;
} elseif ($val['optionlines'] == 2) {
$arr['listType'] = 2;
} else {
$arr['listType'] = 0;
}
}
$items[$typeId][] = $arr;
}
$data['items'] = $items;
}
}
if ($error) {
Yii::app()->jump->error(implode('
', $error));
} else {
$this->render('view', $data);
}
}
public function actionAjaxConfirm()
{
$error = array();
$result = array();
if (! Yii::app()->request->isPostRequest or ! Yii::app()->request->isAjaxRequest) {
$error[] = '错误的来源!';
} else {
$id = (int)Yii::app()->request->getPost('id');
$detail = $this->sConn->createCommand("SELECT * FROM upload_paper WHERE id={$id}")->query()->read();
if (! $detail) {
$error[] = '未找到数据';
} elseif ($detail['status'] != 0) {
$error[] = '已经确认过了';
} elseif (empty($detail['json_data'])) {
$error[] = 'JSON 数据未记录';
} else {
$confirm = $this->apiPost('upload_paper/confirm', array(
'id' => $id,
'schoolId' => $this->schoolId,
'semesterId' => $this->semesterId,
), 1);
if (! $confirm) {
$error[] = 'Api system error';
} elseif (! isset($confirm->success) or !isset($confirm->message)) {
$error[] = 'Api response error';
} elseif ($confirm->success != 1) {
$error[] = $confirm->message;
}
}
}
header('Content-Type: application/json');
if ($error) {
echo json_encode(array('status' => 0, 'error'=> implode('
', $error)));exit;
} else {
echo json_encode(array('status' => 1, 'error'=> ''));exit;
}
}
public function actionAjaxGetTeacherSubjects()
{
$error = array();
$result = array();
if (! Yii::app()->request->isPostRequest or ! Yii::app()->request->isAjaxRequest) {
$error[] = '错误的来源!';
} else {
$teacherId = Yii::app()->request->getPost('teacherId');
if (! $teacherId or ! is_numeric($teacherId)) {
$error[] = 'teacherId 错误';
} else {
/*
$subjects = $this->sConn->createCommand("SELECT DISTINCT csr.subject_id FROM teacher_class_relation tcr JOIN class_subject_relation csr ON csr.class_id = tcr.class_id WHERE tcr.teacher_id = '{$teacherId}' AND tcr.semester_id = '{$this->semesterId}'")->query()->readAll();
$subjectIds = array();
$subjectNames = array();
if ($subjects) {
foreach ($subjects as $v) {
$subjectIds[] = $v['subject_id'];
}
$subjects = $this->apiPost('/subject/batch', array('subjectIds' => $subjectIds));
if (! $subjects) {
$error[] = 'Brain subject/batch error';
} elseif (isset($subjects->error)) {
$error[] = $subjects->error;
} else {
$result = $subjects;
}
}
*/
/* $subjectIds = array(3, 6);
$subjects = $this->apiPost('/subject/batch', array('subjectIds' => $subjectIds));
if (! $subjects) {
$error[] = 'Brain subject/batch error';
} elseif (isset($subjects->error)) {
$error[] = $subjects->error;
} else {
$result = $subjects;
}*/
$teacherSubjectIds=$this->mathSubjectId;
$teacherSubjectNames = array(3 => '高一高二专用', 6 => '高三专用',51=>'新高一高二');
$teacherSubjectMaterialIds = array();
$teacherSubjectMaterialNames = array();
foreach ($teacherSubjectIds as $teacherSubjectId) {
$teacherSubjectMaterialIds[$teacherSubjectId] = array();
$teacherSubjectMaterialNames[$teacherSubjectId] = array();
$textbookTree = $this->apiPost('/textbook/tree', array(
'subjectId' => $teacherSubjectId,
'depth' => 3
));
if (! $textbookTree) {
$error[] = 'Brain textbook/tree error';
} elseif (isset($textbookTree->error)) {
$error[] = $textbookTree->error;
} else {
foreach ($textbookTree as $textbook) {
if (isset($textbook->modules)) {
foreach ($textbook->modules as $module) {
if (isset($module->chapters)) {
$teacherSubjectMaterialIds[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_id;
$teacherSubjectMaterialNames[$teacherSubjectId][$textbook->textbook_id] = $textbook->textbook_name;
}
}
}
}
}
}
$result['teacherSubject'] = array(
array('subject_id'=>3,'subject_name'=>'高一高二专用'),
array('subject_id'=>6,'subject_name'=>'高三专用'),
array('subject_id'=>51,'subject_name'=>'新高一高二'),
);
$result['SubjectMaterialNames'] = $teacherSubjectMaterialNames;
$result['SubjectMaterialIds'] = $teacherSubjectMaterialIds;
}
}
header('Content-Type: application/json');
if ($error) {
echo json_encode(array('status' => 0, 'error'=> implode('
', $error)));exit;
} else {
echo json_encode($result);exit;
}
}
/**
* 替换图片目录
*
* @author CeeFee
*/
private function replaceImgSrc($content, $url)
{
$regex = "/]*[\s]+src[\s]*=[\s]*(([\"](files\/image\d+\.(png|gif|jpg|jpeg|bmp))([^\"]*)[\"])|([\'](files\/image\d+\.(png|gif|jpg|jpeg|bmp))([^\']*)[\'])|(files\/image\d+\.(png|gif|jpg|jpeg|bmp))([^\s]*))[^>]*>/si";
if (preg_match_all($regex, $content, $temp)) {
$imgArr = array();
$tmpArr = array_merge($temp[3], $temp[7], $temp[10]);
foreach ($tmpArr as $v) {
if (! empty($v) and ! in_array($v, $imgArr)) {
$imgArr[] = $v;
}
}
unset($tmpArr);
foreach ($imgArr as $v) {
$content = str_replace($v, $url. $v, $content);
}
}
return $content;
}
/**
* 替换 mathtex
*
* @author CeeFee
*/
private function replaceMathtex($content)
{
// 题目中公式处理(一)
/*if (preg_match_all('/\\\\\(.*?\\\\\)/', $content, $temp)) {
$arr = array_unique($temp[0]);
foreach ($arr as $v) {
$content = str_replace($v, '', $content);
}
}
// 题目中公式处理(二)
if (preg_match_all('/\\\\\[.*?\\\\\]/', $content, $temp)) {
$arr = array_unique($temp[0]);
foreach ($arr as $v) {
$content = str_replace($v, '', $content);
}
}
// 题目中公式处理(三)
if (preg_match_all('/\$.*?\$/', $content, $temp)) {
$arr = array_unique($temp[0]);
foreach ($arr as $v) {
$content = str_replace($v, '', $content);
}
}*/
if (preg_match_all("/(data-latex=\\\"([^\"]*\\\"))|(\\$.*?\\$)|(\\\\\\[.*?\\\\\\])/", $content, $temp)) {
$arr = array_unique($temp[0]);
foreach ($arr as $v) {
if (substr($v, 0, 10) !== "data-latex") {
//$content = str_replace($v, '', $content);
$content = str_replace($v, '', $content);
}
}
}
/*
// 空格替换
if (preg_match_all('/_{5,}/', $content, $temp)) {
foreach ($temp[0] as $k => $v) {
$content = preg_replace('/_{5,}/', '', $content, 1);
}
}
*/
return $content;
}
}