Commit c4f8805c authored by xiabin's avatar xiabin

添加预览页

parent d871017a
......@@ -73,7 +73,7 @@ class HomeController extends \yii\web\Controller
'classInfo' => $classInfo
]);
} else {
throw new HttpException(404,'页面不存在');
throw new HttpException(404, '页面不存在');
}
}
......@@ -92,7 +92,7 @@ class HomeController extends \yii\web\Controller
if ($page >= 0 and $num > 0) {
$result = Course::getCourseListsByClassId($classId, $page, $num);
} else {
throw new HttpException(404,'页面不存在');
throw new HttpException(404, '页面不存在');
}
} else {
throw new ForbiddenHttpException('非法请求');
......@@ -120,18 +120,19 @@ class HomeController extends \yii\web\Controller
* 视频播放页面
* @param $courseId
* @return string
* @throws HttpException
*/
public function actionVideo($courseId)
{
$coursewareInfo = Courseware::findOne(['course_id' => $courseId, 'status' => Courseware::STATUS_OK]);
$course = Course::findOne(['id' => $courseId]);
if($course === NULL){
throw new HttpException(404,'页面不存在');
if ($course === NULL and $coursewareInfo['status'] != Courseware::STATUS_OK) {
throw new HttpException(404, '页面不存在');
}
$teachers = $course->teachers;
$userId = Yii::$app->user->id;
if ($coursewareInfo === NULL) {
throw new HttpException(404,'页面不存在');
throw new HttpException(404, '页面不存在');
} else {
$coursewareInfo = $coursewareInfo->toArray();
$coursewareInfo['previewUrl'] = Yii::$app->qiniu->getUrl('public', $course->preview_pic);
......@@ -147,9 +148,9 @@ class HomeController extends \yii\web\Controller
$order = Orders::findByUserIdAndCourseId($userId, $courseId);
$coursewareInfo['isShop'] = ($order !== NULL and $order->status === Orders::PAID ? TRUE : FALSE);
}
if($coursewareInfo['isShop']){
if ($coursewareInfo['isShop']) {
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['src_stand']);
}else{
} else {
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['src_free']);
}
unset($coursewareInfo['src_stand']);
......@@ -159,7 +160,7 @@ class HomeController extends \yii\web\Controller
$coursewareInfo['className'] = Classes::findOne(['id' => $course->class_id])->name;
$coursewareInfo['isMobile'] = Yii::$app->deviceDetect->isMobile();
//处理讲师头像
foreach ($coursewareInfo['teachers'] as $key => $value){
foreach ($coursewareInfo['teachers'] as $key => $value) {
$coursewareInfo['teachers'][$key]['avatar'] = User::getAvatarUrl($value['avatar']);
}
return $this->render('video', [
......@@ -171,17 +172,18 @@ class HomeController extends \yii\web\Controller
/**
* 预览页
*/
public function actionPreview($courseId){
public function actionPreview($courseId)
{
$coursewareInfo = Courseware::findOne(['course_id' => $courseId, 'status' => Courseware::STATUS_OK]);
$course = Course::findOne(['id' => $courseId]);
if($course === NULL){
throw new HttpException(404,'页面不存在');
if ($course === NULL or Yii::$app->user->id !== $coursewareInfo['user_id']) {
throw new HttpException(404, '页面不存在');
}
$teachers = $course->teachers;
$userId = Yii::$app->user->id;
if ($coursewareInfo === NULL) {
throw new HttpException(404,'页面不存在');
throw new HttpException(404, '页面不存在');
} else {
$coursewareInfo = $coursewareInfo->toArray();
$coursewareInfo['previewUrl'] = Yii::$app->qiniu->getUrl('public', $course->preview_pic);
......@@ -197,9 +199,9 @@ class HomeController extends \yii\web\Controller
$order = Orders::findByUserIdAndCourseId($userId, $courseId);
$coursewareInfo['isShop'] = ($order !== NULL and $order->status === Orders::PAID ? TRUE : FALSE);
}
if($coursewareInfo['isShop']){
if ($coursewareInfo['isShop']) {
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['src_stand']);
}else{
} else {
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['src_free']);
}
unset($coursewareInfo['src_stand']);
......@@ -209,10 +211,10 @@ class HomeController extends \yii\web\Controller
$coursewareInfo['className'] = Classes::findOne(['id' => $course->class_id])->name;
$coursewareInfo['isMobile'] = Yii::$app->deviceDetect->isMobile();
//处理讲师头像
foreach ($coursewareInfo['teachers'] as $key => $value){
foreach ($coursewareInfo['teachers'] as $key => $value) {
$coursewareInfo['teachers'][$key]['avatar'] = User::getAvatarUrl($value['avatar']);
}
return $this->render('preview',[
return $this->render('preview', [
'coursewareInfo' => $coursewareInfo
]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment