# actionGetTeacherTimetable
D:\wamp\www\ketang.test\weike\protected\modules\xingke\controllers\TimetableController.php
1. 查找该老师的课表记录(根据当前教师用户的班级和科目查找)
```
$criteria = new CDbCriteria();
$criteria->addInCondition('t.fdClassID', $classIDs);
$criteria->addInCondition('t.fdSubjectID', $subjectIDs);
$res2 = TimetableService::factory()->getAttributesByObject(teaTimetable::model()->findAll($criteria));
```
![](https://img.kancloud.cn/63/f4/63f46d5723e638df19f13046a8e2a1a1_292x631.png)
2. 组装数组
```
$arr = [];
$week = TimeFormatUtils::get_week($start ? floor($start / 1000) : time(), 'Y-m-d');
for ($i = 1; $i <= 7; $i++) {
$arr[$i]['weekID'] = $i;
$arr[$i]['date'] = $week[$i - 1]['date'];
$weekText = $week[$i - 1]['week'];
$arr[$i]['week'] = $weekText;
}
```
![](https://img.kancloud.cn/0b/df/0bdf6a7528c157cad0eb8b842aa61984_304x782.png)
3. 遍历课表记录,组装每节课的信息到组装数组
```
foreach ($res2 as $item) {
$temp = [];
$weekID = $item['fdWeekID'];
$classIndex = $item['fdClassIndex'];
$classID = $item['fdClassID'];
$subjectID = $item['fdSubjectID'];
$date = $arr[$weekID]['date']; //日期,如3-11
$dateFullName = date('Y-m-d', strtotime($date)); // 完成日期,如2019-03-11
// 检查是否是调课 ['type' => 1 和谁调换 2 被谁调换 3 和空白课调换]
$adjust = TimetableService::factory()->getIsAdjustTimetable($termID, $classID, $dateFullName, $classIndex, $subjectID);
// 课表信息:节次
$temp['classIndex'] = $classIndex;
if ($adjust) {
...
} else {
// 课表信息:科目信息
$temp['subject']['id'] = $subjectID;
$temp['subject']['title'] = Yii::app()->params['SUBJECT_ARR'][$subjectID];
$temp['subject']['isAdjust'] = 0; // 不是调课
// 课表信息:资源信息
$temp['resource'] = TimetableService::factory()->getAllTypesResourcesStatus($termID, $classID, $dateFullName, $classIndex);
}
// 课表信息:班级信息
$temp['class']['id'] = $classID;
$class = wkeClass::model()->findByPk($classID);
$temp['class']['title'] = $class->fdName;
$temp['class']['gradeID'] = $class->fdGradeID;
// 空白课调课情况
if ($adjust['type'] == 3) {
...
}
// 非空白课程调换
if (in_array($adjust['type'], [1, 2]) && !$isAdjust) {
if ($adjust['type'] == 2) {
$weekID = TimeFormatUtils::get_week_id($adjust['data']->fdDate);
$classIndex = $adjust['data']->fdClassIndex;
$temp['classIndex'] = $classIndex;
$temp['subject']['id'] = $adjust['data']->fdSourceSubjectID;
$temp['subject']['title'] = Yii::app()->params['SUBJECT_ARR'][$adjust['data']->fdSourceSubjectID];
$temp['subject']['isAdjust'] = 1; // 是调课*/
$dateFullName = $adjust['data']->fdDate;
} elseif ($adjust['type'] == 1) {
$weekID = TimeFormatUtils::get_week_id($adjust['data']->fdSourceDate);
$classIndex = $adjust['data']->fdSourceClassIndex;
$temp['classIndex'] = $classIndex;
$temp['subject']['id'] = $adjust['data']->fdSubjectID;
$temp['subject']['title'] = Yii::app()->params['SUBJECT_ARR'][$adjust['data']->fdSubjectID];
$temp['subject']['isAdjust'] = 1; // 是调课*/
$dateFullName = $adjust['data']->fdSourceDate;
}
// 调课后,资源访问
$temp['resource'] = TimetableService::factory()->getAllTypesResourcesStatus($termID, $classID, $dateFullName, $classIndex);
}
$arr[$weekID]['class'][$classIndex] = $temp;
}
```
![](https://img.kancloud.cn/2e/cc/2eccf6ddda5ee6579150582db669e5d6_304x427.png)
课表组装到数组后:
![](https://img.kancloud.cn/bb/14/bb1456d6715e9e7d5247c86ecbe7fc5a_695x787.png)
4. 按节次排序,修改数组索引
```
ksort($arr); // 一维数组按照主键排序
foreach ($arr as $k => $v) {
$temp = $v['class'];
$temp && ksort($temp);
$arr[$k]['class'] = $temp; // 二维数组按照主键排序
}
// 去除 index主键
foreach ($arr as $k => $v) {
$temp = [];
$temp['weekID'] = $v['weekID'];
$temp['date'] = $v['date'];
$temp['week'] = $v['week'];
$temp['class'] = $v['class'] ? array_values($v['class']) : null;
krsort($temp);
$arr[$k] = $temp;
}
```
![](https://img.kancloud.cn/58/16/58161dc41bc6a8d49f9fd6a0f22aa855_463x716.png)
- 说明
- 开发任务
- 星课-真光
- 课表
- Excel Down
- 调课
- 课表修改
- 课表代码分析
- 课堂
- 课堂:应用商店通信管理协议
- 教师账号强制绑定手机或邮箱
- 强制绑定手机和修改密码的规则
- 学堂
- 课程学习:讨论功能
- 后台:课程讨论管理
- 课程直播接口
- 学习统计功能(旧版)
- 学习统计功能(新版)
- 同步课程统计功能
- 同步课程编辑-新增视频
- 第三方接口
- 学科网
- 安徽第三方
- 大赛
- 管控系统
- 日志管理
- 设备日志
- 平板接口
- 渝教
- 教学总结
- 空白目录
- Yii 1.1
- 学堂架构
- Yii 1.1一些方法的解读
- MVCS结构
- 基础使用语法
- 创建1个新模块
- 关联模型
- CDbCriteria
- 学生-课堂记录
- 学生端页面展示
- 教师端页面展示
- 编辑课程文档
- SQL
- 课堂项目运行入口
- 上传资源示意图
- 行为
- PHPStorm
- 源码阅读
- 会诊答卷页面
- 考点练习
- 资源首页
- 同步课程
- 同步课程:章节信息
- 升学复习
- 统计图-范例
- 模块
- 非法词
- 服务层
- MongoDB类
- 学堂作答记录从Mongo新集合获取数据
- MongoYii
- 错题集
- 小技巧
- 完善资料
- 邮件发送
- K12
- JSpang视频课程
- MongoDB
- 创业
- 项目
- 包包