diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 369185ca2..bfd559402 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -287,6 +287,30 @@ module Mobile end end + desc "获取课程动态" + params do + requires :id, type: Integer + requires :token, type: String + end + post 'activities' do + authenticate! + + user = current_user + + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + activities = UserActivity.where("(container_type = 'Course' and container_id = #{params[:id]} and act_type in #{course_types})").order('updated_at desc') + + page = params[:page] ? params[:page] : 0 + all_count = activities.count + activities = activities.limit(10).offset(page * 10) + count = activities.count + present :data, activities, with: Mobile::Entities::Activity,user: user + present :all_count, all_count + present :count, count + present :page, page + present :status, 0 + end + desc "课程作业列表" params do requires :token, type: String @@ -558,6 +582,85 @@ module Mobile end end + desc "发布班级通知" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + requires :title, type: String + end + post ':id/publishnotice' do + 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?(7)|| roles_ids.include?(9) || roles_ids.include?(3)) + + tmpparams = {} + tmpparams['title'] = params[:title] + tmpparams['description'] = params[:text] + tmpparams['sticky'] = 0 + + news = News.new(:course => c, :author => current_user) + #render :layout => 'base_courses' + news.safe_attributes = tmpparams + + news.save! + + present :status, 0 + else + present :status, -1 + present :message,"学生不能发布通知" + end + end + + desc "发布班级问题" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + end + post ':id/publishissue' do + authenticate! + + c = Course.find("#{params[:id]}") + + boards = c.boards.includes(:last_message => :author).all + if c.boards.empty? + board = c.boards.build + board.name = "班级问答区" + board.description = c.name.to_s + board.project_id = -1 + if board.save + boards = c.boards.includes(:last_message => :author).all + end + end + + board = boards.first + + message = Message.new + message.author = current_user + message.board = board + + tmpparams = {} + tmpparams['subject'] = params[:title] + tmpparams['content'] = params[:text] + + message.safe_attributes = tmpparams + + message.save! + + present :status, 0 + + end + end end end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index dfd5a3335..271e3419d 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -17,11 +17,21 @@ module Mobile #0一级回复的更多 1 二级回复的更多 type = params[:type] || 0 page = params[:page] || 0 - issue = Issue.find params[:id] - present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page + + is_public = 1 + + if type == 0 + issue = Issue.find params[:id] + issue.project.is_public + present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page + else + jour = Journal.find params[:id] + present :data, jour, with: Mobile::Entities::Issue,user: user,type: type,page: page + end + present :type, type present :page, page - present :is_public, issue.project.is_public + present :is_public,is_public present :status, 0 rescue Exception=>e present :status, -1 diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index c2e2fcb5c..810e4ff2a 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -14,14 +14,19 @@ module Mobile #0一级回复的更多 1 二级回复的更多 type = params[:type] || 0 page = params[:page] || 0 - news = News.find params[:id] is_public = 1 - if news.project - is_public = news.project.is_public - elsif news.course - is_public = news.course.is_public + if type == 0 + news = News.find params[:id] + + if news.project + is_public = news.project.is_public + elsif news.course + is_public = news.course.is_public + end + else + news = Comment.find params[:id] end present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page diff --git a/app/api/mobile/apis/projects.rb b/app/api/mobile/apis/projects.rb index 05d4036f9..2202fbd13 100644 --- a/app/api/mobile/apis/projects.rb +++ b/app/api/mobile/apis/projects.rb @@ -229,6 +229,45 @@ module Mobile present :message, result[:message] end + desc "发布项目帖子" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + end + post ':id/publishnote' do + authenticate! + + project = Project.find("#{params[:id]}") + + boards = project.boards.includes(:last_message => :author).all + if project.boards.empty? + board = project.boards.build + board.name = "项目讨论区" + board.description = project.name.to_s + board.course_id = -1 + if board.save + boards = project.boards.includes(:last_message => :author).all + end + end + + board = boards.first + + message = Message.new + message.author = current_user + message.board = board + + tmpparams = {} + tmpparams['subject'] = params[:title] + tmpparams['content'] = params[:text] + + message.safe_attributes = tmpparams + + message.save! + + present :status, 0 + + end end end end diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 2856354a1..a56deaad3 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -40,6 +40,8 @@ module Mobile ac.act.subject unless ac.nil? || ac.act.nil? elsif ac.act_type == "JournalsForMessage" ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil? + elsif ac.act_type == "Poll" + ac.act.polls_name unless ac.nil? || ac.act.nil? end when :description if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News" @@ -48,6 +50,8 @@ module Mobile strip_html(ac.act.content) unless ac.nil? || ac.act.nil? elsif ac.act_type == "JournalsForMessage" strip_html(ac.act.notes) unless ac.nil? || ac.act.nil? + elsif ac.act_type == "Poll" + ac.act.polls_description unless ac.nil? || ac.act.nil? end when :latest_update time_from_now ac.updated_at unless ac.nil? @@ -73,15 +77,15 @@ module Mobile if ac.container_type == "Course" case ac.act_type when "HomeworkCommon" - "课程作业" + "班级作业" when "News" - "课程通知" + "班级通知" when "Message" - "课程问答区" + "班级讨论区" when "Poll" - "课程问卷" + "班级问卷" when "Course" - "课程" + "班级" end elsif ac.container_type == "Project" case ac.act_type diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 028ad633d..8200c04b2 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 :course_id + f.course.nil? ? 0 : f.course.id end end @@ -38,6 +40,7 @@ module Mobile attachment_expose :file_dir attachment_expose :attafile_size attachment_expose :coursename #所属班级名 + attachment_expose :course_id #所属班级名 expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] current_user_is_teacher = false diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index 9cbeb3459..e3dbb5023 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -36,15 +36,42 @@ module Mobile issue.id when :title issue.subject + when :subject + issue.subject + when :description + issue.description + when :done_ratio + issue.done_ratio end end + elsif issue.is_a?(::Journal) + case f + when :content + issue[:notes] + when :lasted_comment + time_from_now issue.created_on + when :act_id + issue.id + end end end end - expose :subject - expose :description - expose :author, using: Mobile::Entities::User - expose :done_ratio + issue_expose :subject + issue_expose :description + expose :author, using: Mobile::Entities::User do |f, opt| + if f.is_a?(::Issue) + f.send(:author) + end + end + expose :user,using: Mobile::Entities::User do |f, opt| + if f.is_a?(::Journal) + f.send(:user) + end + end + issue_expose :content + issue_expose :lasted_comment + + issue_expose :done_ratio issue_expose :title issue_expose :act_type issue_expose :act_id @@ -55,11 +82,29 @@ module Mobile issue_expose :comment_count issue_expose :project_name issue_expose :praise_count - expose :issue_journals, using: Mobile::Entities::Journal do |f, opt| + + expose :id + # expose :issue_journals, using: Mobile::Entities::Journal do |f, opt| + # if f.is_a?(::Issue) + # f.journals.where("notes is not null and notes != ''").reverse + # end + # end + + expose :all_children, using: Mobile::Entities::Issue do |f, opt| + #f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages) if f.is_a?(::Issue) - f.journals.where("notes is not null and notes != ''").reverse + # f.journals_for_messages.reverse + if !opt[:children] && opt[:type] == 0 + opt[:children] = true + tStart = opt[:page]*5 + tEnd = (opt[:page]+1)*5 - 1 + + all_comments = f.journals.where("notes is not null and notes != ''").reorder("created_on desc") + all_comments[tStart..tEnd] + end end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| has_praise = false current_user = options[:user] @@ -67,6 +112,69 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + if instance.is_a?(::Journal) + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, instance) + parents_reply.count + end + end + + expose :parents_reply_bottom, using:Mobile::Entities::Issue do |f,opt| + if f.is_a? (::Journal) + #取二级回复的底楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 0 && !opt[:bottom] + if opt[:type] == 1 + # opt[:bottom] = true + # parents_reply[opt[:page]..opt[:page]] + else + opt[:bottom] = true + parents_reply[0..0] + end + else + [] + end + end + end + + expose :parents_reply_top, using:Mobile::Entities::Issue do |f,opt| + if f.is_a? (::Journal) + #取二级回复的顶楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 2 && !opt[:top] + if opt[:type] == 1 + opt[:top] = true + tStart = (opt[:page]-1)*5+2 + tEnd = (opt[:page])*5+2 - 1 + + if tEnd >= parents_reply.count - 1 + tEnd = parents_reply.count - 2 + end + + if tStart <= parents_reply.count - 2 + parents_reply = parents_reply.reverse[tStart..tEnd] + parents_reply.reverse + else + [] + end + else + opt[:top] = true + parents_reply = parents_reply.reverse[0..1] + parents_reply.reverse + end + elsif parents_reply.count == 2 && !opt[:top] + opt[:top] = true + parents_reply = parents_reply.reverse[0..0] + parents_reply.reverse + else + [] + end + end + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index be9fa3ceb..a64081d8a 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -28,6 +28,16 @@ module Mobile f.comments.count end end + elsif f.is_a?(::Comment) + case field + when :content + f[:comments] + when :lasted_comment + time_from_now f.created_on + when :act_id + f.id + end + elsif f.is_a?(Hash) && !f.key?(field) n = f[:news] comments = f[:comments] @@ -43,14 +53,16 @@ module Mobile end end end - news_expose :id + expose :id #新闻标题 news_expose :title - expose :author,using: Mobile::Entities::User do |f, opt| + expose :user,using: Mobile::Entities::User do |f, opt| obj = nil if f.is_a?(::News) && f.respond_to?(:author) obj = f.send(:author) + elsif f.is_a?(::Comment) && f.respond_to?(:author) + obj = f.send(:author) elsif f.is_a?(Hash) && f.key?(:author) obj = f[:author] end @@ -73,14 +85,34 @@ module Mobile news_expose :praise_count #课程名字 news_expose :course_name + news_expose :lasted_comment + #评论 - expose :comments, using: Mobile::Entities::Comment do |f, opt| - if f.is_a?(Hash) && f.key?(:comments) - f[:comments] - elsif f.is_a?(::News) && f.respond_to?(:comments) - f.comments.reverse + # expose :comments, using: Mobile::Entities::Comment do |f, opt| + # if f.is_a?(Hash) && f.key?(:comments) + # f[:comments] + # elsif f.is_a?(::News) && f.respond_to?(:comments) + # f.comments.reverse + # end + # end + + news_expose :content + + expose :all_children, using: Mobile::Entities::News do |f, opt| + #f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages) + if f.is_a?(::News) + # f.journals_for_messages.reverse + if !opt[:children] && opt[:type] == 0 + opt[:children] = true + tStart = opt[:page]*5 + tEnd = (opt[:page]+1)*5 - 1 + + all_comments = f.comments.reorder("created_on desc") + all_comments[tStart..tEnd] + end end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| has_praise = false current_user = options[:user] @@ -88,6 +120,69 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + if instance.is_a?(::Comment) + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, instance) + parents_reply.count + end + end + + expose :parents_reply_bottom, using:Mobile::Entities::News do |f,opt| + if f.is_a? (::Comment) + #取二级回复的底楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 0 && !opt[:bottom] + if opt[:type] == 1 + # opt[:bottom] = true + # parents_reply[opt[:page]..opt[:page]] + else + opt[:bottom] = true + parents_reply[0..0] + end + else + [] + end + end + end + + expose :parents_reply_top, using:Mobile::Entities::News do |f,opt| + if f.is_a? (::Comment) + #取二级回复的顶楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 2 && !opt[:top] + if opt[:type] == 1 + opt[:top] = true + tStart = (opt[:page]-1)*5+2 + tEnd = (opt[:page])*5+2 - 1 + + if tEnd >= parents_reply.count - 1 + tEnd = parents_reply.count - 2 + end + + if tStart <= parents_reply.count - 2 + parents_reply = parents_reply.reverse[tStart..tEnd] + parents_reply.reverse + else + [] + end + else + opt[:top] = true + parents_reply = parents_reply.reverse[0..1] + parents_reply.reverse + end + elsif parents_reply.count == 2 && !opt[:top] + opt[:top] = true + parents_reply = parents_reply.reverse[0..0] + parents_reply.reverse + else + [] + end + end + end end end end \ No newline at end of file diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 731a251f2..02dfe9a45 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -30,6 +30,8 @@ class AccountController < ApplicationController user = UserExtensions.where(:user_id => User.current.id).first if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) else redirect_to user_path(User.current) end @@ -357,6 +359,8 @@ class AccountController < ApplicationController user = UserExtensions.where(:user_id => User.current.id).first if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) else redirect_back_or_default User.current #redirect_to my_account_url diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index fa2c87f8c..7ec532d79 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -202,6 +202,11 @@ class AttachmentsController < ApplicationController end @attachment.save @newfiledense = filedense + end + if @project + + elsif @course + end respond_to do |format| format.js diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index b5c174b0c..9d90cb9f2 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -12,11 +12,13 @@ class AvatarController < ApplicationController @source_id = params[:source_id] @temp_file = params[:avatar][:image] @image_file = @temp_file.original_filename + @is_direct = params[:is_direct] else unless request.raw_post.nil? @source_type = params[:source_type] @source_id = params[:source_id] @temp_file = request.raw_post + @is_direct = params[:is_direct] if @temp_file.size > 0 if @temp_file.respond_to?(:original_filename) @image_file = @temp_file.original_filename @@ -38,7 +40,7 @@ class AvatarController < ApplicationController @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) # 用户头像上传时进行特别处理 - if @source_type == 'User' + if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project') diskfile += "temp" @urlfile += "temp" end @@ -105,7 +107,7 @@ class AvatarController < ApplicationController path = File.dirname(diskfile) if File.directory?(path) && File.exist?(diskfile) # 用户头像进行特别处理 - if @source_type == 'User' + if @source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' diskfile1 = diskfile + 'temp' File.open(diskfile1, "wb") do |f| buffer = "DELETE" diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 2f50c8105..6704f7401 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -94,8 +94,10 @@ class HomeworkCommonController < ApplicationController end end + status = false if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 + status = true end eval_start = homework_detail_manual.evaluation_start if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1) @@ -145,6 +147,10 @@ class HomeworkCommonController < ApplicationController @homework_detail_programing.save if @homework_detail_programing @homework_detail_group.save if @homework_detail_group + if @homework.homework_type != 3 && homework_detail_manual.comment_status == 1 && status + create_works_list @homework + end + if params[:is_manage] == "1" redirect_to manage_or_receive_homeworks_user_path(User.current.id) elsif params[:is_manage] == "2" diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 63ef30b35..b0c83e869 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -189,6 +189,15 @@ class IssuesController < ApplicationController # 给该issue在它所在的项目中所有的issues中所在的位置给一个序号 @issue.project_issues_index = @issue.project.issues.last.nil? ? 1 : @issue.project.issues.last.project_issues_index + 1 if @issue.save + + senduser = User.find(params[:issue][:assigned_to_id]) + issue_id = @issue.id + issue_title = params[:issue][:subject] + priority_id = params[:issue][:priority_id] + + ps = ProjectsService.new + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) respond_to do |format| format.html { @@ -581,6 +590,18 @@ class IssuesController < ApplicationController end end @issue.safe_attributes = issue_attributes + + senduser = User.find(params[:issue][:assigned_to_id]) + + if senduser.id != User.current.id + issue_id = @issue.id + issue_title = params[:issue][:subject] + priority_id = params[:issue][:priority_id] + + ps = ProjectsService.new + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + end + @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current) true diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 3aefdfd1d..c4935a1af 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -90,14 +90,34 @@ class MyController < ApplicationController end def clear_user_avatar_temp - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:course] + @course = Course.find params[:course] + diskfile = disk_filename('Course', @course.id) + elsif params[:project] + @project = Project.find params[:project] + diskfile = disk_filename('Project', @project.id) + else + @user = User.current + diskfile = disk_filename('User', @user.id) + end diskfile1 = diskfile + 'temp' File.delete(diskfile1) if File.exist?(diskfile1) end + def save_user_avatar - @user = User.current - diskfile = disk_filename('User', @user.id) + if params[:source_id] && params[:source_type] + case params[:source_type] + when 'User' + @user = User.current + diskfile = disk_filename('User', @user.id) + when 'Course' + @course = Course.find params[:source_id] + diskfile = disk_filename('Course', @course.id) + when 'Project' + @project = Project.find params[:source_id] + diskfile = disk_filename('Project', @project.id) + end + end diskfile1 = diskfile + 'temp' begin FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1 @@ -145,8 +165,10 @@ class MyController < ApplicationController @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') #@user.login = params[:login] unless @user.user_extensions.nil? - if @user.user_extensions.identity == 2 + # 如果用户是从业者,将单位名称保存至学校id字段 + if @user.user_extensions.identity == 3 # @user.firstname = params[:enterprise_name] + @user.user_extensions.school_id = params[:occupation] end end @@ -157,7 +179,6 @@ class MyController < ApplicationController # @se.occupation = params[:occupation] # end @se.school_id = params[:occupation] - @se.gender = params[:sex] @se.location = params[:province] if params[:province] @se.location_city = params[:city] if params[:city] @@ -180,6 +201,7 @@ class MyController < ApplicationController @user.login = lg end end + # 不管前面是否有异常,如果文件已存在就删除 ensure File.delete(diskfile1) if File.exist?(diskfile1) end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 722845ef7..5e13149df 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -734,24 +734,33 @@ class StudentWorkController < ApplicationController end def destroy - if @work.destroy - if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy + if @homework.homework_type == 3 + if @work.destroy + if @homework.homework_detail_group.base_on_project == 1 + pros = @work.student_work_projects.where("is_leader = 0") + pros.each do |pro| + pro.destroy + end + project = @work.student_work_projects.where("is_leader = 1").first + project.update_attributes(:student_work_id => nil) + elsif @homework.homework_detail_group.base_on_project == 0 + @work.student_work_projects.each do |pro2| + pro2.destroy + end end end - respond_to do |format| - format.html { - redirect_to student_work_index_url(:homework => @homework.id) - } - end + else + @work.attachments.destroy_all + @work.student_works_scores.destroy_all + @work.course_messages.destroy_all + @work.student_work_tests.destroy_all + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil) + @work.update_column("work_score",nil) + end + respond_to do |format| + format.html { + redirect_to student_work_index_url(:homework => @homework.id) + } end end @@ -793,6 +802,8 @@ class StudentWorkController < ApplicationController end elsif @homework.homework_type == 1 @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) + @work.attachments.destroy_all + @work.course_messages.destroy_all end @student_work = StudentWork.new respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e929153ad..a44a3bc01 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,7 +42,7 @@ class UsersController < ApplicationController :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, - :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -1115,23 +1115,8 @@ class UsersController < ApplicationController homework_detail_programing.save if homework_detail_programing homework_detail_group.save if homework_detail_group - if homework.homework_type != 3 - students = homework.course.student - if !homework.course.nil? && !students.empty? - name = homework.name - name_str = name + "的作品提交" - str = "" - students.each do |student| - if str != "" - str += "," - end - str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" - end - #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}') - sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str - #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id) - ActiveRecord::Base.connection.execute sql - end + if homework.homework_type != 3 && homework_detail_manual.comment_status == 1 + create_works_list homework end if params[:quotes] && !params[:quotes].blank? @@ -1474,15 +1459,15 @@ class UsersController < ApplicationController #显示更多用户课程 def user_courses4show @page = params[:page].to_i + 1 - @courses = @user.courses.visible.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").limit(10).offset(@page * 10) - @all_count = @user.courses.visible.where("is_delete =?", 0).count + @courses = @user.favorite_courses.visible.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").limit(10).offset(@page * 10) + @all_count = @user.favorite_courses.visible.where("is_delete =?", 0).count end #显示更多用户项目 def user_projects4show @page = params[:page].to_i + 1 - @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) - @all_count = @user.projects.visible.count + @projects = @user.favorite_projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) + @all_count = @user.favorite_projects.visible.count end def user_course_activities @@ -3439,6 +3424,28 @@ class UsersController < ApplicationController end end + #收藏班级/项目 + def cancel_or_collect + if params[:project] + @project = Project.find params[:project] + member = Member.where("user_id = #{@user.id} and project_id = #{@project.id}") + elsif params[:course] + @course = Course.find params[:course] + member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") + end + unless member.empty? + member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) + end + if @project + @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) + elsif @course + @courses = @user.favorite_courses.visible.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").limit(10) + end + respond_to do |format| + format.js + end + end + def user_projectlist @order, @c_sort, @type, @list_type = 1, 2, 1, 1 #limit = 5 diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index cfa5f4414..54486221e 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -435,8 +435,12 @@ class WechatsController < ActionController::Base session[:wechat_openid] = open_id if params[:code] - if params[:userid] - redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}&userid=#{params[:userid]}" and return + # if params[:state].match("review_class_member") || params[:state].match("review_project_member") + @path = params[:state].split('/')[0] + useridstr = params[:state].split('/')[1] + # end + if useridstr + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}&#{useridstr}" and return elsif params[:id] redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ffd30efc3..2d6e84762 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3442,8 +3442,26 @@ def course_syllabus_option user = User.current type end +def create_works_list homework + students = homework.course.student + if !homework.course.nil? && !students.empty? + name = homework.name + name_str = name + "的作品提交" + str = "" + students.each do |student| + if str != "" + str += "," + end + str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')" + end + sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end +end + # 获取项目动态更新时间 def get_forge_act_message(act, type) forge_act = ForgeActivity.where(:forge_act_id => act.id, :forge_act_type => type).first format_time(forge_act.nil? ? act.created_on : forge_act.try(:updated_at)) end + diff --git a/app/models/principal.rb b/app/models/principal.rb index 0c87ec0c6..e65816e83 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -131,6 +131,22 @@ class Principal < ActiveRecord::Base columns.uniq.map {|field| "#{table}.#{field}"} end + #收藏的课程 + def favorite_courses + members = Member.where("user_id = #{self.id} and course_id != -1 and is_collect = 1") + course_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.course_id}.join(",") + ")" + courses = Course.where("id in #{course_ids}") + return courses + end + + #收藏的项目 + def favorite_projects + members = Member.where("user_id = #{self.id} and project_id != -1 and project_id != 0 and is_collect = 1") + project_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.project_id}.join(",") + ")" + projects = Project.where("id in #{project_ids}") + return projects + end + protected # Make sure we don't try to insert NULL values (see #4632) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 09ef15583..183570081 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,6 @@ #学生提交作品表 class StudentWork < ActiveRecord::Base - attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time belongs_to :homework_common belongs_to :user diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb index 56dfaceff..fc7f25d1f 100644 --- a/app/services/projects_service.rb +++ b/app/services/projects_service.rb @@ -331,4 +331,28 @@ class ProjectsService {:status => status,:message => message} end + def send_wechat_project_issue_notice user,project,issue_id,issue_title,priority_id + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count + if count == 0 + title = "您有新的issue需要解决。" + remark = "点击详情查看issue。" + + case priority_id + when "1" + priority = "低" + when "2" + priority = "正常" + when "3" + priority = "高" + when "4" + priority = "紧急" + when "5" + priority = "立刻" + end + + ws = WechatService.new + ws.project_issue_notice user.id, "issues", issue_id,title, issue_title,priority, remark + end + end + end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 3b6cfe930..423676983 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -115,8 +115,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { touser:openid, @@ -149,8 +149,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { @@ -188,8 +188,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { @@ -417,8 +417,19 @@ class WechatService end Rails.logger.info "send over. #{req}" end + end - + def project_issue_notice(user_id, type, id, first, key1, key2,remark="",uid=0) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.project_issue_notice, type, id, first, key1, key2,remark,0 + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[project_issue_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end end end \ No newline at end of file diff --git a/app/views/avatar/_new_avatar_form.html.erb b/app/views/avatar/_new_avatar_form.html.erb index 2593bf1f5..d13a2a4d5 100644 --- a/app/views/avatar/_new_avatar_form.html.erb +++ b/app/views/avatar/_new_avatar_form.html.erb @@ -17,7 +17,8 @@ :upload_path => upload_avatar_path(:format => 'js'), :description_placeholder => nil ,# l(:label_optional_description) :source_type => source.class.to_s, - :source_id => source.id.to_s + :source_id => source.id.to_s, + :is_direct => 0 } %> <% content_for :header_tags do %> diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index 41cf3ab77..c2fa23242 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ -<% if @source_type=='User' %> +<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project') %> var imgSpan = $("img[nhname='avatar_image']"); imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); <% else %> diff --git a/app/views/boards/_course_new.html.erb b/app/views/boards/_course_new.html.erb index 90f0d9c7e..71f9d7c69 100644 --- a/app/views/boards/_course_new.html.erb +++ b/app/views/boards/_course_new.html.erb @@ -126,7 +126,7 @@
- +