123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
- /**
- * @author: CeeFee
- * @description: 考试
- */
- class STopic extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
-
- public function tableName()
- {
- return 'topic';
- }
- public function getSchTopicDetail($topic_id_arr, $isReplaceBlank = FALSE)
- {
- $result = array();
- $condition = "topic_id IN (". implode(',', $topic_id_arr) .")";
- $criteria = new CDbCriteria();
- $criteria->join = 'JOIN teacher c ON t.updater_id = c.teacher_id JOIN teacher u ON t.updater_id = u.teacher_id';
- $criteria->select = 't.*, c.teacher_name AS creator_name, u.teacher_name AS updater_name';
- $criteria->addCondition($condition);
- $criteria->order = 'update_time DESC';
- $topicIds = array();
- $topicQuery = getAttributes($this->findAll($criteria));
- if ($topicQuery)
- {
- foreach ($topicQuery AS $k => $v)
- {
- $topicIds[] = $v['topic_id'];
- }
- $topicKps = STopicKp::model()->getTopicKps($topicIds);
- $topicSpecials = STopicSpecial::model()->getTopicSpecials($topicIds);
- $topicItems = STopicItem::model()->getTopicItems($topicIds);
- $topicItemOptions = STopicItemOption::model()->getTopicItemOptions($topicIds);
- $i = 0;
- foreach ($topicQuery AS $k => $v)
- {
- $_topicId = $v['topic_id'];
- $_key = $_topicId;
- if ($isReplaceBlank AND $v['topic_type'] == 5)
- {
- $v['topic_title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']);
- }
- $result[$_key] = array(
- 'id' => $_topicId,
- 'type_id' => (int)$v['topic_type'],
- 'creator_id' => $v['creator_id'],
- 'updater_id' => $v['updater_id'],
- 'create_time' => (int)$v['create_time'],
- 'update_time' => (int)$v['update_time'],
- 'title' => preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']),
- 'difficulty' => (int)$v['topic_difficulty'],
- 'subject_id' => (int)$v['subject_id'],
- 'folder_id' => $v['folder_id'],
- 'source_id' => (int)$v['source_id'],
- 'source_title' => $v['source_title'],
- 'parse_video' => $v['parse_video'],
- 'parse_content' => $v['parse_content'],
- 'teacher_tips' => $v['teacher_tips'],
- 'relation_topic'=> $v['relation_topic'],
- 'teaching_quality' => $v['teaching_quality'],
- );
- switch ($v['topic_type'])
- {
- case 1:
- $result[$_key]['type_name'] = '选择题';
- break;
- case 5:
- $result[$_key]['type_name'] = '填空题';
- break;
- case 7:
- $result[$_key]['type_name'] = '简答题';
- break;
- default:
- $result[$_key]['type_name'] = '';
- break;
- }
- if (isset($topicKps[$_topicId]))
- {
- $result[$_key]['kps'] = $topicKps[$_topicId];
- }
- else
- {
- $result[$_key]['kps'] = array();
- }
- if (isset($topicSpecials[$_topicId]))
- {
- $result[$_key]['specials'] = $topicSpecials[$_topicId];
- }
- else
- {
- $result[$_key]['specials'] = array();
- }
- $result[$_key]['items'] = array();
- if (isset($topicItems[$_topicId]))
- {
- $result[$_key]['items'][] = array(
- 'type_id' => (int)$topicItems[$_topicId][0]['topic_type'],
- 'type_name' => $result[$_key]['type_name'],
- 'list_type' => (int)$topicItems[$_topicId][0]['list_type'],
- 'title' => '',
- 'options' => array(),
- );
- if (isset($topicItemOptions[$_topicId]))
- {
- $result[$_key]['items'][0]['options'] = array();
- foreach ($topicItemOptions[$_topicId] AS $option)
- {
- $result[$_key]['items'][0]['options'][] = array(
- 'option_id' => (int)$option['option_id'],
- 'option_content' => $option['option_content'],
- 'option_correct' => $option['option_correct'],
- 'option_score' => (float)$option['option_score'],
- );
- }
- }
- }
- $i++;
- }
- }
- return $result;
- }
- public function getRecords($condition, $offset = 0, $limit = 10, $teacherId = '', $isReplaceBlank = FALSE)
- {
- $result = array();
-
- $criteria = new CDbCriteria();
- $criteria->join = 'JOIN teacher c ON t.updater_id = c.teacher_id JOIN teacher u ON t.updater_id = u.teacher_id';
- $criteria->select = 't.*, c.teacher_name AS creator_name, u.teacher_name AS updater_name';
- $criteria->addCondition($condition);
- $criteria->order = 'update_time DESC';
- $criteria->limit = $limit;
- $criteria->offset = $offset;
- $topicIds = array();
- $topicQuery = getAttributes($this->findAll($criteria));
-
- if ($topicQuery)
- {
- foreach ($topicQuery AS $k => $v)
- {
- $topicIds[] = $v['topic_id'];
- }
-
- $topicKps = STopicKp::model()->getTopicKps($topicIds);
- $topicSpecials = STopicSpecial::model()->getTopicSpecials($topicIds);
- $topicItems = STopicItem::model()->getTopicItems($topicIds);
- $topicItemOptions = STopicItemOption::model()->getTopicItemOptions($topicIds);
- $topicUses = STopicUse::model()->getTopicUses($topicIds);
-
- $i = 0;
-
- foreach ($topicQuery AS $k => $v)
- {
- $_topicId = $v['topic_id'];
- $_key = $i .'_'. $_topicId;
-
- if ($isReplaceBlank AND $v['topic_type'] == 5)
- {
- $v['topic_title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['topic_title']);
- }
-
- $result[$_key] = array(
- 'id' => $_topicId,
- 'type_id' => (int)$v['topic_type'],
- 'creator_id' => $v['creator_id'],
- // 'creator_name' => $v['creator_name'],
- 'updater_id' => $v['updater_id'],
- // 'updater_name' => $v['updater_name'],
- 'create_time' => (int)$v['create_time'],
- 'update_time' => (int)$v['update_time'],
- 'title' => $v['topic_title'],
- 'difficulty' => (int)$v['topic_difficulty'],
- 'subject_id' => (int)$v['subject_id'],
- 'folder_id' => $v['folder_id'],
- 'source_id' => (int)$v['source_id'],
- 'source_title' => $v['source_title'],
- 'parse_video' => $v['parse_video'],
- 'parse_content' => $v['parse_content'],
- );
-
- switch ($v['topic_type'])
- {
- case 1:
- $result[$_key]['type_name'] = '选择题';
- break;
- case 5:
- $result[$_key]['type_name'] = '填空题';
- break;
- case 7:
- $result[$_key]['type_name'] = '简答题';
- break;
- default:
- $result[$_key]['type_name'] = '';
- break;
- }
-
- if (isset($topicKps[$_topicId]))
- {
- $result[$_key]['kps'] = $topicKps[$_topicId];
- }
- else
- {
- $result[$_key]['kps'] = array();
- }
-
- if (isset($topicSpecials[$_topicId]))
- {
- $result[$_key]['specials'] = $topicSpecials[$_topicId];
- }
- else
- {
- $result[$_key]['specials'] = array();
- }
-
- $result[$_key]['uses'] = array();
- $result[$_key]['uses']['total'] = 0;
- $result[$_key]['uses']['oneself'] = 0;
-
- if (isset($topicUses[$_topicId]))
- {
- $result[$_key]['uses']['total'] = count($topicUses[$_topicId]);
-
- foreach ($topicUses[$_topicId] AS $key => $val)
- {
- if ($val['teacher_id'] == $teacherId)
- {
- $result[$_key]['uses']['oneself']++;
- }
- }
- }
-
- $result[$_key]['items'] = array();
-
- if (isset($topicItems[$_topicId]))
- {
- $result[$_key]['items'][] = array(
- 'type_id' => (int)$topicItems[$_topicId][0]['topic_type'],
- 'type_name' => $result[$_key]['type_name'],
- 'list_type' => (int)$topicItems[$_topicId][0]['list_type'],
- 'title' => '',
- 'options' => array(),
- );
-
- if (isset($topicItemOptions[$_topicId]))
- {
- $result[$_key]['items'][0]['options'] = array();
-
- foreach ($topicItemOptions[$_topicId] AS $option)
- {
- $result[$_key]['items'][0]['options'][] = array(
- 'option_id' => (int)$option['option_id'],
- 'option_content' => $option['option_content'],
- 'option_correct' => $option['option_correct'],
- 'option_score' => (float)$option['option_score'],
- );
- }
- }
- }
-
- $i++;
- }
- }
-
- return $result;
- }
- }
|