通过邀请码加入课程

This commit is contained in:
cxt 2016-06-24 16:12:24 +08:00
parent 260759e4db
commit afc8fad7fd
5 changed files with 37 additions and 12 deletions

View File

@ -74,7 +74,7 @@ class CoursesController < ApplicationController
else
@state = 5 #未登录
end
@object_id = params[:object_id]
@object_id = @course.id if @course
respond_to do |format|
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
end

View File

@ -326,11 +326,7 @@ class CoursesService
#object_id课程id
#course_password :加入课程的密码
def join_course params,current_user
course = if params[:invite_code]
Course.find_by_invite_code(params[:invite_code])
else
Course.find_by_id params[:object_id]
end
course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code]
@state = 10
if course
@ -340,7 +336,7 @@ class CoursesService
if current_user.member_of_course?(course) #如果已经是成员
member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0]
roleName = member.roles[0].name if member
if params[:course_password] == course.password || params[:invite_code].present?
if params[:invite_code].present?
#如果加入角色为学生 并且当前是学生
if params[:role] == "10" && roleName == "Student"
@state = 3
@ -366,19 +362,19 @@ class CoursesService
elsif params[:role] == "10" && roleName != "Student"
member.role_ids = [params[:role]]
member.save
StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id])
StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id)
@state = 0
end
else
@state = 1
end
else
if params[:course_password] == course.password || params[:invite_code].present?
if params[:invite_code].present?
if params[:role] == "10" || params[:role] == nil
members = []
members << Member.new(:role_ids => [10], :user_id => current_user.id)
course.members << members
StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id])
StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id)
@state = 0
else
#如果已经发送过消息了,那么就要给个提示

View File

@ -63,7 +63,7 @@
<input type="text" style="display: none"/> <!--阻止表单自动填充 -->
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
<span class="tips" style="width: 90px; display: inline-block;">课程邀请码:</span>
<input class="width190" style="margin-left: 0px;" name="object_id" id="object_id" type="text" value="" >
<input class="width190" style="margin-left: 0px;" name="invite_code" id="object_id" type="text" value="" >
<input type="text" style="display: none"/>
</li>
<li class="mB5">课程邀请码是所在课程页面中显示的邀请码</li>

View File

@ -60,7 +60,7 @@
<% if (User.current.logged? && User.current.member_of_course?(@course)) || is_teacher %>
<div class="info_box mb10">
<p class="f14">邀请码</p>
<p class="f14 fontBlue2">123456</p>
<p class="f14 fontBlue2"><%=@course.generate_invite_code %></p>
</div>
<% end %>
<div class="info_box">

View File

@ -550,11 +550,13 @@ ActiveRecord::Schema.define(:version => 20160624032138) do
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
t.integer "syllabus_id"
t.string "invite_code"
t.string "qrcode"
end
add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true
add_index "courses", ["syllabus_id"], :name => "index_courses_on_syllabus_id"
create_table "custom_fields", :force => true do |t|
t.string "type", :limit => 30, :default => "", :null => false
@ -1123,6 +1125,23 @@ ActiveRecord::Schema.define(:version => 20160624032138) do
t.integer "viewed_count", :default => 0
end
create_table "mess", :id => false, :force => true do |t|
t.string "课程名"
t.integer "课程ID", :default => 0, :null => false
t.string "教师姓", :default => "", :null => false
t.string "教师名", :limit => 30, :default => "", :null => false
t.string "主贴名", :default => "", :null => false
t.integer "主贴或回帖ID", :default => 0, :null => false
t.integer "回帖对应主贴ID"
t.integer "帖子点赞数"
t.integer "主贴回复数", :default => 0, :null => false
t.text "主贴或回帖内容"
t.datetime "发帖时间", :null => false
t.integer "发帖或回帖用户ID", :default => 0, :null => false
t.string "发帖或回帖用户姓", :default => "", :null => false
t.string "发帖或回帖用户名", :limit => 30, :default => "", :null => false
end
create_table "message_alls", :force => true do |t|
t.integer "user_id"
t.integer "message_id"
@ -1830,6 +1849,16 @@ ActiveRecord::Schema.define(:version => 20160624032138) do
t.datetime "updated_at", :null => false
end
create_table "syllabuses", :force => true do |t|
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"
create_table "system_messages", :force => true do |t|
t.integer "user_id"
t.string "content"