🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 资源首页-获取教材 ``` //获取老师默认的教材(最近使用的教材,不存在则获取默认第一本) V2UserService::factory()->getTeacherDefaultBook($userID); $book = MongoService::factory()->getTextBookHistory($userID); Array ( [subjectID] => 1 [subjectName] => 语文 [schoolTypeID] => 1 [schoolType] => 小学 [versionID] => 1 [versionName] => 人教版 [tagID] => 68408 [bookName] => 一年级上册(2016版) [unitID] => 68410 [chapterID] => 68412 ) /** * 获取用户设置的所有教材ID * @param $userID * @return array * @author wuzhc 2017-01-17 */ public function getTextbookIDs($userID) { $materialIDs = $this->_materialIDs($userID); /* 用户设置教材 */ $schoolMaterialIDs = $this->_schoolMaterialIDs($userID); /* 学校设置教材 */ return array_unique(array_merge($schoolMaterialIDs,$materialIDs)); } //用户设置教材 private function _materialIDs($userID) { $materials = V2UserService::factory()->getSubjectMaps($userID, WK::SUBJECT_MATERIAL); return $materials ? ArrayUtils::getColumn($materials, 'fdTagID') : array(); } /** * 根据用户ID 和 教材类别 获取 用户的教材内容 * @param $userID // 用户ID * @param $tagType //教材类别:用户对于的教材类别;such: * WK::SUBJECT_INTERESTED - 兴趣科目 , * WK::SUBJECT_TEACH - 任教科目 , * WK::SUBJECT_MATERIAL - 教材科目 3 * WK::SUBJECT_ASSIST - 辅材科目 * * @param int | null $subjectID //科目ID * @param int $limit //限制数据条数 * @return array * @author zhangjsh 2015-8-19 */ public function getSubjectMaps($userID, $tagType, $subjectID = NULL, $limit = 0) { $criteria = new CDbCriteria(); CDbUtils::addCondition($criteria, 't.fdUserID', $userID); CDbUtils::addCondition($criteria, 't.fdTag', $tagType); CDbUtils::addCondition($criteria, 't.fdSubjectID', $subjectID); $criteria->order = 't.id DESC'; if ($limit) { $criteria->limit = $limit; } return SubjectMap::model()->findAll($criteria); } ``` ## 学生/教师与科目的关系表 wkwke.tbSubjectMap ``` CREATE TABLE `tbSubjectMap` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fdUserID` int(11) DEFAULT NULL COMMENT '用户ID,对应service.tbUser.id,用户包括学生、教师', `fdSubjectID` int(11) DEFAULT NULL COMMENT '科目ID,对应tbSubject.id', `fdTag` tinyint(4) DEFAULT NULL COMMENT '1 - 兴趣科目 2 - 任教科目 3 - 教材科目', `fdTagID` int(11) NOT NULL COMMENT '教材ID,对应tbTag.id', `fdGradeID` int(11) DEFAULT NULL COMMENT '年级ID,对应tbGrade.id', PRIMARY KEY (`id`), KEY `FK_CourseID` (`fdSubjectID`), KEY `FK_GradeID` (`fdGradeID`) ) ENGINE=MyISAM AUTO_INCREMENT=425270 DEFAULT CHARSET=utf8 COMMENT='学生/教师与科目的关系表'; ``` ![](./img/2019-01-22_095339.png) ## 获取教材封面 http://xue.test/index.php?r=user/getTextbook D:\wamp\www\xue.test\xuetang\protected\controllers\UserController.php /** * 获取当前用户教材列表(包含学校设置教材) * @link https://tower.im/projects/1297b9da9d2047398fb1618e20f74072/docs/1618c710490a4e559c0121a2d893c289/ * @author wuzhc 2017-01-11 */ public function actionGetTextbook() { $userID = Yii::app()->user->id; $result['textbook'] = V2UserService::factory()->getTextbook($userID); ResponseUtils::json(array('data' => $result)); } ![](./img/2019-01-22_102237.png) /** * 获取当前用户教材列表(包含学校设置教材) * @link https://tower.im/projects/1297b9da9d2047398fb1618e20f74072/docs/1618c710490a4e559c0121a2d893c289/ * @param int $userID * @return array * @author wuzhc 2017-01-11 */ public function getTextbook($userID) { $bookHistory = MongoService::factory()->getTextBookHistory($userID); /* 最后一次设置教材历史记录 */ $data = array(); $bookIDs = $this->getTextbookIDs($userID); foreach ($bookIDs as $id) { $book = RelevanceUtils::resolveAncestors($id); if (!$book) { continue; } $temp = array(); $temp['id'] = $id; $temp['title'] = $book[WK::TAG_ONE_LEVEL]['name']; $temp['thumb'] = RelevanceService::factory()->getTextbookCover($id);; $temp['schoolTypeID'] = $book[WK::SECTION_ATTR_ID]['id']; $temp['schoolType'] = $book[WK::SECTION_ATTR_ID]['name']; $temp['subjectID'] = $book[WK::SUJT_ATTR_ID]['id']; $temp['subject'] = $book[WK::SUJT_ATTR_ID]['name']; $temp['versionID'] = $book[WK::VER_ATTR_ID]['id']; $temp['version'] = $book[WK::VER_ATTR_ID]['name']; $temp['isSelect'] = ($id == $bookHistory['tagID']) ? 1 : 0; $data[] = $temp; } return $data; } ### 根据单个底层节点获取并解析其祖先节点,返回如下结构: $book = RelevanceUtils::resolveAncestors($id); ![](./img/2019-01-22_103344.png) ### 根据ID获取书封面 4677 RelevanceService::factory()->getTextbookCover($id); ![](./img/2019-01-22_103632.png) ## 考点 ![](./img/2019-01-22_104509.png)