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("/]*[\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("/]*[\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("/]*[\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; } }