diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 301417781..5908ef866 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -17,7 +17,7 @@ module Mobile authenticate! cs = CoursesService.new courses = cs.user_courses_list(current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -56,7 +56,7 @@ module Mobile class_period: params[:class_period] } courses = cs.create_course(cs_params, current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -90,7 +90,7 @@ module Mobile end cs.edit_course_authorize(current_user,course) course = cs.edit_course(cs_params, course,current_user) - present :data, course, with: Mobile::Entities::Course + present :data, course, with: Mobile::Entities::Course,user: current_user present :status, 0 end post do @@ -138,7 +138,7 @@ module Mobile get 'search' do cs = CoursesService.new courses = cs.search_course(params,current_user.nil? ? User.find(2):current_user) - present :data, courses, with: Mobile::Entities::Course + present :data, courses, with: Mobile::Entities::Course,user: current_user present :status, 0 end @@ -201,7 +201,7 @@ module Mobile cs = CoursesService.new course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user)) #course = Course.find(params[:id]) - present :data, course, with: Mobile::Entities::Course + present :data, course, with: Mobile::Entities::Course,user: current_user { status: 0} end end @@ -391,7 +391,12 @@ module Mobile end get ':course_id/exercises' do authenticate! - exercises = Course.find(params[:course_id]).exercises + + course = Course.find(params[:course_id]) + exercises = course.exercises + exercises.each do |v| + v[:coursename] = course.nil? ? "未知" : course.name + end present :data,exercises,with:Mobile::Entities::Exercise present :status,0 end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index 6dfe8e599..16531940f 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -11,8 +11,10 @@ module Mobile end get do authenticate! - data = current_user.course_attachments - present :data, data, with: Mobile::Entities::Attachment + rs = ResourcesService.new + # data = current_user.course_attachments + data = rs.all_course_attachments current_user + present :data, data, with: Mobile::Entities::Attachment,user: current_user present :status, 0 end @@ -26,9 +28,10 @@ module Mobile get 'homeworks' do authenticate! - homeworks = current_user.homework_commons + rs = ResourcesService.new + homeworks = rs.all_homework_commons current_user - present :data, homeworks, with: Mobile::Entities::Homework + present :data, homeworks, with: Mobile::Entities::Homework,user: current_user present :status, 0 end @@ -40,8 +43,9 @@ module Mobile get 'exercies' do authenticate! - exercises = current_user.exercises - present :data, exercises, with: Mobile::Entities::Exercise + rs = ResourcesService.new + exercises = rs.all_exercises current_user + present :data, exercises, with: Mobile::Entities::Exercise,user: current_user present :status, 0 end diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb index 57db4cb9e..8538fae99 100644 --- a/app/api/mobile/apis/syllabuses.rb +++ b/app/api/mobile/apis/syllabuses.rb @@ -14,7 +14,7 @@ module Mobile cs = SyllabusesService.new courses = cs.user_syllabus(current_user) - present :data, courses, with: Mobile::Entities::Syllabus + present :data, courses, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end @@ -29,9 +29,8 @@ module Mobile sy = ::Syllabus.find(params[:id]) sy.courses = sy.courses.not_deleted - sy = ss.judge_can_setting(sy,current_user) - present :data, sy, with: Mobile::Entities::Syllabus + present :data, sy, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end @@ -68,7 +67,7 @@ module Mobile if sy.new_record? {status:-1, message: '创建大纲失败' } else - present :data, sy, with: Mobile::Entities::Syllabus + present :data, sy, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index a6536e73e..e2ea8d35b 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -41,8 +41,8 @@ module Mobile openid: openid, user: user ) - # ws = WechatService.new - # ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now)) + ws = WechatService.new + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, Time.now.strftime("%Y-%m-%d")) present status: 0, message: '您已成功绑定Trustie平台' end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index bb67b6d28..49cb6bd2b 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -2,6 +2,7 @@ module Mobile module Entities class Attachment < Grape::Entity include Redmine::I18n + include ActionView::Helpers::NumberHelper def self.attachment_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -17,6 +18,10 @@ module Mobile case field when :file_dir "attachments/download/" << f.send(:id).to_s << '/' + when :attafile_size + (number_to_human_size(f.filesize)).gsub("ytes", "").to_s + when :coursename + f.course.nil? ? "" : f.course.name end end end @@ -29,6 +34,8 @@ module Mobile attachment_expose :quotes attachment_expose :created_on attachment_expose :file_dir + attachment_expose :attafile_size + attachment_expose :coursename #所属班级名 end end end \ No newline at end of file diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index d44869a60..88c8ba144 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -2,6 +2,8 @@ module Mobile module Entities class Course < Grape::Entity include Redmine::I18n + include ApplicationHelper + include ApiHelper def self.course_expose(field) expose field do |f,opt| c = nil @@ -52,7 +54,28 @@ module Mobile course_expose :updated_at course_expose :course_student_num course_expose :member_count - course_expose :can_setting + expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| + current_user = options[:user] + can_setting = false + + if instance[:course] + course = instance[:course] + else + course = instance + end + + member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] + roleName = member.roles[0].name if member + + if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + can_setting = true + end + + if course.tea_id == current_user.id + can_setting = true + end + can_setting + end expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/exercise.rb b/app/api/mobile/entities/exercise.rb index 3218264fb..05066f8a4 100644 --- a/app/api/mobile/entities/exercise.rb +++ b/app/api/mobile/entities/exercise.rb @@ -1,8 +1,32 @@ module Mobile module Entities class Exercise < Grape::Entity + include Redmine::I18n + include ApplicationHelper + include ApiHelper + def self.exercise_expose(field) + expose field do |f,opt| + if f.is_a?(Hash) && f.key?(field) + if field == :created_on + format_time(f[field]) + else + f[field] + end + elsif f.is_a?(::Exercise) + if f.respond_to?(field) + f.send(field) + else + case field + when :coursename + f.course.nil? ? "" : f.course.name + end + end + end + end + end expose :exercise_name expose :exercise_description + exercise_expose :coursename #所属班级名 end end end diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index db3e44119..3f1631c96 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -37,6 +37,8 @@ module Mobile when :homework_anony_type val = f.homework_type == 1 && !f.homework_detail_manual.nil? val + when :coursename + f.course.nil? ? "" : f.course.name end end end @@ -94,6 +96,8 @@ module Mobile homework_expose :homework_anony_type #是否是匿评作业 + homework_expose :coursename #所属班级名 + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/syllabus.rb b/app/api/mobile/entities/syllabus.rb index 4f97dd868..e4dd2e07a 100644 --- a/app/api/mobile/entities/syllabus.rb +++ b/app/api/mobile/entities/syllabus.rb @@ -1,12 +1,14 @@ module Mobile module Entities class Syllabus < Grape::Entity - include ApplicationHelper - expose :title expose :id - expose :can_setting - + expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| + current_user = options[:user] + can_setting = instance.user_id == current_user.id ? true : false + can_setting = false if instance.id.nil? + can_setting + end expose :courses, using: Mobile::Entities::Course end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 52e1f5fd0..6c62c642a 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -82,7 +82,7 @@ class AdminController < ApplicationController syllabus.update_attributes(:title => params[:title], :eng_name => params[:eng_name], :user_id => @user.id) syllabus.description = Message.where("id = 19412").first.nil? ? nil : Message.where("id = 19412").first.content if syllabus.save - course.update_attribute('syllabus_id', syllabus.id) + course.update_column('syllabus_id', syllabus.id) @flag = params[:flag].to_i @course = course respond_to do |format| @@ -96,7 +96,7 @@ class AdminController < ApplicationController def courses @name = params[:name].to_s.strip.downcase if @name && @name != "" - @courses = Course.select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)} + @courses = Course.select{ |course| course.teacher && ((course.teacher.show_name).include?(@name) || course.name.include?(@name))} @courses = @courses.sort{|x, y| y.created_at <=> x.created_at} else @courses = Course.order('created_at desc') @@ -135,6 +135,17 @@ class AdminController < ApplicationController end end + #修改课程名称 + def update_syllabus_title + @syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first + unless @syllabus.nil? + @syllabus.update_column("title", params[:name]) + respond_to do |format| + format.js + end + end + end + #管理员界面精品课程列表 def excellent_courses @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 5b29565ad..69c33f90e 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -47,6 +47,8 @@ class AtController < ApplicationController find_journals_for_message(id) when 'Principal' find_principal(id) + when 'BlogComment' + find_blog_comment(id) when 'All' nil else @@ -166,8 +168,8 @@ class AtController < ApplicationController #BlogComment def find_blog_comment(id) - blog = BlogComment.find(id).blog - blog.users + blog = BlogComment.find(id) + blog.author.watcher_users end end \ No newline at end of file diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 4a8de5814..dcab1b360 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -70,6 +70,10 @@ class BlogCommentsController < ApplicationController @course.outline = 0 @course.save redirect_to course_path(:id=>params[:course_id]) + elsif params[:user_activity_id] + @article.children.destroy + @article.destroy + redirect_to user_path(User.current.id) else @article.children.destroy @article.destroy @@ -80,6 +84,17 @@ class BlogCommentsController < ApplicationController if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的 @article.destroy redirect_to syllabus_course_path(:id=>params[:course_id]) + elsif params[:user_activity_id] + if params[:homepage] && params[:homepage] == "1" + @in_user_homepage = true + end + @user_activity_id = params[:user_activity_id] + @blog_comment = @article.root + @article.destroy + respond_to do |format| + format.js + return + end else root = @article.root @article.destroy @@ -102,13 +117,9 @@ class BlogCommentsController < ApplicationController def quote @blogComment = BlogComment.find(params[:id]) - @subject = @blogComment.title - @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') - @content = "> #{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}\n> " @temp = BlogComment.new @course_id = params[:course_id] - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}".html_safe respond_to do | format| format.js end @@ -116,23 +127,30 @@ class BlogCommentsController < ApplicationController #回复 def reply - if params[:homepage] + if params[:homepage] && params[:homepage] == "1" @in_user_homepage = true end if params[:in_user_center] @in_user_center = true end @article = BlogComment.find(params[:id]).root - @quote = params[:quote][:quote] @blogComment = BlogComment.new @blogComment.author = User.current @blogComment.blog = Blog.find(params[:blog_id]) params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 @blogComment.safe_attributes = params[:blog_comment] - @blogComment.content = @quote + @blogComment.content @blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title] - @article.children << @blogComment + if params[:parent_id] + @blogComment.content = params[:blog_comment][:content] + parent = BlogComment.find params[:parent_id] + @blogComment.reply_id = params[:reply_id] + parent.children << @blogComment + else + @quote = params[:quote][:quote] || "" + @blogComment.content = @quote + @blogComment.content + @article.children << @blogComment + end @article.save # @article.update_attribute(:updated_on, @blogComment.updated_on) @user_activity_id = params[:user_activity_id] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a9d84c2d9..665273ae0 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -633,6 +633,9 @@ class CoursesController < ApplicationController =end end if @course + #发送微信消息 + ss = SyllabusesService.new + ss.send_wechat_create_class_notice User.current,@course respond_to do |format| flash[:notice] = l(:notice_successful_create) format.html {redirect_to course_url(@course)} @@ -968,7 +971,7 @@ class CoursesController < ApplicationController @homework = HomeworkCommon.find params[:homework] #order("#{@order} #{@b_sort}" - @student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc"),@name + @student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc").has_committed,@name @works_hash = {} diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 264c1fc9f..924be596e 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -123,10 +123,14 @@ class OrgDocumentCommentsController < ApplicationController def destroy @org_document_comment = OrgDocumentComment.find(params[:id]) @org_sub_id = @org_document_comment.org_subfield_id - org = @org_document_comment.organization + org = @org_document_comment.root.organization if @org_document_comment.id == org.home_id org.update_attributes(:home_id => nil) end + if params[:user_activity_id] + @act = OrgActivity.find(params[:user_activity_id]) + @document = @org_document_comment.root + end if @org_document_comment.destroy end respond_to do |format| @@ -145,48 +149,26 @@ class OrgDocumentCommentsController < ApplicationController end def quote @org_comment = OrgDocumentComment.find(params[:id]) - @subject = @org_comment.content - @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') - - @content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> " @temp = OrgDocumentComment.new - #@course_id = params[:course_id] - @temp.content = "
#{@blogComment.content.html_safe}
#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}".html_safe respond_to do | format| format.js end end def reply - @document = OrgDocumentComment.find(params[:id]).root - @quote = params[:quote][:quote] + @document = OrgDocumentComment.find(params[:id]) @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id]) - # params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 - # params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 @org_document.title = params[:org_document_comment][:title] @org_document.content = params[:org_document_comment][:content] - @org_document.content = @quote + @org_document.content - #@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title] + @document.children << @org_document - # @user_activity_id = params[:user_activity_id] - # user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first - # if user_activity - # user_activity.updated_at = Time.now - # user_activity.save - # end - # attachments = Attachment.attach_files(@org_document, params[:attachments]) - # render_attachment_warning_if_needed(@org_document) - #@article.save - # redirect_to user_blogs_path(:user_id=>params[:user_id]) + @document = @document.root + @user_activity_id = params[:user_activity_id] + @act = OrgActivity.find(@user_activity_id) if @user_activity_id respond_to do |format| format.html { - # if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 - # redirect_to syllabus_course_path(:id=>params[:course_id]) - # else redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id) - # end - } format.js end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index bc1b97a2f..45b54cf0a 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -271,7 +271,7 @@ class StudentWorkController < ApplicationController all_studentwork = find_all_student_work_by_homeid() - @work_count = all_studentwork.count + @work_count = all_studentwork.has_committed.count end #代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言 @@ -282,7 +282,7 @@ class StudentWorkController < ApplicationController @homework = HomeworkCommon.find params[:homework] - all_studentwork = find_all_student_work_by_homeid() + all_studentwork = find_all_student_work_by_homeid().has_committed if all_studentwork == nil resultObj[:status] = -2 diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 8d7195f38..291e6ca30 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -109,7 +109,11 @@ class SyllabusesController < ApplicationController sort_name = "updated_on" sort_type = @c_sort == 1 ? "asc" : "desc" - @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + if User.current == @syllabus.user || User.current.admin? + @courses = @syllabus.courses.where("is_delete = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + else + @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + end #根据 作业+资源数排序 if @order.to_i == 2 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 15ddf0435..5a88e90d3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -92,6 +92,8 @@ class UsersController < ApplicationController @comment = JournalsForMessage.find params[:comment].to_i when 'Message' @comment = Message.find params[:comment].to_i + when 'BlogComment' + @comment = BlogComment.find params[:comment].to_i end end @@ -120,6 +122,17 @@ class UsersController < ApplicationController @is_course = params[:is_course] @is_board = params[:is_board] @type = 'Message' + when 'BlogComment' + @reply = BlogComment.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @homepage = params[:homepage] + @type = 'BlogComment' + when 'OrgDocumentComment' + @reply = OrgDocumentComment.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @type = 'OrgDocumentComment' end respond_to do |format| format.js @@ -556,12 +569,12 @@ class UsersController < ApplicationController @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" @user = User.current @r_sort = @b_sort == "desc" ? "asc" : "desc" - if(params[:type].blank? || params[:type] == "1") #题库 + if(params[:type].blank? || params[:type] == "1") #我的题库 + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") + elsif params[:type] == "2" #题库 visible_course = Course.where("is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") - elsif params[:type] == "2" #我的题库 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") end @type = params[:type] @limit = 25 @@ -715,7 +728,11 @@ class UsersController < ApplicationController @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current - if(params[:type].blank? || params[:type] == "1") #题库 + if(params[:type].blank? || params[:type] == "1") #我的题库 + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}") + elsif params[:type] == "2" #题库 if params[:is_import].to_i == 1 visible_course = Course.where("is_public = 1 && is_delete = 0") elsif params[:is_import].to_i == 0 @@ -723,10 +740,6 @@ class UsersController < ApplicationController end visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") - elsif params[:type] == "2" #我的题库 - courses = @user.courses.where("is_delete = 1") - course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}") elsif params[:type] == "3" #申请题库 none_visible_course = Course.where("is_delete = 1") none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")" @@ -793,7 +806,18 @@ class UsersController < ApplicationController @user = User.current search = params[:name].to_s.strip.downcase type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")" - if(params[:type].blank? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") #我的题库 + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + end + elsif params[:type] == "2" #题库 if params[:is_import].to_i == 1 visible_course = Course.where("is_public = 1 && is_delete = 0") elsif params[:is_import].to_i == 0 @@ -812,17 +836,6 @@ class UsersController < ApplicationController else @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") end - elsif params[:type] == "2" #我的题库 - courses = @user.courses.where("is_delete = 1") - course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" - if @order == "course_name" - sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" - @homeworks = HomeworkCommon.find_by_sql(sql) - elsif @order == "user_name" - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") - else - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") - end elsif params[:type] == "3" #申请题库 apply_homeworks = ApplyHomework.where("user_id = ?",@user.id) homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")" @@ -1410,8 +1423,13 @@ class UsersController < ApplicationController @all_count = @user.courses.visible.where("is_delete =?", 0).count elsif @type == 'Syllabus' @syllabus = Syllabus.where("id = #{params[:syllabus]}").first - @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) - @all_count = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).count + if User.current == @syllabus.user || User.current.admin? + all_courses = @syllabus.courses.where("is_delete = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc") + else + all_courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc") + end + @courses = all_courses.limit(5).offset(@page * 5) + @all_count = all_courses.count end end @@ -3279,7 +3297,10 @@ class UsersController < ApplicationController case params[:type] when 'OrgDocumentComment' obj = OrgDocumentComment.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_at desc") + @user_activity_id = params[:div_id].to_i if params[:div_id] + @type = 'OrgDocumentComment' + comments = [] + @journals = get_all_children(comments, obj) when 'Message' obj = Message.where('id = ?', params[:id].to_i).first @type = 'Message' @@ -3306,7 +3327,11 @@ class UsersController < ApplicationController @journals = obj.journals.reorder("created_on desc") when 'BlogComment' obj = BlogComment.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_on desc") + @user_activity_id = params[:div_id].to_i if params[:div_id] + @homepage = params[:homepage].to_i + @type = 'BlogComment' + comments = [] + @journals = get_all_children(comments, obj) when 'HomeworkCommon' obj = HomeworkCommon.where('id = ?', params[:id].to_i).first @journals = obj.journals_for_messages.reorder("created_on desc") diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index f49398ff7..5f1e54b8a 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -69,11 +69,21 @@ class WechatsController < ActionController::Base end on :click, with: 'DEV' do |request, key| - request.reply.text "此功能正在开发中,很快就会上线,谢谢!" + uw = user_binded?(request[:FromUserName]) + unless uw + sendBind(request) + else + request.reply.text "此功能正在开发中,很快就会上线,谢谢!" + end end # When user view URL in the menu button on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view| - request.reply.text "#{request[:FromUserName]} view #{view}" + uw = user_binded?(request[:FromUserName]) + unless uw + sendBind(request) + else + request.reply.text "#{request[:FromUserName]} view #{view}" + end end # When user sent the imsage @@ -139,8 +149,8 @@ class WechatsController < ActionController::Base on :click, with: 'JOIN_CLASS' do |request, key| uw = user_binded?(request[:FromUserName]) - unless uw - sendBind(request) + unless uw + sendBind(request) else request.reply.text "请直接回复5位班级邀请码\n(不区分大小写):" end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index add8a9552..efce039aa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3143,13 +3143,18 @@ end #获取所有子节点 def get_all_children result, jour - if (jour.kind_of? JournalsForMessage) || (jour.kind_of? Message) + if (jour.kind_of? JournalsForMessage) || (jour.kind_of? Message) || (jour.kind_of? BlogComment) || (jour.kind_of? OrgDocumentComment) jour.children.each do |jour_child| result << jour_child get_all_children result, jour_child end end - result.sort! { |a,b| b.created_on <=> a.created_on } + if jour.respond_to?(:created_on) + result.sort! { |a,b| b.created_on <=> a.created_on } + elsif jour.respond_to?(:created_at) + result.sort! { |a,b| b.created_at <=> a.created_at } + end + result end #将有置顶属性的提到数组前面 @@ -3298,6 +3303,14 @@ def strip_html(text,len=0,endss="...") return ss end +def message_content content + content = (strip_html content).strip + if content.gsub(" ", "") == "" + content = "[非文本消息]" + end + content +end + def get_hw_index(hw,is_teacher) if is_teacher homeworks = hw.course.homework_commons.order("created_at asc") diff --git a/app/models/user.rb b/app/models/user.rb index daf1237cf..996aa9be7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1148,17 +1148,17 @@ class User < Principal #为新注册用户发送留言 def add_new_jour - if Message.where("id=19278").any? and Message.where("id=19291").any? and Message.where("id=19292").any? - lead_message1 = Message.find(19278) + if Message.where("id=19504").any? and Message.where("id=19291").any? and Message.where("id=19292").any? + lead_message1 = Message.find(19292) notes1 = lead_message1.content - # lead_message2 = Message.find(19292) - # notes2 = lead_message2.content - # lead_message3 = Message.find(19291) - # notes3 = lead_message3.content - # # user_id 默认为课程使者创建 + lead_message2 = Message.find(19291) + notes2 = lead_message2.content + lead_message3 = Message.find(19504) + notes3 = lead_message3.content + #user_id 默认为课程使者创建 self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) end end diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb index a0fec585a..bc97437e4 100644 --- a/app/services/resources_service.rb +++ b/app/services/resources_service.rb @@ -1,7 +1,6 @@ #coding=utf-8 class ResourcesService - #发送资源到课程 def send_resource_to_course user,params send_id = params[:send_id] @@ -50,4 +49,56 @@ class ResourcesService [@ori, @flag, @save_message] end + # 我的资源-课件 已发布的 + def all_course_attachments user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + attchments = Attachment.where("(author_id = #{user.id} and is_publish = 1 and container_id in #{courses_ids} and container_type = 'Course') or (container_type = 'Course' and is_publish = 1 and container_id in #{courses_ids})" ).order("created_on desc") + + # attchments.each do |v| + # course = Course.where("id=?",v.container_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # v[:attafile_size] = (number_to_human_size(v[:filesize])).gsub("ytes", "").to_s + # end + + attchments + end + + # 我的资源-作业 已发布的 + def all_homework_commons user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + homeworks = HomeworkCommon.where("course_id in #{courses_ids} and publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") + + # homeworks.each do |v| + # course = Course.where("id=?",v.course_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # end + + homeworks + end + + # 我的资源-测验 已发布的 + def all_exercises user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + exercises = Exercise.where("exercise_status <> 1 and course_id in #{courses_ids}").order("created_at desc") + + # exercises.each do |v| + # course = Course.where("id=?",v.course_id).first + # v[:coursename] = course.nil? ? "未知" : course.name + # end + + exercises + end + end \ No newline at end of file diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index b3190182c..d5dec9f88 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -29,19 +29,13 @@ class SyllabusesService end #获取指定用户的课程大纲 def user_syllabus(user) - courses = CoursesService.new.user_courses_list(user) - - other = Syllabus.new(title: '未命名课程',user_id: user.id) - - courses.each do |c| - other.courses << c[:course] unless c[:course].syllabus - end - - # user.syllabuses.each do |syllabus| - # syllabus.courses = syllabus.courses.not_deleted - # end + # courses = CoursesService.new.user_courses_list(user) # - # user.syllabuses.to_a << other + # other = Syllabus.new(title: '未命名课程',user_id: user.id) + # + # courses.each do |c| + # other.courses << c[:course] unless c[:course].syllabus + # end courses = user.courses.not_deleted syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" @@ -51,12 +45,13 @@ class SyllabusesService syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc") end - syllabuses.to_a << other + # syllabuses.to_a << other + syllabuses.to_a #管理权限 can_setting - syllabuses.each do |s| - s = judge_can_setting(s,user) - end + # syllabuses.each do |s| + # s = judge_can_setting(s,user) + # end syllabuses end @@ -72,6 +67,15 @@ class SyllabusesService course.course_infos << course_info end + def send_wechat_create_class_notice user,course + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count + if count == 0 + ws = WechatService.new + title = "恭喜您创建班级成功" + ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 0, "点击查看班级详情" + end + end + #创建大纲 # params {title: '大纲名称', [{course}, {course}]} def create(user, title, courses = []) @@ -83,6 +87,7 @@ class SyllabusesService if ::Course === course course.syllabus_id = sy.id course.save! + send_wechat_create_class_notice user,course elsif Hash === course c = ::Course.new(course) c.tea_id = user.id @@ -91,6 +96,7 @@ class SyllabusesService c.is_public = 0 c.save! after_create_course(c, user) + send_wechat_create_class_notice user,c end end @@ -134,6 +140,7 @@ class SyllabusesService course.is_public = 0 course.save! after_create_course(course, user) + send_wechat_create_class_notice user,course end status = 0 end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 3169763c4..2da942ea6 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -115,7 +115,7 @@ class WechatService data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}",#/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { @@ -139,11 +139,43 @@ class WechatService data end + def three_keys_template(openid, template_id, type, id, first, key1, key2, key3, remark="") + data = { + touser:openid, + template_id:template_id, + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}",#/assets/wechat/app.html#/#{type}/#{id} + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + keyword3:{ + value:key3, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + data + end + def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="") data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}", + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}", #/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { @@ -250,4 +282,45 @@ class WechatService end end + def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.create_class_notice, + url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/class?id="+id.to_s, + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + keyword3:{ + value:key3, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + #data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[wechat_create_class_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/app/views/admin/_rename_syllabus_title.html.erb b/app/views/admin/_rename_syllabus_title.html.erb new file mode 100644 index 000000000..e3a175215 --- /dev/null +++ b/app/views/admin/_rename_syllabus_title.html.erb @@ -0,0 +1,3 @@ + + <%= syllabus.title %> + \ No newline at end of file diff --git a/app/views/admin/syllabuses.html.erb b/app/views/admin/syllabuses.html.erb index 782f6b01c..194091abc 100644 --- a/app/views/admin/syllabuses.html.erb +++ b/app/views/admin/syllabuses.html.erb @@ -46,10 +46,8 @@
#{@org_comment.content.html_safe}
","").gsub("
","").gsub("","").gsub("
","").gsub("真实姓名:<%= User.find(ma.course_message_id).realname %>
申请课程:<%= Course.find(ma.course_id).name%>
申请职位:<%= ma.content == '9' ? "教师" : "教辅"%>
+申请职位:<%= ma.content == '9' ? "教师" : "教辅"%>