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
4ef20052
Commit
4ef20052
authored
Oct 14, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
移除 class_teacher 关联,关联放入 teachers 表
相应调整 添加讲师功能完成 添加讲师地址统一
parent
78a2c50a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
137 additions
and
195 deletions
+137
-195
ClassesTeacher.php
src/common/models/ClassesTeacher.php
+0
-136
Teacher.php
src/common/models/Teacher.php
+68
-13
UploadPools.php
src/common/models/UploadPools.php
+10
-0
MyCourseController.php
src/frontend/controllers/MyCourseController.php
+2
-2
TeacherManagerController.php
src/frontend/controllers/TeacherManagerController.php
+22
-39
avatar-upload.vue
src/frontend/web/js/components/uploader/avatar-upload.vue
+10
-4
publish.js
src/frontend/web/js/my-course/publish.js
+2
-1
add.js
src/frontend/web/js/teacher-manager/add.js
+23
-0
No files found.
src/common/models/ClassesTeacher.php
deleted
100644 → 0
View file @
78a2c50a
<?php
namespace
common\models
;
use
Yii
;
use
yii\data\ActiveDataProvider
;
use
yii\db\ActiveRecord
;
/**
* This is the model class for table "classes_teacher".
*
* @property integer $class_id
* @property integer $teacher_id
*/
class
ClassesTeacher
extends
\yii\db\ActiveRecord
{
public
static
$lastErrors
;
/**
* @inheritdoc
*/
public
static
function
tableName
()
{
return
'classes_teacher'
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'class_id'
,
'teacher_id'
],
'required'
],
[[
'class_id'
,
'teacher_id'
],
'integer'
],
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'class_id'
=>
'Class ID'
,
'teacher_id'
=>
'Teacher ID'
,
];
}
/**
* 添加课堂与讲师关联
*
* @param $classId
* @param $teacherId
* @return bool
*/
public
static
function
makeRelation
(
$classId
,
$teacherId
)
{
$model
=
new
self
();
$model
->
teacher_id
=
$teacherId
;
$model
->
class_id
=
$classId
;
if
(
$model
->
save
())
{
return
true
;
}
else
{
self
::
$lastErrors
=
$model
->
errors
;
return
false
;
}
}
/**
* 获取指定课堂下所有讲师的简单列表
*
* ID,头像,昵称
*
* @param $classId
* @return array
*/
public
static
function
fetchTeacherNames
(
$classId
)
{
$obj
=
self
::
find
();
$teacherTable
=
Teacher
::
tableName
();
return
$obj
->
select
(
't.id,t.user_id,t.name,t.avatar'
)
->
join
(
'LEFT JOIN'
,
$teacherTable
.
' t'
,
't.id=c.teacher_id'
)
->
from
(
self
::
tableName
()
.
' c'
)
->
where
([
'c.class_id'
=>
$classId
])
->
asArray
()
->
all
();
}
/**
* 过滤出课堂拥有的讲师ID列表
*
* @param int $classId
* @param array $teacherIds 讲师ID列表数组
* @return array 返回只有传入指定课堂ID拥有的讲师ID列表
*/
public
static
function
filterOwnTeacherIds
(
$classId
,
$teacherIds
)
{
$query
=
self
::
find
();
$result
=
$query
->
select
(
'teacher_id'
)
->
where
([
'class_id'
=>
$classId
,
'teacher_id'
=>
$teacherIds
])
->
all
();
$ids
=
[];
if
(
$result
)
{
foreach
(
$result
as
$row
)
{
$ids
[]
=
$row
->
teacher_id
;
}
}
return
$ids
;
}
/**
* @param $classId
* @param int $page
* @param int $pageSize
* @return array
*/
public
static
function
fetchTeachers
(
$classId
,
$page
=
0
,
$pageSize
=
10
)
{
$query
=
Teacher
::
find
()
->
alias
(
't'
)
->
select
(
't.id,t.user_id,t.name,t.avatar,t.intro'
)
->
join
(
'LEFT JOIN'
,
self
::
tableName
()
.
' c'
,
't.id=c.teacher_id'
)
->
where
([
'c.class_id'
=>
$classId
])
->
orderBy
([
'c.teacher_id'
=>
SORT_DESC
])
->
asArray
();
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'pagination'
=>
[
'page'
=>
$page
,
'pageSize'
=>
$pageSize
]
]);
$data
=
$provider
->
getModels
();
return
$data
;
}
}
src/common/models/Teacher.php
View file @
4ef20052
...
@@ -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\ActiveDataProvider
;
use
yii\db\ActiveRecord
;
use
yii\db\ActiveRecord
;
/**
/**
...
@@ -11,6 +12,7 @@ use yii\db\ActiveRecord;
...
@@ -11,6 +12,7 @@ use yii\db\ActiveRecord;
*
*
* @property integer $id
* @property integer $id
* @property integer $user_id
* @property integer $user_id
* @property integer $class_id
* @property string $name
* @property string $name
* @property string $avatar
* @property string $avatar
* @property string $intro
* @property string $intro
...
@@ -30,13 +32,17 @@ class Teacher extends ActiveRecord
...
@@ -30,13 +32,17 @@ class Teacher extends ActiveRecord
return
'teacher'
;
return
'teacher'
;
}
}
public
function
formName
()
{
return
''
;
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'
user_id'
,
'name'
,
'avatar'
,
'intro
'
],
'required'
],
[[
'
name'
,
'class_id
'
],
'required'
],
[[
'user_id'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'user_id'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'intro'
],
'string'
],
[[
'intro'
],
'string'
],
[[
'name'
],
'string'
,
'min'
=>
2
,
'max'
=>
64
],
[[
'name'
],
'string'
,
'min'
=>
2
,
'max'
=>
64
],
...
@@ -78,19 +84,68 @@ class Teacher extends ActiveRecord
...
@@ -78,19 +84,68 @@ class Teacher extends ActiveRecord
];
];
}
}
public
static
function
simpleAddTeacher
(
$name
)
/**
* 获取指定课堂下所有讲师的简单列表
*
* ID,头像,昵称
*
* @param $classId
* @return array
*/
public
static
function
fetchTeacherNames
(
$classId
)
{
{
$model
=
new
self
();
$obj
=
self
::
find
();
$model
->
user_id
=
0
;
//$teacherTable = Teacher::tableName();
$model
->
name
=
$name
;
//return $obj->select('t.id,t.user_id,t.name,t.avatar')->join('LEFT JOIN', $teacherTable.' t', 't.id=c.teacher_id')
//$model->avatar = 'avatar/f6/98/c6/_tjy7DgC0641.jpg';
// ->from(self::tableName().' c')->where(['c.class_id'=>$classId])->asArray()->all();
$model
->
intro
=
'这个家伙很懒,什么也没有写。'
;
return
$obj
->
select
(
'id,user_id,name,avatar'
)
->
where
([
'class_id'
=>
$classId
])
->
asArray
()
->
all
();
if
(
$model
->
save
())
{
return
$model
->
toArray
();
}
else
{
self
::
$lastErrors
=
$model
->
errors
;
return
false
;
}
}
/**
* 过滤出课堂拥有的讲师ID列表
*
* @param int $classId
* @param array $teacherIds 讲师ID列表数组
* @return array 返回只有传入指定课堂ID拥有的讲师ID列表
*/
public
static
function
filterOwnTeacherIds
(
$classId
,
$teacherIds
)
{
$result
=
self
::
find
()
->
select
(
'id'
)
->
where
([
'class_id'
=>
$classId
,
'id'
=>
$teacherIds
])
->
all
();
$ids
=
[];
if
(
$result
)
{
foreach
(
$result
as
$row
)
{
$ids
[]
=
$row
->
id
;
}
}
}
return
$ids
;
}
/**
* @param $classId
* @param int $page
* @param int $pageSize
* @return array
*/
public
static
function
fetchTeachers
(
$classId
,
$page
=
0
,
$pageSize
=
10
)
{
$query
=
self
::
find
()
->
select
(
'id,user_id,name,avatar,intro'
)
->
where
([
'class_id'
=>
$classId
])
->
orderBy
([
'id'
=>
SORT_DESC
])
->
asArray
();
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'pagination'
=>
[
'page'
=>
$page
,
'pageSize'
=>
$pageSize
]
]);
$data
=
$provider
->
getModels
();
return
$data
;
}
}
}
src/common/models/UploadPools.php
View file @
4ef20052
...
@@ -82,6 +82,16 @@ class UploadPools extends ActiveRecord
...
@@ -82,6 +82,16 @@ class UploadPools extends ActiveRecord
*
*
* @param string $uuid 文件 uuid
* @param string $uuid 文件 uuid
* @return array|false 认领成功返回文件信息,认领失败返回 false
* @return array|false 认领成功返回文件信息,认领失败返回 false
* 成功返回信息如: [
* 'uuid' => '679c43d5-c454-4d80-9c1b-f0a5cae8bd34',
* 'skey' => 'public:preview/30/27/3e/ZuofZkkK5721.jpg',
* 'filesize' => '697118',
* 'w' => '1920',
* 'h' => '1200',
* 'upload_time' => '1475985441',
* 'storage' => 'public',
* 'key' => 'preview/30/27/3e/ZuofZkkK5721.jpg'
* ]
*/
*/
public
static
function
claimFile
(
$uuid
)
public
static
function
claimFile
(
$uuid
)
{
{
...
...
src/frontend/controllers/MyCourseController.php
View file @
4ef20052
...
@@ -3,10 +3,10 @@ namespace frontend\controllers;
...
@@ -3,10 +3,10 @@ namespace frontend\controllers;
use
common\libs\Utils
;
use
common\libs\Utils
;
use
common\models\AttachUploadForm
;
use
common\models\AttachUploadForm
;
use
common\models\ClassesTeacher
;
use
common\models\Course
;
use
common\models\Course
;
use
common\models\CourseTeacher
;
use
common\models\CourseTeacher
;
use
common\models\Courseware
;
use
common\models\Courseware
;
use
common\models\Teacher
;
use
common\models\UploadPools
;
use
common\models\UploadPools
;
use
frontend\components\ClassesFilter
;
use
frontend\components\ClassesFilter
;
use
Qiniu\Storage\BucketManager
;
use
Qiniu\Storage\BucketManager
;
...
@@ -125,7 +125,7 @@ class MyCourseController extends \yii\web\Controller
...
@@ -125,7 +125,7 @@ class MyCourseController extends \yii\web\Controller
//过滤已拥有的讲师列表
//过滤已拥有的讲师列表
$teacherIds
=
$request
->
post
(
'teacher'
,
[]);
$teacherIds
=
$request
->
post
(
'teacher'
,
[]);
$teacherIds
=
Classes
Teacher
::
filterOwnTeacherIds
(
$classId
,
$teacherIds
);
$teacherIds
=
Teacher
::
filterOwnTeacherIds
(
$classId
,
$teacherIds
);
//课件数据
//课件数据
$vuid
=
$request
->
post
(
'vuid'
);
$vuid
=
$request
->
post
(
'vuid'
);
...
...
src/frontend/controllers/TeacherManagerController.php
View file @
4ef20052
...
@@ -3,12 +3,13 @@
...
@@ -3,12 +3,13 @@
namespace
frontend\controllers
;
namespace
frontend\controllers
;
use
common\components\Qiniu
;
use
common\components\Qiniu
;
use
common\libs\Utils
;
use
common\models\Teacher
;
use
common\models\Teacher
;
use
common\models\ClassesTeacher
;
use
common\models\ClassesTeacher
;
use
common\models\UploadPools
;
use
frontend\components\ClassesFilter
;
use
frontend\components\ClassesFilter
;
use
Yii
;
use
Yii
;
use
yii\filters\AccessControl
;
use
yii\filters\AccessControl
;
use
yii\helpers\Html
;
class
TeacherManagerController
extends
\yii\web\Controller
class
TeacherManagerController
extends
\yii\web\Controller
{
{
...
@@ -41,7 +42,7 @@ class TeacherManagerController extends \yii\web\Controller
...
@@ -41,7 +42,7 @@ class TeacherManagerController extends \yii\web\Controller
*/
*/
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$data
=
Classes
Teacher
::
fetchTeachers
(
$this
->
classStatus
[
'id'
]);
$data
=
Teacher
::
fetchTeachers
(
$this
->
classStatus
[
'id'
]);
return
$this
->
render
(
'index'
,
compact
(
'data'
));
return
$this
->
render
(
'index'
,
compact
(
'data'
));
}
}
...
@@ -57,12 +58,26 @@ class TeacherManagerController extends \yii\web\Controller
...
@@ -57,12 +58,26 @@ class TeacherManagerController extends \yii\web\Controller
if
(
Yii
::
$app
->
request
->
getIsPost
())
{
if
(
Yii
::
$app
->
request
->
getIsPost
())
{
$model
->
load
(
Yii
::
$app
->
request
->
post
());
$model
->
load
(
Yii
::
$app
->
request
->
post
());
$model
->
class_id
=
$this
->
classStatus
[
'id'
];
if
(
$model
->
validate
())
{
//认领头像文件
if
(
$model
->
avatar
)
{
$avatar
=
UploadPools
::
claimFile
(
$model
->
avatar
);
if
(
$avatar
)
{
$model
->
avatar
=
$avatar
[
'key'
];
}
else
{
}
else
{
$model
->
addError
(
'avatar'
,
'上传的头像不存在'
);
}
}
if
(
$model
->
validate
()
&&
$model
->
save
())
{
Utils
::
ajaxResponse
(
true
,
null
,
$model
->
toArray
());
}
else
{
Utils
::
ajaxResponse
(
false
,
Utils
::
fetchErrorFirst
(
$model
->
errors
));
}
}
return
;
}
}
/**
/**
...
@@ -84,40 +99,8 @@ class TeacherManagerController extends \yii\web\Controller
...
@@ -84,40 +99,8 @@ class TeacherManagerController extends \yii\web\Controller
$response
=
\Yii
::
$app
->
response
;
$response
=
\Yii
::
$app
->
response
;
$response
->
format
=
\yii\web\Response
::
FORMAT_JSON
;
$response
->
format
=
\yii\web\Response
::
FORMAT_JSON
;
return
Classes
Teacher
::
fetchTeacherNames
(
$classId
);
return
Teacher
::
fetchTeacherNames
(
$classId
);
}
}
/**
* 添加讲师
*/
public
function
actionAddTeacher
()
{
//Todo: 假设数据
$uid
=
Yii
::
$app
->
user
->
identity
->
getId
();;
$classId
=
$this
->
classStatus
[
'id'
];
$response
=
Yii
::
$app
->
response
;
$response
->
format
=
\yii\web\Response
::
FORMAT_JSON
;
$name
=
Html
::
encode
(
Yii
::
$app
->
request
->
post
(
'name'
));
$teacher
=
Teacher
::
simpleAddTeacher
(
$name
);
if
(
$teacher
)
{
ClassesTeacher
::
makeRelation
(
$classId
,
$teacher
[
'id'
]);
return
[
'teacher_id'
=>
$teacher
[
'id'
],
'name'
=>
$teacher
[
'name'
]
];
}
else
{
return
[
'error'
=>
join
(
"
\\
n"
,
Teacher
::
$lastErrors
)];
}
}
public
function
actionTest
()
{
$data
=
ClassesTeacher
::
getTeachers
(
1
);
print_r
(
$data
);
}
}
}
src/frontend/web/js/components/uploader/avatar-upload.vue
View file @
4ef20052
<
template
>
<
template
>
<div
class=
"upload-avatar"
:id=
"uploaderId"
>
<div
class=
"upload-avatar"
:id=
"uploaderId"
style=
"cursor:pointer;"
>
<i
class=
"icon-image"
></i>
<i
class=
"icon-image"
></i>
<p>
{{
text
}}
</p>
<p>
{{
text
}}
</p>
</div>
</div>
...
@@ -23,6 +23,7 @@ export default {
...
@@ -23,6 +23,7 @@ export default {
uptoken
:
String
uptoken
:
String
},
},
ready
()
{
ready
()
{
var
self
=
this
;
this
.
text
=
defaultText
;
this
.
text
=
defaultText
;
var
uploader
=
new
qiniu
.
Uploader
({
var
uploader
=
new
qiniu
.
Uploader
({
...
@@ -30,7 +31,7 @@ export default {
...
@@ -30,7 +31,7 @@ export default {
drop_element
:
self
.
uploaderId
,
drop_element
:
self
.
uploaderId
,
upload_token
:
self
.
uptoken
,
upload_token
:
self
.
uptoken
,
filters
:
{
filters
:
{
max_file_size
:
'
5
mb'
,
max_file_size
:
'
3
mb'
,
mime_types
:
[
mime_types
:
[
{
title
:
"图片文件"
,
extensions
:
"jpg,jpeg,gif,png"
}
{
title
:
"图片文件"
,
extensions
:
"jpg,jpeg,gif,png"
}
]
]
...
@@ -54,7 +55,7 @@ export default {
...
@@ -54,7 +55,7 @@ export default {
'BeforeUpload'
:
function
(
up
,
file
)
{
'BeforeUpload'
:
function
(
up
,
file
)
{
},
},
'UploadProgress'
:
function
(
up
,
file
)
{
'UploadProgress'
:
function
(
up
,
file
)
{
self
.
text
=
"上传中.."
+
file
.
percent
+
"%"
;
self
.
text
=
file
.
percent
+
"%"
;
},
},
//每个文件上传成功后
//每个文件上传成功后
'FileUploaded'
:
function
(
up
,
file
,
info
)
{
'FileUploaded'
:
function
(
up
,
file
,
info
)
{
...
@@ -65,7 +66,9 @@ export default {
...
@@ -65,7 +66,9 @@ export default {
},
1000
);
},
1000
);
var
response
=
$
.
parseJSON
(
info
.
response
);
var
response
=
$
.
parseJSON
(
info
.
response
);
self
.
$dispatch
(
"thumb-uploaded"
,
file
.
name
,
response
);
$
(
"#"
+
self
.
uploaderId
).
html
(
'<img src="'
+
response
.
src
+
'-m.avatar">'
);
self
.
$dispatch
(
"avatar-uploaded"
,
file
.
name
,
response
);
},
},
'Error'
:
function
(
up
,
err
)
{
'Error'
:
function
(
up
,
err
)
{
var
msg
=
""
;
var
msg
=
""
;
...
@@ -81,9 +84,12 @@ export default {
...
@@ -81,9 +84,12 @@ export default {
//队列文件处理完毕后
//队列文件处理完毕后
'UploadComplete'
:
function
()
{
'UploadComplete'
:
function
()
{
self
.
state
=
'completed'
;
self
.
state
=
'completed'
;
uploader
.
disableBrowse
();
}
}
}
}
});
});
uploader
.
init
();
}
}
}
}
...
...
src/frontend/web/js/my-course/publish.js
View file @
4ef20052
...
@@ -51,7 +51,7 @@ var vm = new Vue({
...
@@ -51,7 +51,7 @@ var vm = new Vue({
var
self
=
this
;
var
self
=
this
;
//添加讲师
//添加讲师
$
.
post
(
"/teacher-manager/add
-teacher
"
,
{
$
.
post
(
"/teacher-manager/add"
,
{
name
:
self
.
addTeacherName
name
:
self
.
addTeacherName
},
function
(
t
)
{
},
function
(
t
)
{
if
(
!
t
.
error
)
{
if
(
!
t
.
error
)
{
...
@@ -149,6 +149,7 @@ var vm = new Vue({
...
@@ -149,6 +149,7 @@ var vm = new Vue({
location
.
replace
(
"/my-course/result?id="
+
t
.
data
.
course_id
+
"&action=publish"
);
location
.
replace
(
"/my-course/result?id="
+
t
.
data
.
course_id
+
"&action=publish"
);
}
else
{
}
else
{
alert
(
t
.
message
);
alert
(
t
.
message
);
layer
.
alert
(
t
.
message
,
{
icon
:
5
,
title
:
"提示"
});
}
}
},
"json"
);
},
"json"
);
...
...
src/frontend/web/js/teacher-manager/add.js
View file @
4ef20052
...
@@ -13,6 +13,7 @@ var vm = new Vue({
...
@@ -13,6 +13,7 @@ var vm = new Vue({
"avatar-upload"
:
avatarUploader
"avatar-upload"
:
avatarUploader
},
},
ready
:
function
()
{
ready
:
function
()
{
var
self
=
this
;
var
form
=
document
.
forms
[
"teacher"
];
var
form
=
document
.
forms
[
"teacher"
];
$
(
form
).
submit
(
function
()
{
$
(
form
).
submit
(
function
()
{
...
@@ -24,7 +25,29 @@ var vm = new Vue({
...
@@ -24,7 +25,29 @@ var vm = new Vue({
return
false
;
return
false
;
}
}
var
idx
=
layer
.
msg
(
"正在提交.."
,
{
icon
:
16
,
shade
:[
0.2
,
'#000'
],
time
:
0
});
$
.
post
(
"/teacher-manager/add"
,
$
(
form
).
serialize
(),
function
(
t
)
{
layer
.
close
(
idx
);
if
(
t
.
status
)
{
layer
.
msg
(
'添加成功'
,
{
time
:
2000
,
icon
:
1
,
end
:
function
()
{
location
.
href
=
"/teacher-manager/"
;
},
shade
:[
0.2
,
'#000'
]
});
}
else
{
layer
.
alert
(
t
.
message
,
{
icon
:
5
,
title
:
"添加失败"
});
}
},
"json"
);
return
false
;
return
false
;
});
});
this
.
$on
(
"avatar-uploaded"
,
function
(
name
,
data
)
{
self
.
avatar
=
data
.
uuid
;
});
}
}
});
});
\ 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