diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cf4e6a8e9..b878a14ac 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -251,7 +251,7 @@ class AttachmentsController < ApplicationController @history.version = @old_history.nil? ? 1 : @old_history.version + 1 @history.save #历史记录保存完毕 #将最新保存的记录 数据替换到 需要修改的文件记录 - @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads") + @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes") @old_attachment.save #删除当前记录 @attachment.delete diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index be96124c2..f06a782bc 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -240,6 +240,18 @@ class CoursesController < ApplicationController # req[:message] = l(:modal_valid_passing) if req[:message].blank? render :json => req end + + def teacher_assign_group + member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first + member.course_group_id = params[:course_group_id].to_i + member.save + @course_groups = @course.course_groups + @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + respond_to do |format| + format.js + end + end + def join_group @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) @@ -838,6 +850,8 @@ class CoursesController < ApplicationController # render_403 # return # end + # 统计访问量 + @course.update_attribute(:visits, @course.visits.to_i + 1) #更新创建课程消息状态 create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0) create_course_messages.update_all(:viewed => true) @@ -1067,7 +1081,7 @@ class CoursesController < ApplicationController sql_select = "" if groupid == 0 sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) + SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} @@ -1079,7 +1093,7 @@ class CoursesController < ApplicationController WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) + SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 57cadc10b..b288629c8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -559,7 +559,8 @@ class FilesController < ApplicationController end end # 更新课程英雄榜得分 - update_contributor_score(@course, attachments[:files].first) + course_member_score(@course.id, attachments[:files].first.author_id, "Attachment") + # end # end # TODO: 临时用 nyan sort_init 'created_on', 'desc' @@ -632,18 +633,6 @@ class FilesController < ApplicationController end end - def update_contributor_score(course, file ) - course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first - if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) - else - score = course_contributor_score.resource_num + 5 - total_score = course_contributor_score.total_score + 5 - course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) - end - end - def get_project_tag_name_by_type_nmuber type case type when "1" diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 00b11323b..ba6c136bb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -17,9 +17,9 @@ class HomeworkCommonController < ApplicationController @page = params[:page] ? params[:page].to_i + 1 : 0 @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @is_teacher - @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) + @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) else - @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 0962deb10..f45e1dbd7 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -107,32 +107,18 @@ class NewsController < ApplicationController def show # 更新news对应的forge_messages的消息viewed字段 + ids = @news.comments.map { |comment| comment.id }.join(",") unless @news.comments.nil? if @project - query_message_news = @news.forge_messages + # 更新新闻 + query_message_news = ForgeMessage.where("forge_message_id =? and user_id =? and viewed =?", @news.id, User.current.id, 0).first + # 更新新闻的时候一并更新回复 + ForgeMessage.where("forge_message_id in (#{ids}) and forge_message_type = 'Comment' and user_id = #{User.current.id}").update_all(:viewed => true) unless ids.blank? else - query_message_news = @news.course_messages + query_message_news = CourseMessage.where("course_message_id =? and user_id =? and viewed =?", @news.id, User.current.id, 0).first + CourseMessage.where("course_message_id in (#{ids}) and course_message_type = 'Comment' and user_id = #{User.current.id}").update_all(:viewed => true) unless ids.blank? end - query_message_news.each do |query| - if User.current.id == query.user_id - query.update_attributes(:viewed => true) - end - end - # 更新项目新闻的评阅的消息viewed字段 - current_message_comments = @news.comments - current_message_comments.each do |current_message_comment| - if @project - query_message_comment = current_message_comment.forge_messages - else - query_message_comment = current_message_comment.course_messages - end - query_message_comment.each do |query| - if User.current.id == query.user_id - query.update_attributes(:viewed => true) - end - end - end - # end - + query_message_news.update_attribute(:viewed, true) unless query_message_news.nil? + # over cs = CoursesService.new result = cs.show_course_news params,User.current @news = result[:news] diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index f225e7f50..711663c3d 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -69,6 +69,8 @@ class OrganizationsController < ApplicationController def show if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) + # 统计访问量 + @organization.update_attribute(:visits, @organization.visits.to_i + 1) if params[:org_subfield_id] @org_subfield = OrgSubfield.find(params[:org_subfield_id]) @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b650afe1b..05c80a9fc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -298,6 +298,8 @@ class ProjectsController < ApplicationController if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end + # 统计访问量 + @project.update_attribute(:visits, @project.visits.to_i + 1) =begin cond = @project.project_condition(Setting.display_subprojects_issues?) has = { @@ -406,6 +408,7 @@ class ProjectsController < ApplicationController end flash.now[:error] = html if !html.to_s.blank? end + # for:设置默认分支 scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first @repository = Repository.factory(scm) @repository.is_default = @project.repository.nil? diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f7845d6f1..9bb6055ee 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -140,7 +140,7 @@ class RepositoriesController < ApplicationController attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?} redirect_to new_project_url(attrs, :course => '0') else - redirect_to settings_project_url(project) + redirect_to project_path(project) end } format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) } @@ -431,7 +431,10 @@ update def entry entry_and_raw(false) - render :layout => 'base_projects' + @content = @repository.cat(@path, @rev) + if is_entry_text_data?(@content, @path) + render :layout => 'base_projects' + end end def entry_and_raw(is_raw) @@ -443,9 +446,7 @@ update @content = @repository.cat(@path, @rev) (show_error_not_found; return) unless @content - if is_raw || - (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || - ! is_entry_text_data?(@content, @path) + if is_raw || (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || !is_entry_text_data?(@content, @path) # Force the download send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } send_type = Redmine::MimeType.of(@path) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index a38d83851..e297bc3cd 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -36,6 +36,14 @@ class StudentWorkController < ApplicationController unless student_work.save resultObj[:status] = 200 else + student_work.name = params[:title] + student_work.description = params[:src] + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty + else + student_work.late_penalty = 0 + end + student_work.save resultObj[:status] = result["status"].to_i resultObj[:time] = student_work_test.created_at.to_s(:db) resultObj[:index] = student_work.student_work_tests.count @@ -93,12 +101,12 @@ class StudentWorkController < ApplicationController end #老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 if @homework.is_open == 1 - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_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").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_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").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 @@ -106,10 +114,10 @@ class StudentWorkController < ApplicationController if pro.nil? @stundet_works = [] else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + @stundet_works = @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").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + @stundet_works = @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").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -129,15 +137,15 @@ class StudentWorkController < ApplicationController if pro.nil? my_work = [] else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + my_work = @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").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + my_work = @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").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_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").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true end else @@ -148,14 +156,14 @@ class StudentWorkController < ApplicationController return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (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").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else if @homework.is_open == 1 - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @stundet_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("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表 - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @stundet_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("#{@order} #{@b_sort}"),@name @show_all = true elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 @@ -163,10 +171,10 @@ class StudentWorkController < ApplicationController if pro.nil? @stundet_works = [] else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + @stundet_works = @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").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + @stundet_works = @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").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -186,15 +194,15 @@ class StudentWorkController < ApplicationController if pro.nil? my_work = [] else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + my_work = @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").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + my_work = @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").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @stundet_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("#{@order} #{@b_sort}"),@name @show_all = true end else @@ -205,7 +213,7 @@ class StudentWorkController < ApplicationController return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (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("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" @@ -303,6 +311,7 @@ class StudentWorkController < ApplicationController stu_project.save end end + @homework.update_attributes(:updated_at => Time.now) update_course_activity(@homework.class,@homework.id) update_user_activity(@homework.class,@homework.id) update_org_activity(@homework.class,@homework.id) @@ -500,6 +509,10 @@ class StudentWorkController < ApplicationController when 3 #学生评分 学生评分显示平均分 @work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f end + @homework.update_attributes(:updated_at => Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) if @work.save respond_to do |format| format.js diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 921262106..7fe146926 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -58,6 +58,7 @@ class UsersController < ApplicationController helper :sort helper :attachments include SortHelper + include ApplicationHelper helper :custom_fields include CustomFieldsHelper include AvatarHelper @@ -422,7 +423,7 @@ class UsersController < ApplicationController end def choose_user_course - homework = HomeworkCommon.find params[:homework].to_i + homework = HomeworkCommon.find params[:send_id].to_i if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} @@ -690,6 +691,11 @@ class UsersController < ApplicationController end student_work.save + homework.update_attributes(:updated_at => Time.now) + update_course_activity(homework.class,homework.id) + update_user_activity(homework.class,homework.id) + update_org_activity(homework.class,homework.id) + flash[:notice] = l(:notice_successful_create) redirect_to student_work_index_url(:homework => params[:homework]) else @@ -1168,6 +1174,10 @@ class UsersController < ApplicationController end def show + # 统计访问量 + unless User.current == @user + @user.update_attribute(:visits, @user.visits.to_i + 1) + end #更新用户申请成为课程老师或教辅消息的状态 if params[:course_id] != nil join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index d1aa67483..e6d1d9117 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -276,7 +276,7 @@ class WordsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE end - + @homework_common.update_attributes(:updated_at => Time.now) update_course_activity(@homework_common.class,@homework_common.id) update_user_activity(@homework_common.class,@homework_common.id) update_org_activity(@homework_common.class,@homework_common.id) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bf7a5fdf9..477e18f41 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -117,56 +117,102 @@ module ApplicationHelper when "HomeworkCommon" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1 , :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1) else score = course_contributor_score.homework_journal_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:homework_journal_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:homework_journal_num => score) end - when "JournalForMessage" + # 课程留言 + when "Course" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0) else score = course_contributor_score.journal_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:journal_num => score) end when "Message" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else - score = course_contributor_score.message_num + 2 - total_score = course_contributor_score.total_score + 2 - course_contributor_score.update_attributes(:message_num => score, :total_score => total_score) + score = course_contributor_score.message_num + 1 + course_contributor_score.update_attributes(:message_num => score) end when "MessageReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.message_reply_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:message_reply_num => score) end when "NewReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.news_reply_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:news_reply_num => score) end when "News" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.news_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:news_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:news_num => score) + end + when "Attachment" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0) + else + score = course_contributor_score.resource_num + 1 + course_contributor_score.update_attributes(:resource_num => score) + end + end + end + + # 删除某条记录相应减少课程统计数 + def down_course_score_num (course_id,user_id,type) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first + case type + when "HomeworkCommon" + unless course_contributor_score.nil? + score = course_contributor_score.homework_journal_num - 1 + course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score) + end + # 课程留言 + when "Course" + unless course_contributor_score.nil? + score = course_contributor_score.journal_num - 1 + course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score) + end + when "Message" + unless course_contributor_score.nil? + score = course_contributor_score.message_num - 1 + course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score) + end + when "MessageReply" + unless course_contributor_score.nil? + score = course_contributor_score.message_reply_num - 1 + course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score) + end + when "NewReply" + unless course_contributor_score.nil? + score = course_contributor_score.news_reply_num - 1 + course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score) + end + when "News" + unless course_contributor_score.nil? + score = course_contributor_score.news_num - 1 + course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score) + end + when "Attachment" + unless course_contributor_score.nil? + score = course_contributor_score.resource_num - 1 + course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score) end end end @@ -2895,3 +2941,13 @@ int main(int argc, char** argv){ end end end + +def user_url_in_org(user_id) + if Rails.env.development? + return "http://localhost:3000/users/" + user_id.to_s + elsif Rails.env.test? + return "https://www.test.forge.trustie.net/users/" + user_id.to_s + else + return "https://www.trustie.net/users/" + user_id.to_s + end +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index aff7ecc7d..4307d7a45 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -606,6 +606,24 @@ module CoursesHelper Course.tagged_with(tag_name).order('updated_at desc') end + #分班下拉框 + def course_group_option course + type = [] + option1 = [] + option1 << "暂无" + option1 << 0 + type << option1 + unless course.course_groups.nil? + course.course_groups.each do |cg| + option = [] + option << cg.name + option << cg.id + type << option + end + end + type + end + #课程实践年份下拉框 def course_time_option year type = [] diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 82f648ad9..9f0c2c559 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -43,6 +43,7 @@ class Attachment < ActiveRecord::Base #elasticsearch include Elasticsearch::Model + include ApplicationHelper #elasticsearch kaminari init Kaminari::Hooks.init Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari @@ -92,7 +93,7 @@ class Attachment < ActiveRecord::Base after_save :act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index - after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count + after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score # add by nwb # 获取所有可公开的资源文件列表 @@ -655,6 +656,12 @@ class Attachment < ActiveRecord::Base self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end + + def down_course_score + if self.container_type == "Course" + down_course_score_num(self.container_id, self.author_id, "Attachment") + end + end end # Delete the previous articles index in Elasticsearch diff --git a/app/models/comment.rb b/app/models/comment.rb index 4d7af1d73..b87203a50 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -36,6 +36,7 @@ class Comment < ActiveRecord::Base validates_presence_of :commented, :author, :comments safe_attributes 'comments' after_create :send_mail, :act_as_system_message, :act_as_student_score + after_destroy :down_course_score def act_as_system_message if self.commented.course @@ -86,4 +87,11 @@ class Comment < ActiveRecord::Base end end + # 课程新闻数减少 + def down_course_score + if self.commented.course + down_course_score_num(self.commented.course.id, self.author_id, "NewReply") + end + end + end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 7990979e4..dae779b65 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -73,7 +73,7 @@ class JournalsForMessage < ActiveRecord::Base #after_update :update_activity after_destroy :reset_counters! after_save :be_user_score - after_destroy :down_user_score + after_destroy :down_user_score, :down_course_score # default_scope { where('m_parent_id IS NULL') } @@ -184,6 +184,7 @@ class JournalsForMessage < ActiveRecord::Base end end end + # 更新用户分数 -by zjc def down_user_score #删除了留言回复 @@ -286,10 +287,19 @@ class JournalsForMessage < ActiveRecord::Base # 课程成员得分(活跃度) def act_as_student_score if self.jour_type == "Course" - course_member_score(self.jour_id, self.user_id, "JournalForMessage") + course_member_score(self.jour_id, self.user_id, "Course") elsif self.jour_type == "HomeworkCommon" course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon") end end + # 删除操作的时候相应扣掉回复数 + def down_course_score + if self.jour_type == "Course" + down_course_score_num(self.jour_id, self.user_id, "Course") + elsif self.jour_type == "HomeworkCommon" + down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon") + end + end + end diff --git a/app/models/member.rb b/app/models/member.rb index 413fedc07..ee329def8 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -150,7 +150,7 @@ class Member < ActiveRecord::Base #当前学生在指定作业内的得分 def homework_common_score homework_common - StudentWork.select("IF(final_score is null,null,final_score - absence_penalty - late_penalty) as final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + StudentWork.select("IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) end def student_work_score_avg @@ -158,7 +158,7 @@ class Member < ActiveRecord::Base end def student_work_score_sum - sql_select = "SELECT (SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) as score + sql_select = "SELECT (SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) as score FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{self.course_id} diff --git a/app/models/message.rb b/app/models/message.rb index 44f2d2c80..0ddc6f8e0 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -79,7 +79,7 @@ class Message < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity - after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count + after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message #before_save :be_user_score @@ -354,6 +354,18 @@ class Message < ActiveRecord::Base end end + # 删除帖子的时候更新课程帖子总数, 删除回复的时候减少总数 + def down_course_score + if self.course + if self.parent_id.nil? # 发帖 + down_course_score_num(self.course.id, self.author_id, "Message") + else + # 回帖 + down_course_score_num(self.course.id, self.author_id, "MessageReply") + end + end + end + def delete_org_activities OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all end diff --git a/app/models/news.rb b/app/models/news.rb index 028b6d737..6746d90cd 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -61,7 +61,7 @@ class News < ActiveRecord::Base after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score after_update :update_activity - after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities + after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -195,10 +195,18 @@ class News < ActiveRecord::Base OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all end + # 新增新闻统计数增加 def act_as_student_score if self.course course_member_score(self.course.id, self.author_id, "News") end end + # 删除新闻统计数减少 + def down_course_score + if self.course + down_course_score_num(self.course.id, self.author_id, "News") + end + end + end \ No newline at end of file diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index 35d9fe399..b399c6035 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -1,81 +1,146 @@ - -
- <%= l(:label_search_member_count) %> - <%= @result_count %> - <%= l(:label_member_people) %> -
- - <% end %> - -- <%= l(:label_no_data) %> -
-<% end%> - + ++ <%= l(:label_search_member_count) %> + <%= @result_count %> + <%= l(:label_member_people) %> +
+ + <% end %> + ++ <%= l(:label_no_data) %> +
+<% end%> + + + diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index f26c5fd41..f697383ca 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -6,7 +6,7 @@<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
+<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
<% if e_course.attachments.count > 0 %> <%= l(:project_module_attachments) %>(<%= link_to e_course.attachments.count, course_files_path(e_course), :class => "linkBlue2" %>) @@ -14,6 +14,7 @@ <% if e_course.homework_commons.count > 0 %> <%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>) <% end %> +
分数:<%=format("%.1f",score.to_i<0 ? 0 : score.to_i) %>分
@@ -303,14 +313,14 @@ <% replies_all_i = replies_all_i + 1 %>