123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <?php
- class UploadController extends Controller
- {
- public function actionIndex()
- {
- $data = array();
- $teachers = $this->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('<br/>', $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('<br/>', $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('<br/>', $error)));exit;
- } else {
- echo json_encode($result);exit;
- }
- }
-
- /**
- * 替换图片目录
- *
- * @author CeeFee
- */
- private function replaceImgSrc($content, $url)
- {
- $regex = "/<img[^>]*[\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, '<img src="'. Yii::app()->params['mt_prefix'] . $v.'" class="gsImgLatex mathType"/>', $content);
- }
- }
-
- // 题目中公式处理(二)
- if (preg_match_all('/\\\\\[.*?\\\\\]/', $content, $temp)) {
- $arr = array_unique($temp[0]);
-
- foreach ($arr as $v) {
- $content = str_replace($v, '<img src="'. Yii::app()->params['mt_prefix']. $v .'" class="gsImgLatex mathType"/>', $content);
- }
- }
-
- // 题目中公式处理(三)
- if (preg_match_all('/\$.*?\$/', $content, $temp)) {
- $arr = array_unique($temp[0]);
-
- foreach ($arr as $v) {
- $content = str_replace($v, '<img src="'. Yii::app()->params['mt_prefix']. $v .'" class="gsImgLatex mathType"/>', $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, '<img src="'. $this->mtUrl. $v .'" class="gsImgLatex mathType"/>', $content);
- $content = str_replace($v, '<img src="'. Yii::app()->params['mt_prefix']. $v .'" class="gsImgLatex mathType"/>', $content);
- }
- }
- }
-
- /*
- // 空格替换
- if (preg_match_all('/_{5,}/', $content, $temp)) {
- foreach ($temp[0] as $k => $v) {
- $content = preg_replace('/_{5,}/', '<img class="tiankong" src="/images/list_'. ($k + 1) .'.png">', $content, 1);
- }
- }
- */
-
- return $content;
- }
- }
|