NewSchoolManager.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: 刘红伟
  5. * QQ : 454303753
  6. * Date: 2017/11/22 0022
  7. * Time: 下午 17:43
  8. */
  9. defined("ROLE_USER") or define("ROLE_USER", 1);
  10. defined("ROLE_SU") or define("ROLE_SU", 2);
  11. class NewSchoolManager extends SchoolManager{
  12. function __construct($coachId, $role = ROLE_USER,$pad='')
  13. {
  14. parent::__construct($coachId,$role,$pad);
  15. }
  16. /**
  17. * 设置试卷纸张类型
  18. * @param array $rs
  19. */
  20. private function setPaperSize(&$rs)
  21. {
  22. if($rs["rs"])
  23. {
  24. foreach($rs["rs"] as $key => $val)
  25. {
  26. $tplData = json_decode($val["tpl_data"], true);
  27. $paperSize = null;
  28. $examDate = null;
  29. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  30. switch($val["tpl_index"]){
  31. case "12":
  32. $paperSize = "A3";
  33. break;
  34. case "13":
  35. $paperSize = "A4";
  36. break;
  37. case "14":
  38. $paperSize = "8K";
  39. break;
  40. case "15":
  41. $paperSize = "16K";
  42. break;
  43. case "2012":
  44. $paperSize = "A3";
  45. break;
  46. case "2013":
  47. $paperSize = "A4";
  48. break;
  49. case "2014":
  50. $paperSize = "8K";
  51. break;
  52. case "2015":
  53. $paperSize = "16K";
  54. break;
  55. case "2016":
  56. $paperSize = "A3";
  57. break;
  58. case "2017":
  59. $paperSize = "A4";
  60. break;
  61. case "2018":
  62. $paperSize = "8K";
  63. break;
  64. case "2019":
  65. $paperSize = "16K";
  66. break;
  67. case "1012":
  68. $paperSize = "A3";
  69. break;
  70. case "1013":
  71. $paperSize = "A4";
  72. break;
  73. case "1014":
  74. $paperSize = "8K";
  75. break;
  76. case "1015":
  77. $paperSize = "16K";
  78. break;
  79. case "1016":
  80. $paperSize = "A3";
  81. break;
  82. case "1017":
  83. $paperSize = "A4";
  84. break;
  85. case "1018":
  86. $paperSize = "8K";
  87. break;
  88. case "1019":
  89. $paperSize = "16K";
  90. break;
  91. case "3012":
  92. $paperSize = "A3";
  93. break;
  94. case "3013":
  95. $paperSize = "A4";
  96. break;
  97. case "3014":
  98. $paperSize = "8K";
  99. break;
  100. case "3015":
  101. $paperSize = "16K";
  102. break;
  103. case "3016":
  104. $paperSize = "A3";
  105. break;
  106. case "3017":
  107. $paperSize = "A4";
  108. break;
  109. case "3018":
  110. $paperSize = "8K";
  111. break;
  112. case "3019":
  113. $paperSize = "16K";
  114. break;
  115. case "4012":
  116. $paperSize = "A3";
  117. break;
  118. case "4013":
  119. $paperSize = "A4";
  120. break;
  121. case "4014":
  122. $paperSize = "8K";
  123. break;
  124. case "4015":
  125. $paperSize = "16K";
  126. break;
  127. case "4016":
  128. $paperSize = "A3";
  129. break;
  130. case "4017":
  131. $paperSize = "A4";
  132. break;
  133. case "4018":
  134. $paperSize = "8K";
  135. break;
  136. case "4019":
  137. $paperSize = "16K";
  138. break;
  139. case "2011":
  140. $paperSize = "A3";
  141. break;
  142. case "3011":
  143. $paperSize = "A3";
  144. break;
  145. }
  146. }
  147. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  148. switch($val["tpl_index"]){
  149. case "16":
  150. $paperSize = "A3";
  151. break;
  152. case "3016":
  153. $paperSize = "A3";
  154. break;
  155. case "3017":
  156. $paperSize = "A4";
  157. break;
  158. case "3013":
  159. $paperSize = "A4";
  160. break;
  161. case "3007":
  162. $paperSize = "A3";
  163. break;
  164. case "17":
  165. $paperSize = "A4";
  166. break;
  167. case "18":
  168. $paperSize = "8K";
  169. break;
  170. case "19":
  171. $paperSize = "16K";
  172. break;
  173. case "2011":
  174. $paperSize = "A3";
  175. break;
  176. case "3011":
  177. $paperSize = "A3";
  178. break;
  179. }
  180. }
  181. if($tplData){
  182. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  183. $examDate = $val["create_time"];
  184. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  185. $paperSize = "A3";
  186. }
  187. if($examDate === null)
  188. {
  189. $examDate = $val["create_time"];
  190. }
  191. if($paperSize === null)
  192. {
  193. $paperSize = "A4";
  194. }
  195. $rs["rs"][$key]["exam_time"] = $examDate;
  196. $rs["rs"][$key]["paper_size"] = $paperSize;
  197. }
  198. }
  199. return $rs;
  200. }
  201. /**
  202. * 获取考试列表
  203. * 用于:
  204. *
  205. * @param $condition
  206. * @param $orderBy
  207. * @param int $pageSize 页码
  208. */
  209. public function getPrintGroupList($condition,$orderBy,$pageSize=9)
  210. {
  211. $condition = $this->condition($condition);
  212. $orderBy = $this->orderBy($orderBy);
  213. $handle = $this->sConn->createCommand("
  214. select e.name as print_name,e.class_id,e.is_display,e.subject_id,e.exam_id,e.create_time,e.tpl_data,e.tpl_index,e.is_new,e.school_card_status,e.school_card_length,eg.*,c.grade
  215. from exam_group as eg
  216. left JOIN exam e ON eg.exam_group_id = e.exam_group_id and e.semester_id = {$this->semester['id']} and eg.status >0
  217. left join class c on c.class_id=e.class_id
  218. {$condition}
  219. group by eg.exam_group_id
  220. {$orderBy}
  221. ")->query();
  222. //进行分页
  223. $rs = $this->paging($this->sConn, $handle, $pageSize);
  224. if($rs["rs"] && !empty($rs["rs"]))
  225. {
  226. return $this->setPaperSize($rs);
  227. }
  228. return $rs;
  229. }
  230. /**
  231. * 获取考试列表
  232. * 用于:个性化学习宝督学列表
  233. *
  234. * @param $condition
  235. * @param $orderBy
  236. * @param int $pageSize 页码
  237. */
  238. public function getExamGroupList($condition,$orderBy,$pageSize=9)
  239. {
  240. $condition = $this->condition($condition);
  241. $orderBy = $this->orderBy($orderBy);
  242. $sql = "select e.name,e.exam_id,e.create_time,e.tpl_data,count(e.class_id) as class_count,e.exam_group_id,eg.mark_type,e.subject_id
  243. from exam_group as eg
  244. JOIN exam e ON eg.exam_group_id = e.exam_group_id and e.semester_id = {$this->semester['id']} and eg.status >0
  245. join student_improve_score_plan_topics spt on e.exam_id=spt.plan_id
  246. {$condition}
  247. group by eg.exam_group_id
  248. {$orderBy}";
  249. $handle = $this->sConn->createCommand($sql)->query();
  250. //进行分页
  251. $rs = $this->paging($this->sConn, $handle, $pageSize);
  252. return $rs;
  253. }
  254. /**
  255. * 获取已发送标注或未发送标注的考试
  256. * @param $is_labelled
  257. *
  258. * @return array|\CDbDataReader
  259. */
  260. public function getPaerLabelledByExam($is_labelled)
  261. {
  262. return $this->sConn->createCommand("select p.exam_id from paper as p JOIN exam as e on p.exam_id = e.exam_id where e.semester_id = {$this->semester['id']} and p.is_labelled = ".$is_labelled)->queryAll();
  263. }
  264. /**
  265. * 通过班级ID,获取考试信息
  266. * @param $class_ids
  267. *r
  268. * @return array|\CDbDataReader
  269. */
  270. public function getClassIdByExam($class_ids)
  271. {
  272. if(!$class_ids || !is_array($class_ids))
  273. {
  274. return array();
  275. }
  276. return $this->sConn->createCommand("select exam_id from exam where class_id in (".implode(',',$class_ids).")")->queryAll();
  277. }
  278. /**
  279. * 通过学期获取班级信息
  280. * @param $semesterId
  281. *
  282. * @return array|\CDbDataReader
  283. */
  284. public function getSemesterClasses($semesterId){
  285. $classes = array();
  286. if($semesterId){
  287. $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
  288. }
  289. return $classes;
  290. }
  291. /**
  292. *
  293. * 班级考试列表
  294. * @param $condition
  295. * @param $orderBy
  296. * @param int $pageSize
  297. *
  298. * @return array
  299. */
  300. public function getExamsByExamGroupIdList($condition,$orderBy,$pageSize=9)
  301. {
  302. $condition = $this->condition($condition);
  303. $orderBy = $this->orderBy($orderBy);
  304. $handle = $this->sConn->createCommand("
  305. select exam_id,exam_group_id,semester_id,upload_status,`status`,class_id,subject_id,`name` as print_name,`type`,create_time,tpl_index,tpl_data,is_new
  306. from exam
  307. {$condition}
  308. {$orderBy}
  309. ")->query();
  310. //进行分页
  311. $rs = $this->paging($this->sConn, $handle, $pageSize);
  312. if($rs["rs"] && !empty($rs["rs"]))
  313. {
  314. return $this->setPaperSize($rs);
  315. }
  316. return $rs;
  317. }
  318. /**
  319. * 通过老师名称获取老师与班级信息
  320. */
  321. public function getTeachersByteacherName($teacher_name){
  322. $teachers = array();
  323. $class_ids = array();
  324. if($teacher_name){
  325. $teacher_data = $this->sConn->createCommand(" select * from teacher where teacher_name LIKE '%{$teacher_name}%' ")->queryAll();
  326. if($teacher_data)
  327. {
  328. foreach($teacher_data as $v)
  329. {
  330. $teachers[$v['teacher_id']] = $v['teacher_id'];
  331. }
  332. if($teachers)
  333. {
  334. $class_teacher_data = $this->sConn->createCommand(" select * from teacher_class_relation where teacher_id in(".implode(',',$teachers).") and semester_id =".$this->semester['id']." ")->queryAll();
  335. if($class_teacher_data)
  336. {
  337. foreach($class_teacher_data as $v)
  338. {
  339. $class_ids[$v['class_id']] = $v['class_id'];
  340. }
  341. }
  342. }
  343. }
  344. }
  345. return $class_ids;
  346. }
  347. public function getBacklogList($condition = array(), $orderBy = array("add_time desc")){
  348. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  349. $condition = $this->condition($condition);
  350. $orderBy = $this->orderBy($orderBy);
  351. $handle =$this->sConn->createCommand("
  352. SELECT
  353. c.class_name,
  354. e.`name` AS exam_name,
  355. e.subject_id,
  356. e.class_id,
  357. e.exam_id,
  358. e.is_backlog,
  359. e.create_time,
  360. e.is_display,
  361. eg.upload_status AS group_upload_status,
  362. eg.mark_type,
  363. eg.mark_status,
  364. e.exam_group_id,
  365. eg.import_score_type
  366. FROM exam AS e
  367. JOIN `class` AS c ON e.class_id = c.class_id
  368. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  369. {$condition}
  370. GROUP BY
  371. e.class_id,
  372. e.exam_id
  373. {$orderBy}");
  374. $rs = $handle->queryAll();
  375. $examsIds = $this->grouping($rs, "exam_id", true);
  376. $studentAnswerImg=array();
  377. if($examsIds){
  378. $paperData=$this->sConn->createCommand("select paper_id,exam_id from paper where exam_id in(".implode(',',$examsIds).")")->queryAll();
  379. $studentAnswerImg=array();
  380. $paperIds=array();
  381. $paperIdToExamId=array();
  382. if($paperData){
  383. foreach ($paperData as $val){
  384. $paperIds[]=$val['paper_id'];
  385. $paperIdToExamId[$val['paper_id']]=$val['exam_id'];
  386. }
  387. $sql="select count(DISTINCT student_id) as count,paper_id from student_paper_topic_rs where paper_id in(".implode(',',$paperIds).") and answer_url<>'' group by paper_id ";
  388. $rsImg=$this->sConn->createCommand($sql)->queryAll();
  389. if($rsImg){
  390. foreach ($rsImg as $val){
  391. $studentAnswerImg[$paperIdToExamId[$val['paper_id']]]=$val['count'];
  392. }
  393. }
  394. }
  395. }
  396. $examsIds = "'".implode("','", $examsIds)."'";
  397. $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();
  398. $examsSprs = array();
  399. foreach($sprs as $key => $val){
  400. if(!isset($examsSprs[$val["exam_id"]]))
  401. $examsSprs[$val["exam_id"]] = array();
  402. $examsSprs[$val["exam_id"]][] = $val;
  403. }
  404. $examsStudentsCount = array();
  405. foreach($examsSprs as $examId => $sprs){
  406. $examsStudentsCount[$examId] = array(
  407. "is_complete_count" => 0,
  408. "is_uploaded_count" => 0,
  409. "wrongbook_pdf_count" => 0,
  410. "wbisp_pdf_count" => 0,
  411. "isp_pdf_count" => 0,
  412. );
  413. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  414. foreach($sprs as $k => $v){
  415. if($v["is_complete"] == 1)
  416. {
  417. $examsStudentsCount[$examId]["is_complete_count"]++;
  418. }
  419. if($v["is_feedback"] == 1)
  420. {
  421. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  422. }
  423. if($v["is_wrongbook_pdf"] == 1)
  424. {
  425. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  426. }
  427. if($v["is_wbisp_pdf"] == 1)
  428. {
  429. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  430. }
  431. if($v["is_isp_pdf"] == 1)
  432. {
  433. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  434. }
  435. }
  436. }
  437. foreach($rs as $key => $val){
  438. if(isset($examsStudentsCount[$val["exam_id"]])){
  439. $rs[$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  440. $rs[$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  441. $rs[$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  442. $rs[$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  443. $rs[$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  444. $rs[$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  445. }
  446. else{
  447. $rs[$key]["students_count"] = 0;
  448. $rs[$key]["is_complete_count"] = 0;
  449. $rs[$key]["is_uploaded_count"] = 0;
  450. $rs[$key]["wrongbook_pdf_count"] = 0;
  451. $rs[$key]["wbisp_pdf_count"] = 0;
  452. $rs[$key]["isp_pdf_count"] = 0;
  453. }
  454. $rs[$key]["student_answer_img"] =0;
  455. if($val['import_score_type']){
  456. //导入成绩,判断图片
  457. if(isset($studentAnswerImg[$val['exam_id']])){
  458. $rs[$key]["student_answer_img"] =$studentAnswerImg[$val['exam_id']] ;
  459. }
  460. }
  461. }
  462. return $rs;
  463. }
  464. public function getPaperIdsByExamIds($examIds){
  465. $paperIds = array();
  466. if($examIds && is_array($examIds)){
  467. $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")";
  468. $paperInfo = $this->sConn->createCommand($sql)->queryAll();
  469. if($paperInfo){
  470. foreach ($paperInfo as $item) {
  471. $paperIds[] = $item['paper_id'];
  472. }
  473. }
  474. }
  475. return $paperIds;
  476. }
  477. public function getTopicWord($examGroupId){
  478. }
  479. }