Commit dbb95922 authored by xiabin's avatar xiabin

修改收藏评论表结构

parent 96434d90
......@@ -11,7 +11,7 @@ use yii\db\ActiveRecord;
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $courseware_id
* @property integer $parent_id
* @property string $content
* @property string $ip
......@@ -49,8 +49,8 @@ class Comments extends \yii\db\ActiveRecord
public function rules()
{
return [
[['user_id', 'course_id', 'parent_id', 'content', 'ip'], 'required'],
[['user_id', 'course_id', 'parent_id', 'created_at'], 'integer'],
[['user_id', 'courseware_id', 'parent_id', 'content', 'ip'], 'required'],
[['user_id', 'courseware_id', 'parent_id', 'created_at'], 'integer'],
[['content'], 'string'],
[['ip'], 'string', 'max' => 32],
];
......@@ -64,7 +64,7 @@ class Comments extends \yii\db\ActiveRecord
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'courseware_id' => 'CourseWare ID',
'parent_id' => 'Parent ID',
'content' => 'Content',
'ip' => 'Ip',
......
......@@ -137,7 +137,7 @@ class Course extends \yii\db\ActiveRecord
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
if ($count > 0) {
$data = self::find()->select('id,price,name,intro,preview_pic,recommend,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers')->asArray()->all();
$data = self::find()->select('id,user_id,price,name,intro,preview_pic,recommend,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers', 'favorites')->asArray()->all();
}
return [
'count' => $count,
......@@ -164,4 +164,15 @@ class Course extends \yii\db\ActiveRecord
{
return $this->hasMany(Teacher::className(), ['id' => 'teacher_id'])->viaTable(CourseTeacher::tableName(), ['course_id' => 'id']);
}
public function getComments()
{
$tableA = Comments::tableName();
return $this->hasMany(Comments::className(), ['user_id' => 'user_id', 'course_id' => 'id']);
}
public function getFavorites()
{
return $this->hasMany(Favorite::className(), ['user_id' => 'user_id', 'course_id' => 'id']);
}
}
......@@ -11,7 +11,7 @@ use yii\db\ActiveRecord;
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $courseware_id
* @property integer $created_at
*/
class Favorite extends \yii\db\ActiveRecord
......@@ -47,8 +47,8 @@ class Favorite extends \yii\db\ActiveRecord
public function rules()
{
return [
[['user_id', 'course_id',], 'required'],
[['user_id', 'course_id', 'created_at'], 'integer'],
[['user_id', 'courseware_id',], 'required'],
[['user_id', 'courseware_id', 'created_at'], 'integer'],
];
}
......@@ -60,7 +60,7 @@ class Favorite extends \yii\db\ActiveRecord
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'courseware_id' => 'CourseWare ID',
'created_at' => 'Created At',
];
}
......@@ -74,7 +74,7 @@ class Favorite extends \yii\db\ActiveRecord
$tableA = self::tableName();
$tableB = Course::tableName();
return self::find()
->select("course_id,$tableA.created_at as time ,$tableB.name,$tableB.avatar,$tableB.price,$tableB.free_time,$tableB.intro,$tableB.preview_pic,$tableB.created_at")
->select("courseware_id,$tableA.created_at as time ,$tableB.name,$tableB.avatar,$tableB.price,$tableB.free_time,$tableB.intro,$tableB.preview_pic,$tableB.created_at")
->where("$tableA.user_id = :user_id", [
':user_id' => $userId
])->join('left join', $tableB, "$tableA.user_id=$tableB.id")->asArray()->all();
......@@ -83,13 +83,13 @@ class Favorite extends \yii\db\ActiveRecord
/**
* 判断该用户是否收藏了该课堂
* @param $userId
* @param $courseId
* @param $coursewareId
* @return array|null|ActiveRecord
*/
public static function findByUserIdAndCourseId($userId, $courseId)
public static function findByUserIdAndCourseId($userId, $coursewareId)
{
return self::find()->select('id,user_id,course_id,created_at')
->where("user_id=:user_id and course_id=:course_id", ['user_id' => $userId, 'course_id' => $courseId])
return self::find()->select('id,user_id,courseware_id,created_at')
->where("user_id=:user_id and courseware_id=:courseware_id", ['user_id' => $userId, 'courseware_id' => $courseId])
->one();
}
}
......@@ -17,11 +17,11 @@ class m160927_120435_favorite_init extends Migration
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'courseware_id' => $this->integer()->notNull()->unsigned(),
'created_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '收藏表');
$this->createIndex('index-course_id', $this->table, 'course_id');
$this->createIndex('index-courseware_id', $this->table, 'courseware_id');
}
......
......@@ -17,14 +17,14 @@ class m160927_120550_comments_init extends Migration
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'courseware_id' => $this->integer()->notNull()->unsigned(),
'parent_id' => $this->integer()->notNull()->unsigned(),
'content' => $this->text()->notNull(),
'ip' => $this->string(32)->notNull(),
'created_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '评论表');
$this->createIndex('index-course_id', $this->table, 'course_id');
$this->createIndex('index-courseware_id', $this->table, 'courseware_id');
}
......
......@@ -122,7 +122,7 @@ class HomeController extends \yii\web\Controller
public function actionVideo($courseId)
{
$coursewareInfo = Courseware::findOne(['id' => $courseId, 'status' => Courseware::STATUS_OK]);
$course = Course::findOne(['id'=>$courseId]);
$course = Course::findOne(['id' => $courseId]);
$teachers = $course->teachers;
if ($coursewareInfo === NULL) {
throw new InvalidParamException('参数错误');
......
......@@ -10,109 +10,9 @@ $this->title = "视频播放";
\frontend\assets\AppAsset::addScript($this, '@web/assets/home_video.js');
\frontend\assets\AppAsset::addCss($this, '@web/assets/css/home_video.css');
?>
<div class="container">
<div class="cnt-tit">
<h3>为什么身体会做出不由自主的行为?</h3>
<div class="tit-share hidden-xs">
<a href="javascript:;" class="wechat post-icons"></a>
<a href="javascript:;" class="weibo post-icons"></a>
<a href="javascript:;" class="qzone post-icons"></a>
</div>
</div>
<div class="video-main">
<video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="1280" height="264"
poster="<?= \yii\helpers\Html::encode($coursewareInfo['previewUrl']) ?>"
data-setup='{"example_option":true,"autoplay":false,"language":"zh-CN"}'>
<source src="<?= \yii\helpers\Html::encode($coursewareInfo['videoUrl']) ?>" type="video/mp4"/>
</video>
</div>
<div class="video-detail-info">
<div class="video-teacher">
<a href="#"><img src="img/avatar2.jpg"></a>
<p><a href="#">乔布斯</a></p>
<span>2016-10-08</span>
</div>
<div class="video-sm-info">
<a href="#"><i class="icon-comment-empty"></i>543</a>
<a href="#"><i class="icon-fav-empty"></i>31</a>
<a href="#"><i class="icon-zan-empty"></i>97</a>
</div>
</div>
<input type="hidden" id="courseware-info" value="<?= \yii\helpers\Html::encode(json_encode($coursewareInfo)) ?>"/>
<div id="video-container">
<video-play :courseware-info="coursewareInfo"></video-play>
<video-intro :courseware-info="coursewareInfo"></video-intro>
</div>
<!--视频介绍-->
<div class="warp-box">
<div class="container">
<div class="video-description">
<div class="title">视频介绍</div>
<div class="text">
<?= \yii\helpers\Html::encode($coursewareInfo['intro'])?>
</div>
</div>
<div class="video-comment">
<div class="title">评论
<small>607次</small>
</div>
</div>
<?php if(Yii::$app->user->isGuest):?>
<div class="comment-login">
需要 <a href="#">登录</a> 才能评论
</div>
<?php endif;?>
<div class="comment-box">
<div class="comment-head">
<img src="img/avatar2.jpg">
</div>
<div class="comment-input clearfix">
<textarea name="" id="" cols="30" rows="10" class="form-control" placeholder="说几句吧,亲..."></textarea>
<button class="btn btn-default pull-right m-t-10">发表评论</button>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatarMax.png"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatar2.jpg"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src="img/avatarMax.png"></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
</div>
</div>
......@@ -9,7 +9,6 @@
<span class="play-mask"><i class="glyphicon glyphicon-play-circle"></i></span>
</a>
<!--头像-->
<span><img src="http://dev.zuiketang.com/assets/img/avatar2.jpg"></span>
</div>
<div class="v-tit"><a @click="itemClick(item.id)" href="javascript:;">{{item.name}}</a></div>
<div class="v-price">
......@@ -18,11 +17,10 @@
</div>
<div class="v-foot">
<p>{{transcateTime(item.created_at)}}</p>
<!--<div class="v-detail">-->
<!--<span><i class="icon-comment-full"></i> 12031</span>-->
<!--<span><i class="icon-fav-full"></i> 87</span>-->
<!--<span><i class="icon-zan-full"></i> 331</span>-->
<!--</div>-->
<div class="v-detail">
<span><i class="icon-comment-full"></i> 12031</span>
<span><i class="icon-fav-full"></i> 87</span>
</div>
</div>
</div>
</div>
......
<template>
<div class="warp-box">
<div class="container">
<div class="video-description">
<div class="title">视频介绍</div>
<div class="text">
<?= \yii\helpers\Html::encode($coursewareInfo['intro']) ?>
</div>
</div>
<div class="video-comment">
<div class="title">评论
<small>607次</small>
</div>
</div>
<div class="comment-login">
需要 <a href="">登录</a> 才能评论
</div>
<div class="comment-box">
<div class="comment-head">
<img src="">
</div>
<div class="comment-input clearfix">
<textarea name="" id="" cols="30" rows="10" class="form-control" placeholder="说几句吧,亲..."></textarea>
<button class="btn btn-default pull-right m-t-10">发表评论</button>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default{
data(){
return {}
},
props: {
coursewareInfo: {
require: true
}
},
components: {}
}
</script>
<template>
<div class="container">
<div class="cnt-tit">
<h3>为什么身体会做出不由自主的行为?</h3>
<div class="tit-share hidden-xs">
<a href="javascript:;" class="wechat post-icons"></a>
<a href="javascript:;" class="weibo post-icons"></a>
<a href="javascript:;" class="qzone post-icons"></a>
</div>
</div>
<div class="video-main">
<video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="640" height="264"
poster="{{{coursewareInfo.previewUrl}}}"
data-setup='{"example_option":true,"autoplay":false,"language":"zh-CN"}'>
<source :src="coursewareInfo.videoUrl" type="video/mp4"/>
</video>
</div>
<div class="video-detail-info">
<div class="video-teacher">
<a href="#"><img src=""></a>
<p><a href="#">乔布斯</a></p>
<span>2016-10-08</span>
</div>
<div class="video-sm-info">
<a href="#"><i class="icon-comment-empty"></i>543</a>
<a href="#"><i class="icon-fav-empty"></i>31</a>
<a href="#"><i class="icon-zan-empty"></i>97</a>
</div>
</div>
</div>
</template>
<script>
require('expose?videojs!../../libs/videojs/video.js');
require('../../libs/videojs/video-js.css');
require('../../libs/videojs/lang/zh-CN.js');
videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf';
window.VIDEOJS_NO_BASE_THEME = true;
//
export default{
data(){
return {}
},
props: {
coursewareInfo: {
require: true
}
},
components: {},
ready(){
videojs("example_video_1").ready(function () {
var myPlayer = this;
// EXAMPLE: Start playing the video.
// myPlayer.play();
});
}
}
</script>
/**
* Created by xiabin on 2016/10/14.
*/
require('expose?videojs!../libs/videojs/video.js');
require('../libs/videojs/video-js.css');
require('../libs/videojs/lang/zh-CN.js');
// console.log(videojs);
// layer.msg('home/index');
videojs.options.flash.swf = __CDN_URL__ + 'assets/videojs/video-js.swf';
window.VIDEOJS_NO_BASE_THEME = true;
//
videojs("example_video_1").ready(function () {
var myPlayer = this;
// EXAMPLE: Start playing the video.
// myPlayer.play();
var Vue = require('vue');
var videoPlay = require('./components/video-play.vue');
var videoIntro = require('./components/video-intro.vue');
var coursewareInfo = JSON.parse($('#courseware-info').val());
new Vue({
el: "#video-container",
data: {
coursewareInfo: coursewareInfo
},
components: {
videoPlay: videoPlay,
videoIntro: videoIntro
}
});
\ No newline at end of file
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