STopic.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class STopic extends MyActiveRecord
  7. {
  8. public static function model($className = __CLASS__)
  9. {
  10. return parent::model($className);
  11. }
  12. public function tableName()
  13. {
  14. return 'topic';
  15. }
  16. public function getSchTopicDetail($topic_id_arr, $isReplaceBlank = FALSE)
  17. {
  18. $result = array();
  19. $condition = "topic_id IN (". implode(',', $topic_id_arr) .")";
  20. $criteria = new CDbCriteria();
  21. $criteria->join = 'JOIN teacher c ON t.updater_id = c.teacher_id JOIN teacher u ON t.updater_id = u.teacher_id';
  22. $criteria->select = 't.*, c.teacher_name AS creator_name, u.teacher_name AS updater_name';
  23. $criteria->addCondition($condition);
  24. $criteria->order = 'update_time DESC';
  25. $topicIds = array();
  26. $topicQuery = getAttributes($this->findAll($criteria));
  27. if ($topicQuery)
  28. {
  29. foreach ($topicQuery AS $k => $v)
  30. {
  31. $topicIds[] = $v['topic_id'];
  32. }
  33. $topicKps = STopicKp::model()->getTopicKps($topicIds);
  34. $topicSpecials = STopicSpecial::model()->getTopicSpecials($topicIds);
  35. $topicItems = STopicItem::model()->getTopicItems($topicIds);
  36. $topicItemOptions = STopicItemOption::model()->getTopicItemOptions($topicIds);
  37. $i = 0;
  38. foreach ($topicQuery AS $k => $v)
  39. {
  40. $_topicId = $v['topic_id'];
  41. $_key = $_topicId;
  42. if ($isReplaceBlank AND $v['topic_type'] == 5)
  43. {
  44. $v['topic_title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']);
  45. }
  46. $result[$_key] = array(
  47. 'id' => $_topicId,
  48. 'type_id' => (int)$v['topic_type'],
  49. 'creator_id' => $v['creator_id'],
  50. 'updater_id' => $v['updater_id'],
  51. 'create_time' => (int)$v['create_time'],
  52. 'update_time' => (int)$v['update_time'],
  53. 'title' => preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']),
  54. 'difficulty' => (int)$v['topic_difficulty'],
  55. 'subject_id' => (int)$v['subject_id'],
  56. 'folder_id' => $v['folder_id'],
  57. 'source_id' => (int)$v['source_id'],
  58. 'source_title' => $v['source_title'],
  59. 'parse_video' => $v['parse_video'],
  60. 'parse_content' => $v['parse_content'],
  61. 'teacher_tips' => $v['teacher_tips'],
  62. 'relation_topic'=> $v['relation_topic'],
  63. 'teaching_quality' => $v['teaching_quality'],
  64. );
  65. switch ($v['topic_type'])
  66. {
  67. case 1:
  68. $result[$_key]['type_name'] = '选择题';
  69. break;
  70. case 5:
  71. $result[$_key]['type_name'] = '填空题';
  72. break;
  73. case 7:
  74. $result[$_key]['type_name'] = '简答题';
  75. break;
  76. default:
  77. $result[$_key]['type_name'] = '';
  78. break;
  79. }
  80. if (isset($topicKps[$_topicId]))
  81. {
  82. $result[$_key]['kps'] = $topicKps[$_topicId];
  83. }
  84. else
  85. {
  86. $result[$_key]['kps'] = array();
  87. }
  88. if (isset($topicSpecials[$_topicId]))
  89. {
  90. $result[$_key]['specials'] = $topicSpecials[$_topicId];
  91. }
  92. else
  93. {
  94. $result[$_key]['specials'] = array();
  95. }
  96. $result[$_key]['items'] = array();
  97. if (isset($topicItems[$_topicId]))
  98. {
  99. $result[$_key]['items'][] = array(
  100. 'type_id' => (int)$topicItems[$_topicId][0]['topic_type'],
  101. 'type_name' => $result[$_key]['type_name'],
  102. 'list_type' => (int)$topicItems[$_topicId][0]['list_type'],
  103. 'title' => '',
  104. 'options' => array(),
  105. );
  106. if (isset($topicItemOptions[$_topicId]))
  107. {
  108. $result[$_key]['items'][0]['options'] = array();
  109. foreach ($topicItemOptions[$_topicId] AS $option)
  110. {
  111. $result[$_key]['items'][0]['options'][] = array(
  112. 'option_id' => (int)$option['option_id'],
  113. 'option_content' => $option['option_content'],
  114. 'option_correct' => $option['option_correct'],
  115. 'option_score' => (float)$option['option_score'],
  116. );
  117. }
  118. }
  119. }
  120. $i++;
  121. }
  122. }
  123. return $result;
  124. }
  125. public function getRecords($condition, $offset = 0, $limit = 10, $teacherId = '', $isReplaceBlank = FALSE)
  126. {
  127. $result = array();
  128. $criteria = new CDbCriteria();
  129. $criteria->join = 'JOIN teacher c ON t.updater_id = c.teacher_id JOIN teacher u ON t.updater_id = u.teacher_id';
  130. $criteria->select = 't.*, c.teacher_name AS creator_name, u.teacher_name AS updater_name';
  131. $criteria->addCondition($condition);
  132. $criteria->order = 'update_time DESC';
  133. $criteria->limit = $limit;
  134. $criteria->offset = $offset;
  135. $topicIds = array();
  136. $topicQuery = getAttributes($this->findAll($criteria));
  137. if ($topicQuery)
  138. {
  139. foreach ($topicQuery AS $k => $v)
  140. {
  141. $topicIds[] = $v['topic_id'];
  142. }
  143. $topicKps = STopicKp::model()->getTopicKps($topicIds);
  144. $topicSpecials = STopicSpecial::model()->getTopicSpecials($topicIds);
  145. $topicItems = STopicItem::model()->getTopicItems($topicIds);
  146. $topicItemOptions = STopicItemOption::model()->getTopicItemOptions($topicIds);
  147. $topicUses = STopicUse::model()->getTopicUses($topicIds);
  148. $i = 0;
  149. foreach ($topicQuery AS $k => $v)
  150. {
  151. $_topicId = $v['topic_id'];
  152. $_key = $i .'_'. $_topicId;
  153. if ($isReplaceBlank AND $v['topic_type'] == 5)
  154. {
  155. $v['topic_title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']);
  156. }
  157. $result[$_key] = array(
  158. 'id' => $_topicId,
  159. 'type_id' => (int)$v['topic_type'],
  160. 'creator_id' => $v['creator_id'],
  161. // 'creator_name' => $v['creator_name'],
  162. 'updater_id' => $v['updater_id'],
  163. // 'updater_name' => $v['updater_name'],
  164. 'create_time' => (int)$v['create_time'],
  165. 'update_time' => (int)$v['update_time'],
  166. 'title' => $v['topic_title'],
  167. 'difficulty' => (int)$v['topic_difficulty'],
  168. 'subject_id' => (int)$v['subject_id'],
  169. 'folder_id' => $v['folder_id'],
  170. 'source_id' => (int)$v['source_id'],
  171. 'source_title' => $v['source_title'],
  172. 'parse_video' => $v['parse_video'],
  173. 'parse_content' => $v['parse_content'],
  174. );
  175. switch ($v['topic_type'])
  176. {
  177. case 1:
  178. $result[$_key]['type_name'] = '选择题';
  179. break;
  180. case 5:
  181. $result[$_key]['type_name'] = '填空题';
  182. break;
  183. case 7:
  184. $result[$_key]['type_name'] = '简答题';
  185. break;
  186. default:
  187. $result[$_key]['type_name'] = '';
  188. break;
  189. }
  190. if (isset($topicKps[$_topicId]))
  191. {
  192. $result[$_key]['kps'] = $topicKps[$_topicId];
  193. }
  194. else
  195. {
  196. $result[$_key]['kps'] = array();
  197. }
  198. if (isset($topicSpecials[$_topicId]))
  199. {
  200. $result[$_key]['specials'] = $topicSpecials[$_topicId];
  201. }
  202. else
  203. {
  204. $result[$_key]['specials'] = array();
  205. }
  206. $result[$_key]['uses'] = array();
  207. $result[$_key]['uses']['total'] = 0;
  208. $result[$_key]['uses']['oneself'] = 0;
  209. if (isset($topicUses[$_topicId]))
  210. {
  211. $result[$_key]['uses']['total'] = count($topicUses[$_topicId]);
  212. foreach ($topicUses[$_topicId] AS $key => $val)
  213. {
  214. if ($val['teacher_id'] == $teacherId)
  215. {
  216. $result[$_key]['uses']['oneself']++;
  217. }
  218. }
  219. }
  220. $result[$_key]['items'] = array();
  221. if (isset($topicItems[$_topicId]))
  222. {
  223. $result[$_key]['items'][] = array(
  224. 'type_id' => (int)$topicItems[$_topicId][0]['topic_type'],
  225. 'type_name' => $result[$_key]['type_name'],
  226. 'list_type' => (int)$topicItems[$_topicId][0]['list_type'],
  227. 'title' => '',
  228. 'options' => array(),
  229. );
  230. if (isset($topicItemOptions[$_topicId]))
  231. {
  232. $result[$_key]['items'][0]['options'] = array();
  233. foreach ($topicItemOptions[$_topicId] AS $option)
  234. {
  235. $result[$_key]['items'][0]['options'][] = array(
  236. 'option_id' => (int)$option['option_id'],
  237. 'option_content' => $option['option_content'],
  238. 'option_correct' => $option['option_correct'],
  239. 'option_score' => (float)$option['option_score'],
  240. );
  241. }
  242. }
  243. }
  244. $i++;
  245. }
  246. }
  247. return $result;
  248. }
  249. }