diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index cbf8f4986..c4b445af9 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -118,6 +118,8 @@ module Mobile roles_ids << "10" end + go_course_group = 0 + if roles_ids.length <= 0 {status:-1,message:"请至少选择一个角色"} else @@ -125,7 +127,9 @@ module Mobile status = cs.join_course_roles({role: roles_ids, openid: params[:openid], invite_code: params[:invite_code]}, current_user) { status: status[:state], - message:CoursesService::JoinCourseError.message(status[:state]) + message:CoursesService::JoinCourseError.message(status[:state]), + go_coursegroup_flag:status[:go_coursegroup_flag], + course_id:status[:course_id] } end end @@ -537,6 +541,7 @@ module Mobile present :course_id,params[:id] present :user_id,params[:user_id] present :member_info,my_member, with: Mobile::Entities::ProjectMember + present :course_group_id,my_member.course_group_id present :status, 0 else present :status, -1 @@ -750,6 +755,168 @@ module Mobile end out.merge(message: message) end + + desc '获取分班列表' + params do + requires :id, type: Integer + requires :token, type:String + end + get 'course_groups/:id' do + begin + authenticate! + course = Course.find(params[:id]) + groups = [] + groups = course.course_groups if course.course_groups + present :data,groups + present :status,0 + rescue + present :status,-1 + end + end + + desc "加入分班" + params do + requires :id, type: Integer + requires :token, type: String + requires :course_group_id, type: Integer + end + post 'user_join_coursegroup' do + begin + authenticate! + member = Member.where(:course_id => params[:id], :user_id => current_user.id).first + + raise "你还不是该班级的学生!" unless member + + member.course_group_id = params[:course_group_id].to_i + member.save + present :status,0 + rescue Exception=>e + present :message,e.message + present :status,-1 + end + end + + desc "修改分班" + params do + requires :id, type: Integer + requires :token, type: String + requires :course_group_id, type: Integer + requires :user_id, type: Integer + end + post 'user_edit_coursegroup' do + begin + authenticate! + member = Member.where(:course_id => params[:id], :user_id => params[:user_id]).first + + raise "不是该班级的学生!" unless member + + member.course_group_id = params[:course_group_id].to_i + member.save + present :status,0 + rescue Exception=>e + present :message,e.message + present :status,-1 + end + end + + desc '获取分班列表带上学生' + params do + requires :id, type: Integer + requires :token, type:String + end + get 'course_groups_withstudent/:id' do + begin + authenticate! + course = Course.find(params[:id]) + groups = [] + groups = course.course_groups if course.course_groups + present :data,groups, with: Mobile::Entities::CourseGroup + present :status,0 + rescue + present :status,-1 + end + end + + desc "删除分班" + params do + requires :id, type: Integer + requires :token, type: String + requires :course_group_id, type: Integer + end + post 'delete_coursegroup' do + begin + authenticate! + c = Course.find("#{params[:id]}") + my_member = c.member_principals.where("users.id=#{current_user.id}").first + + roles_ids = [] + my_member.roles.each do |role| + roles_ids << role.id + end + + if my_member && (roles_ids.include?(3) || roles_ids.include?(7) || roles_ids.include?(9) ) + else + raise "您没有该权限!" + end + CourseGroup.delete(params[:course_group_id]) + present :status,0 + rescue Exception=>e + present :message,e.message + present :status,-1 + end + end + + + desc "编辑分班" + params do + requires :id, type: Integer + requires :token, type: String + end + post 'edit_coursegroup' do + begin + authenticate! + c = Course.find("#{params[:id]}") + my_member = c.member_principals.where("users.id=#{current_user.id}").first + + roles_ids = [] + my_member.roles.each do |role| + roles_ids << role.id + end + + if my_member && (roles_ids.include?(3) || roles_ids.include?(7) || roles_ids.include?(9) ) + else + raise "您没有该权限!" + end + + #增加分班和修改分班名 + modify_groups = params[:modify_groups] + modify_groups.each do |g| + group = CourseGroup.find(g.id) + group.name = g.id.to_s + Time.now.to_i.to_s #只能先另取个名了不然原有的两个互换的话修改不了 + group.save + end + + modify_groups.each do |g| + group = CourseGroup.find(g.id) + group.name = g.name + group.save + end + + #增加分班和修改分班名 + add_groups = params[:add_groups] + add_groups.each do |name| + group = CourseGroup.new + group.name = name + group.course_id = params[:id] + group.save + end + present :status,0 + rescue Exception=>e + present :message,e.message + present :status,-1 + end + end + end end end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 8200c04b2..0eda2d1c0 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -23,6 +23,8 @@ module Mobile (number_to_human_size(f.filesize)).gsub("ytes", "").to_s when :coursename f.course.nil? ? "" : f.course.name + when :syllabus_title + f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title when :course_id f.course.nil? ? 0 : f.course.id @@ -40,6 +42,7 @@ module Mobile attachment_expose :file_dir attachment_expose :attafile_size attachment_expose :coursename #所属班级名 + attachment_expose :syllabus_title #所属班级名 attachment_expose :course_id #所属班级名 expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 30a5a6cc9..1b696e40c 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -54,6 +54,7 @@ module Mobile course_expose :updated_at course_expose :course_student_num course_expose :member_count + course_expose :groupnum expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] can_setting = false diff --git a/app/api/mobile/entities/course_group.rb b/app/api/mobile/entities/course_group.rb new file mode 100644 index 000000000..f5d05d44c --- /dev/null +++ b/app/api/mobile/entities/course_group.rb @@ -0,0 +1,19 @@ +module Mobile + module Entities + class CourseGroup < Grape::Entity + include Redmine::I18n + include ApplicationHelper + include ApiHelper + def self.course_group_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + end + end + end + expose :id + expose :name + expose :users, using: Mobile::Entities::User + end + end +end diff --git a/app/api/mobile/entities/exercise.rb b/app/api/mobile/entities/exercise.rb index ce6a2fb39..821380b47 100644 --- a/app/api/mobile/entities/exercise.rb +++ b/app/api/mobile/entities/exercise.rb @@ -19,6 +19,8 @@ module Mobile case field when :coursename f.course.nil? ? "" : f.course.name + when :syllabus_title + f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title end end end @@ -27,6 +29,7 @@ module Mobile expose :exercise_name expose :exercise_description exercise_expose :coursename #所属班级名 + exercise_expose :syllabus_title expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index a5b981c6d..d149681e4 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -39,6 +39,8 @@ module Mobile val when :coursename f.course.nil? ? "" : f.course.name + when :syllabus_title + f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title end end end @@ -49,6 +51,8 @@ module Mobile #课程名称 homework_expose :course_name + homework_expose :syllabus_title + homework_expose :course_id #作业发布者 expose :author,using: Mobile::Entities::User do |f, opt| diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index 07c560a1f..189b52851 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -22,6 +22,10 @@ module Mobile else u.project.name end + when :syllabus_title + if u.board.project_id == -1 + u.course.syllabus.nil? ? "" : u.course.syllabus.title + end when :lasted_comment time_from_now u.created_on when :praise_count @@ -50,6 +54,7 @@ module Mobile message_expose :act_type message_expose :act_id message_expose :course_project_name + message_expose :syllabus_title message_expose :board_id message_expose :subject message_expose :title diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index d8c4dcab3..4515791cd 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -26,6 +26,11 @@ module Mobile f.id when :comment_count f.comments.count + when :syllabus_title + unless f.course_id == nil + course = get_course(f.course_id) + course.syllabus.nil? ? "" : course.syllabus.title + end end end elsif f.is_a?(::Comment) @@ -89,6 +94,7 @@ module Mobile news_expose :praise_count #课程名字 news_expose :course_name + news_expose :syllabus_title news_expose :lasted_comment #评论 diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 30a2a7edd..09ef6a599 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -36,6 +36,8 @@ module Mobile u.lastname when :mail u.mail + when :is_me + defined? u.is_me ? u.is_me : 0 end end end @@ -77,6 +79,8 @@ module Mobile user_expose :name + user_expose :is_me + end end diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb index 9d141552a..b19d34f05 100644 --- a/app/api/mobile/entities/whomework.rb +++ b/app/api/mobile/entities/whomework.rb @@ -30,6 +30,8 @@ module Mobile wh.journals_for_messages.count when :course_name wh.course.name + when :syllabus_title + wh.course.syllabus.nil? ? "" : wh.course.syllabus.title when :act_type 'HomeworkCommon' when :act_id @@ -65,6 +67,7 @@ module Mobile whomework_expose :act_type whomework_expose :act_id whomework_expose :course_name + whomework_expose :syllabus_title whomework_expose :created_at whomework_expose :absence_penalty whomework_expose :evaluation_start diff --git a/app/models/course.rb b/app/models/course.rb index 659f9fcec..cc80a1b4b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -495,10 +495,11 @@ class Course < ActiveRecord::Base def generate_qrcode ticket = self.qrcode - if !ticket || ticket.size < 10 + if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime) response = Wechat.api.qrcode_create_scene(invite_code, 2592000) logger.debug "response = #{response}" self.qrcode = response['ticket'] + self.qrcode_expiretime = Time.now.to_i+response['expire_seconds'] save! && reload ticket = qrcode end diff --git a/app/models/project.rb b/app/models/project.rb index 0d297bb3c..e80306036 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -930,10 +930,11 @@ class Project < ActiveRecord::Base def generate_qrcode ticket = self.qrcode - if !ticket || ticket.size < 10 + if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime) response = Wechat.api.qrcode_create_scene(invite_code, 2592000) logger.debug "response = #{response}" self.qrcode = response['ticket'] + self.qrcode_expiretime = Time.now.to_i+response['expire_seconds'] save! ticket = qrcode end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 5add9979d..b97fa1a64 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -115,7 +115,7 @@ class CoursesService role_name: m.roles.first.name, name: m.user.show_name, roles_id: role_ids.include?(7) ? 7 : (role_ids.include?(9) ? 9 : 10 ), - :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} + :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname,:is_me => current_user.id == m.user.id ? 1:0 } # end end @@ -332,7 +332,9 @@ class CoursesService # unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) # raise '403' # end - {:course => course,:syllabus_title => course.syllabus.nil? ? "":course.syllabus.title ,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.nil? ? false : current_user.member_of_course?(course),:current_user_is_teacher => current_user.nil? ? false : is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0} + groupnum = 0 + groupnum = course.course_groups.length if course.course_groups + {:course => course,:syllabus_title => course.syllabus.nil? ? "":course.syllabus.title ,:work_unit => work_unit, :img_url => "/images/"+url_to_avatar(course),:current_user_is_member => current_user.nil? ? false : current_user.member_of_course?(course),:current_user_is_teacher => current_user.nil? ? false : is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0,:groupnum => groupnum} end #创建课程 @@ -565,6 +567,8 @@ class CoursesService #多个角色加入课程 def join_course_roles params,current_user course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code] + go_coursegroup_flag = 0 + course_id = 0 @state = 10 if course @@ -621,6 +625,8 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 + go_coursegroup_flag = 1 if course.course_groups + course_id = course.id send_wechat_join_class_notice current_user,course,10,0 else is_stu = false @@ -630,6 +636,8 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id =>course.id) is_stu = true + go_coursegroup_flag = 1 if course.course_groups + course_id = course.id send_wechat_join_class_notice current_user,course,10,0 end #如果已经发送过消息了,那么就要给个提示 @@ -674,7 +682,7 @@ class CoursesService else @state = 4 end - {:state => @state,:course => course} + {:state => @state,:course => course,:go_coursegroup_flag => go_coursegroup_flag,:course_id=>course_id} end diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index c4df9e715..bf4cf9e76 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -43,7 +43,7 @@ 第<%= work.student_work_tests.count - index%>次测试
- <%= test.created_at.to_s(:db) %> + <%= format_time(test.created_at).to_s %> diff --git a/db/migrate/20160918024056_add_qrcode_expiretime_to_courses.rb b/db/migrate/20160918024056_add_qrcode_expiretime_to_courses.rb new file mode 100644 index 000000000..17d8548cc --- /dev/null +++ b/db/migrate/20160918024056_add_qrcode_expiretime_to_courses.rb @@ -0,0 +1,5 @@ +class AddQrcodeExpiretimeToCourses < ActiveRecord::Migration + def change + add_column :courses, :qrcode_expiretime, :integer, :default => 0 + end +end diff --git a/db/migrate/20160918024214_add_qrcode_expiretime_to_projects.rb b/db/migrate/20160918024214_add_qrcode_expiretime_to_projects.rb new file mode 100644 index 000000000..870917443 --- /dev/null +++ b/db/migrate/20160918024214_add_qrcode_expiretime_to_projects.rb @@ -0,0 +1,5 @@ +class AddQrcodeExpiretimeToProjects < ActiveRecord::Migration + def change + add_column :projects, :qrcode_expiretime, :integer, :default => 0 + end +end diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index 2d45f4d17..09490b766 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -40,7 +40,7 @@ - +