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
7efe5423
Commit
7efe5423
authored
Oct 15, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
课程列表分页
parent
254878f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
19 deletions
+32
-19
Course.php
src/common/models/Course.php
+24
-12
MyCourseController.php
src/frontend/controllers/MyCourseController.php
+2
-3
TeacherManagerController.php
src/frontend/controllers/TeacherManagerController.php
+1
-2
index.php
src/frontend/views/my-course/index.php
+5
-2
No files found.
src/common/models/Course.php
View file @
7efe5423
...
@@ -4,6 +4,7 @@ namespace common\models;
...
@@ -4,6 +4,7 @@ namespace common\models;
use
Yii
;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
yii\behaviors\TimestampBehavior
;
use
yii\data\Pagination
;
use
yii\helpers\HtmlPurifier
;
use
yii\helpers\HtmlPurifier
;
use
yii\redis\ActiveRecord
;
use
yii\redis\ActiveRecord
;
...
@@ -126,26 +127,37 @@ class Course extends \yii\db\ActiveRecord
...
@@ -126,26 +127,37 @@ class Course extends \yii\db\ActiveRecord
/**
/**
* 获取课程列表
* 获取课程列表
*
* @param int $classId
* @param int $classId
* @param int $page 从0开始
* @param int $page 从0开始
,如果传入null则使用系统分页机制,并返回 pagination 对象
* @param int $num
* @param int $num
* @param int $status 要获取的状态,null代表获取全部,默认为只获取审核通过的课程
* @return array
* @return array
*/
*/
public
static
function
getCourseListsByClassId
(
$classId
,
$page
=
0
,
$num
=
10
)
public
static
function
getCourseListsByClassId
(
$classId
,
$page
=
0
,
$num
=
10
,
$status
=
self
::
STATUS_OK
)
{
{
$
status
=
self
::
STATUS_OK
;
$
cond
=
[
'class_id'
=>
$classId
]
;
$
condition
=
"class_id=:class_id and status=
$status
"
;
$
status
!==
null
&&
$cond
[
'status'
]
=
$status
;
$params
=
[
':class_id'
=>
$classId
];
//获取总数
//获取总数
$count
=
self
::
find
()
->
where
(
$condition
,
$params
)
->
count
();
$count
=
self
::
find
()
->
where
(
$cond
)
->
count
();
$start
=
$page
*
$num
;
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
if
(
$page
===
null
)
{
$pagination
=
new
Pagination
([
'totalCount'
=>
$count
,
'pageSize'
=>
$num
,
'forcePageParam'
=>
false
]);
$offset
=
$pagination
->
offset
;
$return
[
'pagination'
]
=
$pagination
;
}
else
{
$offset
=
$page
*
$num
;
}
if
(
$count
>
0
)
{
if
(
$count
>
0
)
{
$data
=
self
::
find
()
->
select
(
'id,user_id,price,name,intro,preview_pic,recommend,play_count,comment_count,favorite_count,created_at'
)
->
where
(
$condition
,
$params
)
->
limit
(
$num
)
->
offset
(
$start
)
->
with
(
'teachers'
)
->
asArray
()
->
all
();
$return
[
'data'
]
=
self
::
find
()
->
select
(
'id,user_id,price,name,intro,preview_pic,recommend,play_count,comment_count,favorite_count,created_at'
)
->
where
(
$cond
)
->
limit
(
$num
)
->
offset
(
$offset
)
->
with
(
'teachers'
)
->
asArray
()
->
all
();
}
}
return
[
'count'
=>
$count
,
return
$return
;
'data'
=>
$data
];
}
}
/**
/**
...
...
src/frontend/controllers/MyCourseController.php
View file @
7efe5423
...
@@ -51,9 +51,8 @@ class MyCourseController extends \yii\web\Controller
...
@@ -51,9 +51,8 @@ class MyCourseController extends \yii\web\Controller
*/
*/
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$list
=
Course
::
getCourseListsByClassId
(
$this
->
classStatus
[
'id'
]);
$list
=
Course
::
getCourseListsByClassId
(
$this
->
classStatus
[
'id'
],
null
,
6
,
null
);
return
$this
->
render
(
'index'
,
[
'list'
=>
$list
[
'data'
],
'pagination'
=>
$list
[
'pagination'
]]);
return
$this
->
render
(
'index'
,
[
'list'
=>
$list
[
'data'
]]);
}
}
/**
/**
...
...
src/frontend/controllers/TeacherManagerController.php
View file @
7efe5423
...
@@ -42,8 +42,7 @@ class TeacherManagerController extends \yii\web\Controller
...
@@ -42,8 +42,7 @@ class TeacherManagerController extends \yii\web\Controller
*/
*/
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$data
=
Teacher
::
fetchTeachers
(
$this
->
classStatus
[
'id'
]);
$data
=
Teacher
::
fetchTeachers
(
$this
->
classStatus
[
'id'
],
0
,
100
);
return
$this
->
render
(
'index'
,
compact
(
'data'
));
return
$this
->
render
(
'index'
,
compact
(
'data'
));
}
}
...
...
src/frontend/views/my-course/index.php
View file @
7efe5423
...
@@ -2,8 +2,10 @@
...
@@ -2,8 +2,10 @@
/**
/**
* @var $this yii\web\View
* @var $this yii\web\View
* @var $list array
* @var $list array
* @var $pagination yii\data\Pagination
*/
*/
use
yii\helpers\Url
;
use
yii\helpers\Url
;
use
yii\widgets\LinkPager
;
$this
->
title
=
'课程列表'
;
$this
->
title
=
'课程列表'
;
...
@@ -12,7 +14,7 @@ $this->title = '课程列表';
...
@@ -12,7 +14,7 @@ $this->title = '课程列表';
*/
*/
$qiniu
=
\Yii
::
$app
->
qiniu
;
$qiniu
=
\Yii
::
$app
->
qiniu
;
?>
?>
<div
class=
"cls-list-box"
>
<div
class=
"cls-list-box
clearfix
"
>
<?php
foreach
(
$list
as
$course
)
{
?>
<?php
foreach
(
$list
as
$course
)
{
?>
<div
class=
"col-md-4"
>
<div
class=
"col-md-4"
>
<div
class=
"cls-box-main"
>
<div
class=
"cls-box-main"
>
...
@@ -33,4 +35,5 @@ $qiniu = \Yii::$app->qiniu;
...
@@ -33,4 +35,5 @@ $qiniu = \Yii::$app->qiniu;
</div>
</div>
</div>
</div>
<?php
}
?>
<?php
}
?>
</div>
</div>
\ No newline at end of file
<?=
LinkPager
::
widget
([
'pagination'
=>
$pagination
])
?>
\ No newline at end of file
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