# 修改课表
## 需求说明
在指定的日期,替换科目ID。
#### 实现:
*1、修改的情况*
**班级课表:**
根据日期(当前日期大于修改日期时就启用修改后的课表)、周、节、科目,去判断是否有修改。如果有修改,则覆盖掉旧的课表。
**教师课表:**
根据老师执教的班级、日期、科目获取是否有修改课表的记录。如果有修改,才修改教师课表。
所教班级、周、节、科目,去判断是否有修改。
*2、新增的情况*
**班级课表:**
根据班级、日期(修改前,不需要修改)判断是否有新增课表的记录。如果有,添加到课表中。
**教师课表:**
....
## 会有影响的接口
**课表管理:**
- ~~获取作息时间 tms/timetable/getRestTimetable~~
- ~~批量设置作息时间 tms/timetable/settingRestTime~~
- ~~选择年级ID获取班级列表 tms/timetable/getClassesList~~
- 获取班级课表 tms/timetable/getClassTimetable
- ~~设置班级课程表 tms/timetable/setClassesTimetable~~
- 获取教师课表列表 tms/timetable/getTeacherTimetableList
**教师首页课表:**
- 获取教师课表 xingke/timetable/getTeacherTimetable
- ~~获取教师所教的班级 xingke/timetable/getClassListByTeacherID~~
- ~~教师调课 xingke/timetable/saveAdjustClass~~
- ~~获取每节课开始和结束时间 xingke/timetable/getTimetableSetting~~
- ~~获取课程表资源: xingke/timetable/getResources~~
**学生首页课表:**
- 获取班级课程表 xingke/timetable/getClassTimeTable
## 修改课表记录表字段
- fdTermID
- fdClassID
- fdDate
- fdWeekID
- fdClassIndex
- fdSubjectID
- fdSourceSubjectID
- fdUserID
- fdCreate
```
CREATE TABLE `tbTimetableChange` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fdTermID` int(11) DEFAULT NULL COMMENT '学期ID',
`fdClassID` int(11) DEFAULT NULL COMMENT '班级ID',
`fdDate` date DEFAULT NULL COMMENT '指定变更日期',
`fdWeekID` tinyint(4) DEFAULT NULL COMMENT '星期 1-7',
`fdClassIndex` tinyint(4) DEFAULT NULL COMMENT '当前课节次',
`fdSubjectID` tinyint(4) DEFAULT NULL COMMENT '当前课科目ID',
`fdSourceSubjectID` tinyint(4) DEFAULT NULL COMMENT '原课被修改为科目ID',
`fdUserID` int(11) DEFAULT NULL COMMENT '操作者用户ID',
`fdCreate` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `classid` (`fdClassID`)
) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8 COMMENT='修改课表记录';
```
### 获取课表接口
Request URL: http://ketang.test/index.php?r=tms/timetable/getClassTimetable&classID=20331&gradeID=7
- Request Method: GET
- r: tms/timetable/getClassTimetable
- classID: 20331
- gradeID: 7
```json
{
"data": {
"timetable": [{
"weekID": "1",
"class": [{
"classIndex": "1",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "2",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "3",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "4",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "5",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "6",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "8",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "9",
"subjectID": "3",
"subject": "英语",
"teacher": [{
"name": "香钦源",
"id": "1251338"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "10",
"subjectID": "7",
"subject": "音乐",
"teacher": []
}],
"date": "2019-5-27",
"week": "周一"
}, {
"weekID": "2",
"class": [{
"classIndex": "1",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "2",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "3",
"subjectID": "5",
"subject": "科学",
"teacher": []
}, {
"classIndex": "4",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "5",
"subjectID": "6",
"subject": "体育与健康",
"teacher": []
}, {
"classIndex": "6",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "8",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "9",
"subjectID": "7",
"subject": "音乐",
"teacher": []
}, {
"classIndex": "10",
"subjectID": "7",
"subject": "音乐",
"teacher": []
}],
"date": "2019-5-28",
"week": "周二"
}, {
"weekID": "3",
"class": [{
"classIndex": "3",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "4",
"subjectID": "8",
"subject": "美术",
"teacher": [{
"name": "帅嘉亮",
"id": "1459420"
}]
}, {
"classIndex": "5",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "8",
"subjectID": "10",
"subject": "其他",
"teacher": []
}, {
"classIndex": "9",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "10",
"subjectID": "11",
"subject": "物理",
"teacher": []
}],
"date": "2019-5-29",
"week": "周三"
}, {
"weekID": "4",
"class": [{
"classIndex": "3",
"subjectID": "11",
"subject": "物理",
"teacher": []
}, {
"classIndex": "4",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "5",
"subjectID": "12",
"subject": "化学",
"teacher": []
}, {
"classIndex": "8",
"subjectID": "7",
"subject": "音乐",
"teacher": []
}, {
"classIndex": "9",
"subjectID": "8",
"subject": "美术",
"teacher": [{
"name": "帅嘉亮",
"id": "1459420"
}]
}, {
"classIndex": "10",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}],
"date": "2019-5-30",
"week": "周四"
}, {
"weekID": "5",
"class": [{
"classIndex": "3",
"subjectID": "16",
"subject": "信息技术",
"teacher": []
}, {
"classIndex": "4",
"subjectID": "15",
"subject": "历史",
"teacher": []
}, {
"classIndex": "5",
"subjectID": "14",
"subject": "地理",
"teacher": []
}, {
"classIndex": "8",
"subjectID": "4",
"subject": "政治(道德与法治)",
"teacher": []
}, {
"classIndex": "9",
"subjectID": "3",
"subject": "英语",
"teacher": [{
"name": "香钦源",
"id": "1251338"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "10",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}],
"date": "2019-5-31",
"week": "周五"
}, {
"weekID": "6",
"class": [{
"classIndex": "5",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "6",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "8",
"subjectID": "3",
"subject": "英语",
"teacher": [{
"name": "香钦源",
"id": "1251338"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "9",
"subjectID": "2",
"subject": "数学",
"teacher": [{
"name": "吴金容",
"id": "1424397"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}]
}, {
"classIndex": "10",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}],
"date": "2019-6-01",
"week": "周六"
}, {
"weekID": "7",
"class": [{
"classIndex": "8",
"subjectID": "7",
"subject": "音乐",
"teacher": []
}, {
"classIndex": "9",
"subjectID": "1",
"subject": "语文",
"teacher": [{
"name": "贺洵",
"id": "2895089"
}, {
"name": "香钦源",
"id": "1251338"
}, {
"name": "莫小一",
"id": "677552"
}, {
"name": "董老师",
"id": "618430"
}]
}, {
"classIndex": "10",
"subjectID": "5",
"subject": "科学",
"teacher": []
}],
"date": "2019-6-02",
"week": "周日"
}],
"classNum": {
"morningClassNum": "0",
"forenoonClassNum": "4",
"afternoonClassNum": "3",
"nightClassNum": "0"
},
"isHeader": false
},
"status": 0,
"msg": "success",
"ssk": null,
"systime": 1559119015000
}
```
## 代码
*D:\wamp\www\ketang.test\weike\protected\modules\tms\controllers\TimetableController.php*
```
private function _checkChangeTimetable($timetables, $termID, $week, $subjectIDs = [])
{
$classID = 0;
foreach ($timetables as $k => $v) {
$classID = $v->fdClassID;
$dateFullName = $week[$v->fdWeekID - 1]['date'];
$weekID = $v->fdWeekID;
$classIndex = $v->fdClassIndex;
$subjectID = $v->fdSubjectID;
// 按日期查询是否有修改课表(换课) add by wangbo 2019-6-18
/*$change = TimetableService::factory()->getChangeTimetable($termID, $classID, $dateFullName, $weekID, $classIndex, $subjectID);
if ($change) {
$timetables[$k]->fdSubjectID = $change->fdSourceSubjectID;
}*/
// p($timetables); die;
}
// 获取本周的起始时间,查询本周是否有新增的课程
/*$beginDate = $week[0]['date'];
$endDate = $week[count($week) - 1]['date'];*/
$today = date("Y-m-d");
$criteria = new CDbCriteria();
$criteria->compare("fdTermID", $termID);
$criteria->compare("fdClassID", $classID);
$criteria->compare("fdSubjectID", 0);
if ($subjectIDs) {
// 教师课表,需要按教师所教科目查询
$criteria->addInCondition("fdSourceSubjectID", $subjectIDs);
}
$criteria->addCondition("fdBeginDate <= '{$today}'");
$criteria->addCondition("fdEndDate >= '{$today}'");
$res = teaTimetableChange::model()->findAll($criteria);
// var_dump($res); die;
// var_dump( $timetables); die;
/*
SELECT * FROM `wkteach`.`tbTimetableChange` `t` WHERE
((((fdTermID=:ycp164) AND (fdClassID=:ycp165)) AND (fdSubjectID=:ycp166))
AND (fdBeginDate <= '2019-06-03')) AND (fdEndDate >= '2019-06-03')
*/
// var_dump($res); die;
if ($res && $timetables) {
foreach ($res as $v) {
$temp = clone $timetables[0];
$temp->fdClassIndex = $v->fdClassIndex;
$temp->fdWeekID = $v->fdWeekID;
$temp->fdSubjectID = $v->fdSourceSubjectID;
$timetables = array_merge($timetables, [$temp]);
}
}
// var_dump($timetables); die;
return $timetables;
}
```
- 说明
- 开发任务
- 星课-真光
- 课表
- Excel Down
- 调课
- 课表修改
- 课表代码分析
- 课堂
- 课堂:应用商店通信管理协议
- 教师账号强制绑定手机或邮箱
- 强制绑定手机和修改密码的规则
- 学堂
- 课程学习:讨论功能
- 后台:课程讨论管理
- 课程直播接口
- 学习统计功能(旧版)
- 学习统计功能(新版)
- 同步课程统计功能
- 同步课程编辑-新增视频
- 第三方接口
- 学科网
- 安徽第三方
- 大赛
- 管控系统
- 日志管理
- 设备日志
- 平板接口
- 渝教
- 教学总结
- 空白目录
- Yii 1.1
- 学堂架构
- Yii 1.1一些方法的解读
- MVCS结构
- 基础使用语法
- 创建1个新模块
- 关联模型
- CDbCriteria
- 学生-课堂记录
- 学生端页面展示
- 教师端页面展示
- 编辑课程文档
- SQL
- 课堂项目运行入口
- 上传资源示意图
- 行为
- PHPStorm
- 源码阅读
- 会诊答卷页面
- 考点练习
- 资源首页
- 同步课程
- 同步课程:章节信息
- 升学复习
- 统计图-范例
- 模块
- 非法词
- 服务层
- MongoDB类
- 学堂作答记录从Mongo新集合获取数据
- MongoYii
- 错题集
- 小技巧
- 完善资料
- 邮件发送
- K12
- JSpang视频课程
- MongoDB
- 创业
- 项目
- 包包