Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
520e6928
Commit
520e6928
authored
Oct 17, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加收藏记录查看
parent
ef1e4364
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
113 deletions
+72
-113
Course.php
src/common/models/Course.php
+16
-7
Courseware.php
src/common/models/Courseware.php
+1
-0
Favorite.php
src/common/models/Favorite.php
+12
-4
m160927_114841_browse_record_init.php
src/console/migrations/m160927_114841_browse_record_init.php
+1
-0
m160927_120435_favorite_init.php
src/console/migrations/m160927_120435_favorite_init.php
+1
-0
HomeController.php
src/frontend/controllers/HomeController.php
+1
-0
UserCenterController.php
src/frontend/controllers/UserCenterController.php
+3
-1
favorite.php
src/frontend/views/user-center/favorite.php
+37
-101
No files found.
src/common/models/Course.php
View file @
520e6928
...
...
@@ -100,7 +100,7 @@ class Course extends \yii\db\ActiveRecord
'free_time'
=>
'免费试看'
,
'intro'
=>
'课程介绍'
,
'preview_pic'
=>
'预览图'
,
'favorite_count'
=>
'favorite_count'
'favorite_count'
=>
'favorite_count'
];
}
...
...
@@ -135,17 +135,17 @@ class Course extends \yii\db\ActiveRecord
* @param int $status 要获取的状态,null代表获取全部,默认为只获取审核通过的课程
* @return array
*/
public
static
function
getCourseListsByClassId
(
$classId
,
$page
=
0
,
$num
=
10
,
$status
=
self
::
STATUS_OK
)
public
static
function
getCourseListsByClassId
(
$classId
,
$page
=
0
,
$num
=
10
,
$status
=
self
::
STATUS_OK
)
{
$cond
=
[
'class_id'
=>
$classId
];
$status
!==
null
&&
$cond
[
'status'
]
=
$status
;
$cond
=
[
'class_id'
=>
$classId
];
$status
!==
NULL
&&
$cond
[
'status'
]
=
$status
;
//获取总数
$count
=
self
::
find
()
->
where
(
$cond
)
->
count
();
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
if
(
$page
===
null
)
{
$pagination
=
new
Pagination
([
'totalCount'
=>
$count
,
'pageSize'
=>
$num
,
'forcePageParam'
=>
false
]);
if
(
$page
===
NULL
)
{
$pagination
=
new
Pagination
([
'totalCount'
=>
$count
,
'pageSize'
=>
$num
,
'forcePageParam'
=>
FALSE
]);
$offset
=
$pagination
->
offset
;
$return
[
'pagination'
]
=
$pagination
;
}
else
{
...
...
@@ -180,4 +180,13 @@ class Course extends \yii\db\ActiveRecord
{
return
$this
->
hasMany
(
Teacher
::
className
(),
[
'id'
=>
'teacher_id'
])
->
viaTable
(
CourseTeacher
::
tableName
(),
[
'course_id'
=>
'id'
]);
}
/**
* 关联用户
* @return \yii\db\ActiveQuery
*/
public
function
getUser
()
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'user_id'
]);
}
}
src/common/models/Courseware.php
View file @
520e6928
...
...
@@ -104,4 +104,5 @@ class Courseware extends ActiveRecord
return
$result
===
NULL
?
FALSE
:
TRUE
;
}
}
src/common/models/Favorite.php
View file @
520e6928
...
...
@@ -48,7 +48,7 @@ class Favorite extends \yii\db\ActiveRecord
public
function
rules
()
{
return
[
[[
'user_id'
,
'courseware_id'
,],
'required'
],
[[
'user_id'
,
'courseware_id'
,
'course_id'
],
'required'
],
[[
'user_id'
,
'courseware_id'
,
'created_at'
],
'integer'
],
];
}
...
...
@@ -62,6 +62,7 @@ class Favorite extends \yii\db\ActiveRecord
'id'
=>
'ID'
,
'user_id'
=>
'User ID'
,
'courseware_id'
=>
'CourseWare ID'
,
'course_id'
=>
'Course ID'
,
'created_at'
=>
'Created At'
,
];
}
...
...
@@ -73,7 +74,6 @@ class Favorite extends \yii\db\ActiveRecord
public
static
function
findByUserId
(
$userId
,
$page
,
$num
)
{
$tableA
=
self
::
tableName
();
$tableB
=
Course
::
tableName
();
$condition
=
"
$tableA
.user_id=:user_id"
;
$params
=
[
':user_id'
=>
$userId
];
//获取总数
...
...
@@ -82,8 +82,7 @@ class Favorite extends \yii\db\ActiveRecord
$pagination
=
new
Pagination
([
'totalCount'
=>
$count
,
'pageSize'
=>
$num
,
'forcePageParam'
=>
FALSE
]);
$data
=
self
::
find
()
->
select
(
"courseware_id,
$tableA
.created_at as time ,
$tableB
.name,
$tableB
.price,
$tableB
.free_time,
$tableB
.intro,
$tableB
.preview_pic,
$tableB
.created_at"
)
->
where
(
$condition
,
$params
)
->
limit
(
$num
)
->
offset
(
$start
)
->
orderBy
(
"
$tableA
.created_at DESC"
)
->
join
(
'left join'
,
$tableB
,
"
$tableA
.user_id=
$tableB
.id"
)
->
asArray
()
->
all
();
->
where
(
$condition
,
$params
)
->
limit
(
$num
)
->
offset
(
$start
)
->
orderBy
(
"
$tableA
.created_at DESC"
)
->
joinWith
(
'course'
)
->
asArray
()
->
all
();
return
[
'count'
=>
$count
,
'data'
=>
$data
,
...
...
@@ -103,4 +102,13 @@ class Favorite extends \yii\db\ActiveRecord
->
where
(
"user_id=:user_id and courseware_id=:courseware_id"
,
[
':user_id'
=>
$userId
,
':courseware_id'
=>
$coursewareId
])
->
one
();
}
/**
* 获取课程信息
* @return $this
*/
public
function
getCourse
()
{
return
$this
->
hasOne
(
Course
::
className
(),
[
'id'
=>
'course_id'
])
->
with
(
'teachers'
)
->
with
(
'user'
);
}
}
src/console/migrations/m160927_114841_browse_record_init.php
View file @
520e6928
...
...
@@ -18,6 +18,7 @@ class m160927_114841_browse_record_init extends Migration
'id'
=>
$this
->
primaryKey
()
->
unsigned
(),
'user_id'
=>
$this
->
integer
()
->
notNull
()
->
unsigned
(),
'course_id'
=>
$this
->
integer
()
->
notNull
()
->
unsigned
(),
'courseware_id'
=>
$this
->
integer
()
->
notNull
()
->
unsigned
(),
'time'
=>
$this
->
integer
()
->
notNull
(),
],
$tableOptions
);
$this
->
addCommentOnTable
(
$this
->
table
,
'浏览记录表'
);
...
...
src/console/migrations/m160927_120435_favorite_init.php
View file @
520e6928
...
...
@@ -17,6 +17,7 @@ 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
);
...
...
src/frontend/controllers/HomeController.php
View file @
520e6928
...
...
@@ -228,6 +228,7 @@ class HomeController extends \yii\web\Controller
$favorite
=
new
Favorite
();
$favorite
->
user_id
=
$userId
;
$favorite
->
courseware_id
=
$coursewareId
;
$favorite
->
course_id
=
$courseware
->
course_id
;
$result
=
$favorite
->
save
();
//统计总数
...
...
src/frontend/controllers/UserCenterController.php
View file @
520e6928
...
...
@@ -91,8 +91,10 @@ class UserCenterController extends Controller
{
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
0
);
$num
=
Yii
::
$app
->
request
->
get
(
'num'
,
10
);
$page
--
;
$num
=
Yii
::
$app
->
request
->
get
(
'per-page'
,
10
);
$favorite
=
Favorite
::
findByUserId
(
Yii
::
$app
->
user
->
getId
(),
$page
,
$num
);
// var_dump($favorite);exit;
return
$this
->
render
(
'favorite'
,
[
'favorite'
=>
$favorite
]);
...
...
src/frontend/views/user-center/favorite.php
View file @
520e6928
...
...
@@ -5,118 +5,54 @@
* Date: 2016/9/27
* Time: 下午4:16
*/
use
\frontend\assets\AppAsset
;
use
yii\widgets\LinkPager
;
$
this
->
title
=
'收藏记录'
;
$
baseUrl
=
\yii\helpers\Url
::
base
()
;
$this
->
title
=
'收藏记录'
;
\frontend\assets\AppAsset
::
addScript
(
$this
,
'@web/assets/user_favorite.js'
)
?>
<div
class=
"cls-list-box"
>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/videoimg.jpg'
)
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"#"
>
英国为什么比中国先进入工业时代?
</a></div>
<div
class=
"price"
>
¥182.97
</div>
</div>
<div
class=
"outline"
>
<span>
购买日期:2016年9月12日 16:02
</span>
</div>
<div
class=
"avatar"
><img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/avatar2.jpg'
)
?>
"
></div>
<div
class=
"play-mask"
>
<a
href=
"#"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
</div>
</div>
</div>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/videoimg.jpg'
)
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"#"
>
英国为什么比中国先进入工业时代?
</a></div>
<div
class=
"price"
>
¥182.97
</div>
</div>
<div
class=
"outline"
>
<span>
购买日期:2016年9月12日 16:02
</span>
</div>
<div
class=
"avatar"
><img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/avatar2.jpg'
)
?>
"
></div>
<div
class=
"play-mask"
>
<a
href=
"#"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
</div>
</div>
</div>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/videoimg.jpg'
)
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"#"
>
英国为什么比中国先进入工业时代?
</a></div>
<div
class=
"price"
>
¥182.97
</div>
</div>
<div
class=
"outline"
>
<span>
购买日期:2016年9月12日 16:02
</span>
</div>
<div
class=
"avatar"
><img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/avatar2.jpg'
)
?>
"
></div>
<div
class=
"play-mask"
>
<a
href=
"#"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
</div>
</div>
</div>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/videoimg.jpg'
)
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"#"
>
英国为什么比中国先进入工业时代?
</a></div>
<div
class=
"price"
>
¥182.97
</div>
</div>
<div
class=
"outline"
>
<span>
购买日期:2016年9月12日 16:02
</span>
</div>
?>
<div
class=
"avatar"
><img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/avatar2.jpg'
)
?>
"
></div>
<div
class=
"cls-list-box clearfix"
>
<?php
foreach
(
$favorite
[
'data'
]
as
$key
=>
$value
)
:
?>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
Yii
::
$app
->
qiniu
->
getUrl
(
'public'
,
$value
[
'course'
][
'preview_pic'
])
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"
<?php
echo
$baseUrl
.
'/home/video?courseId='
.
$value
[
'course'
][
'id'
];
?>
"
>
<?=
$value
[
'course'
][
'name'
]
?>
</a></div>
<div
class=
"teacher"
>
讲师:
<?php
foreach
(
$value
[
'course'
][
'teachers'
]
as
$teaKey
=>
$teaValue
)
:
?>
<?php
if
(
$teaKey
>
0
)
:
?>
,
<?=
$teaValue
[
'name'
]
?>
<?php
else
:
?>
<?=
$teaValue
[
'name'
]
?>
<?php
endif
?>
<?php
endforeach
;
?>
</div>
<div
class=
"price"
>
<?=
$value
[
'course'
][
'price'
]
?>
</div>
</div>
<div
class=
"outline"
>
<span>
<?=
$value
[
'course'
][
'user'
][
'username'
]
?>
收藏了该内容
</span>
</div>
<div
class=
"play-mask"
>
<a
href=
"
<?php
echo
$baseUrl
.
'/home/video?courseId='
.
$value
[
'course'
][
'id'
];
?>
"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
<div
class=
"play-mask"
>
<a
href=
"#"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
</div>
</div>
</div>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main sm-box"
>
<div
class=
"video-img-box"
>
<img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/videoimg.jpg'
)
?>
"
>
<div
class=
"video-list-cnt"
>
<div
class=
"tit"
><a
href=
"#"
>
英国为什么比中国先进入工业时代?
</a></div>
<div
class=
"price"
>
¥182.97
</div>
</div>
<div
class=
"outline"
>
<span>
购买日期:2016年9月12日 16:02
</span>
</div>
<div
class=
"avatar"
><img
src=
"
<?=
AppAsset
::
getStaticUrl
(
'img/avatar2.jpg'
)
?>
"
></div>
<div
class=
"play-mask"
>
<a
href=
"#"
><i
class=
"glyphicon glyphicon-play"
></i></a>
</div>
<?php
endforeach
;
?>
</div>
</div>
</div>
</div>
<div
class=
"container text-center"
>
<?php
echo
LinkPager
::
widget
([
'pagination'
=>
$favorite
[
'pagination'
],
]);
?>
</div>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment