diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index d53dc067c..0a95fd025 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -5,14 +5,17 @@ class ExerciseController < ApplicationController before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] include ExerciseHelper - include ExerciseHelper def index + if @course.is_public == 0 && !User.current.member_of_course?(@course) + render_403 + return + end remove_invalid_exercise(@course) @is_teacher = User.current.allowed_to?(:as_teacher,@course) if @is_teacher - exercises = @course.exercises + exercises = @course.exercises.order("created_at asc") else - exercises = @course.exercises.where(:exercise_status => 2) + exercises = @course.exercises.where(:exercise_status => 2).order("created_at asc") end @exercises = paginateHelper exercises,20 #分页 respond_to do |format| @@ -31,17 +34,24 @@ class ExerciseController < ApplicationController render_403 return end - @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? + exercise_end = Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") + if @exercise.time == -1 + @can_edit_excercise = exercise_end + else + @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end) || User.current.admin? + end @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first # 学生点击的时候即创建关联,自动保存 #eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) # 已提交问卷的用户不能再访问该界面 +=begin if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) respond_to do |format| format.html {render :layout => 'base_courses'} end else +=end if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first @@ -52,7 +62,7 @@ class ExerciseController < ApplicationController respond_to do |format| format.html {render :layout => 'base_courses'} end - end + #end end def new @@ -65,7 +75,6 @@ class ExerciseController < ApplicationController :end_time => "", :publish_time => "", :exercise_description => "", - :show_result => "", :show_result => 1 } @exercise = Exercise.create option @@ -80,7 +89,7 @@ class ExerciseController < ApplicationController exercise ||= Exercise.new exercise.exercise_name = params[:exercise][:exercise_name] exercise.exercise_description = params[:exercise][:exercise_description] - exercise.end_time = params[:exercise][:end_time] + exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) exercise.publish_time = params[:exercise][:publish_time] exercise.user_id = User.current.id exercise.time = params[:exercise][:time] @@ -104,10 +113,10 @@ class ExerciseController < ApplicationController def update @exercise.exercise_name = params[:exercise][:exercise_name] @exercise.exercise_description = params[:exercise][:exercise_description] - @exercise.time = params[:exercise][:time] - @exercise.end_time = params[:exercise][:end_time] + @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time] + @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) @exercise.publish_time = params[:exercise][:publish_time] - @exercise.show_result = params[:exercise][:show_result] + @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result] if @exercise.save respond_to do |format| format.js @@ -300,6 +309,7 @@ class ExerciseController < ApplicationController # 发布试卷 def publish_exercise @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] @exercise.exercise_status = 2 @exercise.publish_time = Time.now if @exercise.save @@ -314,11 +324,13 @@ class ExerciseController < ApplicationController # 重新发布的时候会删除所有的答题 def republish_exercise @is_teacher = User.current.allowed_to?(:as_teacher,@course) + @index = params[:index] @exercise.exercise_questions.each do |exercise_question| exercise_question.exercise_answers.destroy_all end @exercise.exercise_users.destroy_all @exercise.exercise_status = 1 + @exercise.publish_time = nil @exercise.save respond_to do |format| format.js @@ -328,7 +340,7 @@ class ExerciseController < ApplicationController def student_exercise_list @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @exercise = Exercise.find params[:id] - @all_exercises = @course.exercises.order("created_at desc") + @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") @exercise_count = @exercise.exercise_users.where('score is not NULL').count if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S")) @exercise_users_list = @exercise.exercise_users.where('score is not NULL') @@ -346,8 +358,8 @@ class ExerciseController < ApplicationController # 学生提交答卷,选中答案的过程中提交 def commit_answer eq = ExerciseQuestion.find(params[:exercise_question_id]) - # 已提交过的则不允许答题 - if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) + # 已提交过的且是限时的则不允许答题 + if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") < Time.now.strftime("%Y-%m-%d %H:%M:%S") render :json => {:text => "failure"} return end @@ -364,8 +376,14 @@ class ExerciseController < ApplicationController ea.exercise_choice_id = params[:exercise_choice_id] if ea.save # 保存成功返回成功信息及当前以答题百分比 + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)} + render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)} else #返回失败信息 render :json => {:text => "failure"} @@ -380,8 +398,14 @@ class ExerciseController < ApplicationController ea.exercise_question_id = params[:exercise_question_id] ea.exercise_choice_id = params[:exercise_choice_id] if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end @percent = get_percent(@exercise,User.current) - render :json => {:text => "ok",:percent => format("%.2f" ,@percent)} + render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)} else render :json => {:text => "failure"} end @@ -410,8 +434,14 @@ class ExerciseController < ApplicationController ea.exercise_question_id = params[:exercise_question_id] ea.answer_text = params[:answer_text] if ea.save + uncomplete_question = get_uncomplete_question(@exercise, User.current) + if uncomplete_question.count < 1 + complete = 1; + else + complete = 0; + end @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:percent => format("%.2f",@percent)} + render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)} else render :json => {:text => "failure"} end @@ -447,6 +477,17 @@ class ExerciseController < ApplicationController def commit_exercise # 老师不需要提交 if User.current.allowed_to?(:as_teacher,@course) + if @exercise.publish_time.nil? + @exercise.update_attributes(:show_result => params[:show_result]) + @exercise.update_attributes(:exercise_status => 2) + @exercise.update_attributes(:publish_time => Time.now) + redirect_to exercise_url(@exercise) + return + elsif Time.parse(@exercise.publish_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S") + @exercise.update_attributes(:show_result => params[:show_result]) + redirect_to exercise_url(@exercise) + return + end @exercise.update_attributes(:show_result => params[:show_result]) redirect_to exercise_url(@exercise) # REDO: 提示提交成功 @@ -490,7 +531,7 @@ class ExerciseController < ApplicationController exercise_qustions.each do |question| answer = get_user_answer(question, user) standard_answer = get_user_standard_answer(question, user) - unless answer.nil? + unless answer.empty? # 问答题有多个答案 if question.question_type == 3 if standard_answer.include?(answer.first.answer_text) @@ -532,19 +573,6 @@ class ExerciseController < ApplicationController eu end - #获取未完成的题目 - def get_uncomplete_question exercise,user - all_questions = exercise.exercise_questions - uncomplete_question = [] - all_questions.each do |question| - answers = get_user_answer(question, user) - if answers.nil? - uncomplete_question << question - end - end - uncomplete_question - end - # 获取当前学生回答问题的答案 def get_user_answer(question,user) # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first @@ -563,7 +591,8 @@ class ExerciseController < ApplicationController standard_answer = question.exercise_standard_answers.first end standard_answer - end # 是否完成了答题 + end + # 是否完成了答题 def get_complete_question(exercise,user) questions = exercise.exercise_questions complete_question = [] diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a2902e3fc..b15be4896 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,6 +374,9 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end + # 更新课程英雄榜得分 + update_contributor_score(@course, attachments[:files].first) + # end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type @@ -423,6 +426,20 @@ class FilesController < ApplicationController end end + def update_contributor_score(course, file ) + unless file.author.allowed_to?(:as_teacher, course) + 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 + end + def get_tag_name_by_type_number type case type when "1" diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1f252cc24..2bd54954a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,7 +34,7 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -42,7 +42,7 @@ class RepositoriesController < ApplicationController include RepositoriesHelper helper :project_score #@root_path = RepositoriesHelper::ROOT_PATH - + $g=Gitlab.client rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed def new @@ -63,6 +63,78 @@ class RepositoriesController < ApplicationController end + def forked + # 被forked的标识如果不满足单个用户唯一性,则不执行fork + if is_sigle_identifier?(User.current, @repository.identifier) + # REDO: 那些人有权限forked项目 + g = Gitlab.client + gproject = g.post ("/projects/fork/#{@project.gpid}?user_id=#{User.current.gid}") + if gproject + copy_project(@project, gproject) + end + else + flash[:notice] = l(:project_gitlab_fork_double_message) + redirect_to settings_project_url(@project, :tab => 'repositories') + end + end + + # copy a project for fork + def copy_project(project, gproject) + project = Project.new + project.name = @project.name + project.is_public = @project.is_public + project.status = @project.status + project.description = @project.description + project.hidden_repo = @project.hidden_repo + project.user_id = User.current.id + project.project_type = 0 + project.project_new_type = @project.project_new_type + project.gpid = gproject.id + if project.save + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id) + user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id) + Rails.logger.debug "UserGrade created: #{user_grades.to_json}" + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0) + Rails.logger.debug "ProjectStatus created: #{project_status.to_json}" + project.members << m + project.project_infos << project_info + copy_repository(project, gproject) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + 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) + end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) } + format.js + end + else + respond_to do |format| + format.html { render :action => 'forked', :layout => 'base_projects'} + format.api { render_validation_errors(@project) } + end + end + end + + def copy_repository(project, gproject) + # 避免 + if is_sigle_identifier?(project.user_id, gproject.name) + repository = Repository.factory('Git') + repository.project_id = project.id + repository.type = 'Repository::Gitlab' + repository.url = gproject.name + repository.identifier = gproject.name + repository = repository.save + else + flash[:notice] = l(:project_gitlab_create_double_message) + end + end def newrepo scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first @@ -115,21 +187,27 @@ update } def create - attrs = pickup_extra_info - @repository = Repository.factory('Git') - @repository.safe_attributes = params[:repository] - if attrs[:attrs_extra].keys.any? - @repository.merge_extra_info(attrs[:attrs_extra]) - end - @repository.project = @project - @repository.type = 'Repository::Gitlab' - @repository.url = @repository.identifier - if request.post? && @repository.save - s = Trustie::Gitlab::Sync.new - s.create_project(@project, @repository) + # 判断版本库创建者是否有同名版本库,避免版本库路径一致问题 + unless is_sigle_identifier?(@project.user_id, params[:repository].first[1]) + flash[:notice] = l(:project_gitlab_create_double_message) redirect_to settings_project_url(@project, :tab => 'repositories') else - redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages) + attrs = pickup_extra_info + @repository = Repository.factory('Git') + @repository.safe_attributes = params[:repository] + if attrs[:attrs_extra].keys.any? + @repository.merge_extra_info(attrs[:attrs_extra]) + end + @repository.project = @project + @repository.type = 'Repository::Gitlab' + @repository.url = @repository.identifier + if request.post? && @repository.save + s = Trustie::Gitlab::Sync.new + s.create_project(@project, @repository) + redirect_to settings_project_url(@project, :tab => 'repositories') + else + redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages) + end end end @@ -237,14 +315,34 @@ update #Modified by young # (show_error_not_found; return) unless @entries g = Gitlab.client - count = 0 - (0..100).each do |page| - if g.commits(@project.gpid,:page => page).count == 0 - break - else - count = count + g.commits(@project.gpid,:page => page).count - end + + # count = 0 + # (0..100).each do |page| + # if g.commits(@project.gpid,:page => page).count == 0 + # break + # else + # count = count + g.commits(@project.gpid,:page => page).count + # end + # end + + + #add by hx + if g.commits(@project.gpid , :page=>25).count==0 + count = count_commits(@project.gpid , 0 , 25) + elsif g.commits(@project.gpid , :page=>50).count ==0 + count = count_commits(@project.gpid , 25 , 50)+ 25 * 20 + elsif g.commits(@project.gpid , :page=>75).count ==0 + count = count_commits(@project.gpid , 50 , 75)+ 50 * 20 + elsif g.commits(@project.gpid , :page=>100).count== 0 + count = count_commits(@project.gpid , 75 , 100) + 75 * 20 + elsif g.commits(@project.gpid , :page=>125).count==0 + count = count_commits(@project.gpid , 100 , 125) + 100 * 20 + elsif g.commits(@project.gpid , :page=>150).count==0 + count = count_commits(@project.gpid , 125 , 150) + 125 * 20 + else + count = count_commits(@project.gpid , 150 ,200) + 150 * 20 end + @changesets = g.commits(@project.gpid) # @changesets = @repository.latest_changesets(@path, @rev) # @changesets_count = @repository.latest_changesets(@path, @rev).count @@ -271,11 +369,30 @@ update alias_method :browse, :show + #add by hx + def count_commits(project_id , left , right) + count = 0 + (left..right).each do |page| + if $g.commits(project_id,:page => page).count == 0 + break + else + count = count + $g.commits(project_id,:page => page).count + end + end + return count + end + def changes @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry g = Gitlab.client - @commits = g.commits(@project.gpid, page:params[:pamge]) + limit = 20 + #每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来 + @commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s) + #页面传递必须要str类型,但是Paginator的初始化必须要num类型,需要类型转化 + @commits_count = params[:commit_count].to_i + @commits_pages = Redmine::Pagination::Paginator.new @commits_count,limit,params[:page] + @commit = g.commit(@project.gpid,@rev) # @changesets = g.get ("/projects/#{@project.gpid}/repository/commits?#{@rev}") #@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) @@ -284,6 +401,7 @@ update render :layout => 'base_projects' end + def revisions @changeset_count = @repository.changesets.count @changeset_pages = Paginator.new @changeset_count, @@ -467,8 +585,8 @@ update def find_repository @repository = Repository.find(params[:id]) @project = @repository.project - rescue ActiveRecord::RecordNotFound - render_404 + rescue ActiveRecord::RecordNotFound + render_404 end REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9ad46cd69..d2aba1386 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -76,7 +76,7 @@ class StudentWorkController < ApplicationController end ################################################################################################################## @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group] - @homework_commons = @course.homework_commons.order("created_at desc") + @homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评 @show_all = false @@ -167,6 +167,18 @@ class StudentWorkController < ApplicationController end def create + # 提交作品前先判断是否已经提交 + @has_commit = false; + if hsd_committed_work?(User.current.id, @homework.id) + @work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first + @has_commit = true; + #flash[:notice] = l(:notice_successful_create) + #redirect_to edit_student_work_url(params[:student_work]) + respond_to do |format| + format.js + end + return + end if params[:student_work] @submit_result = true student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id] @@ -499,6 +511,12 @@ class StudentWorkController < ApplicationController end private + def hsd_committed_work?(user, homework) + sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first + sw.nil? ? result = false : result = true + result + end + #获取作业 def find_homework @homework = HomeworkCommon.find params[:homework] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f4e0f88ff..046e0c5a0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,6 +75,50 @@ module ApplicationHelper end end + # 更新课程英雄榜得分 + # user传过来必须是学生 + def course_member_score(course_id,user_id,type) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first + case type + when "JournalForMessage" + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + end + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index caca6fb1e..a1b119cb5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -25,6 +25,10 @@ module CoursesHelper # searchTeacherAndAssistant(project).count end + def show_nav?(count) + count == 0 ? true : false + end + #课程模块需要展示的模块 def course_model @nav_dispaly_course_all_label = 1 @@ -733,4 +737,26 @@ module CoursesHelper end desc.html_safe end + + # 学生按作业总分排序,取前8个 + def hero_homework_score(course, score_sort_by) + sql_select = "SELECT members.*,( + SELECT SUM(student_works.final_score) + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = #{course.id} + AND student_works.user_id = members.user_id + ) AS score + FROM members + JOIN students_for_courses + ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id + WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9" + homework_scores = Member.find_by_sql(sql_select) + end + + def contributor_course_scor(course_id) + ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9) + end + end + diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index bb87f3b82..b0d0118e5 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -107,6 +107,19 @@ module ExerciseHelper end end + #获取未完成的题目 + def get_uncomplete_question exercise,user + all_questions = exercise.exercise_questions + uncomplete_question = [] + all_questions.each do |question| + answers = get_user_answer(question, user) + if answers.empty? + uncomplete_question << question + end + end + uncomplete_question + end + #获取文本题答案 def get_anwser_vote_text(question_id,user_id) pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index f32bef51b..ff4aa61fb 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -27,6 +27,20 @@ module RepositoriesHelper REPO_IP_ADDRESS = Setting.host_repository REPO_GITLAB_ADDRESS = "git.trustie.net" + # 某个成员不能拥有同名版本库,不同的成员可以创建同名版本库 + def is_sigle_identifier?(user_id, iden) + projects = Project.where("user_id =?",user_id) + identifiers = [] + projects.each do |project| + # 只针对gitlab类型的,git类型的后期清掉 + repository = Repository.where("project_id =? and type =?", project.id, "Repository::Gitlab").first + if repository + identifiers << repository.identifier + end + end + identifiers.include?(iden) ? false :true + end + def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier @@ -47,7 +61,7 @@ module RepositoriesHelper def user_commit_rep(mail) user = User.find_by_mail(mail) - user.nil? ? User.find(2) : User.find_by_mail(mail) + #user.nil? ? User.find(2) : User.find_by_mail(mail) end def render_properties(properties) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f7fb9b1aa..9c6bb9cb1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -560,4 +560,5 @@ class Attachment < ActiveRecord::Base self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) end end + end diff --git a/app/models/comment.rb b/app/models/comment.rb index bb31eb894..9de25c50d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -35,7 +35,7 @@ class Comment < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments safe_attributes 'comments' - after_create :send_mail, :act_as_system_message + after_create :send_mail, :act_as_system_message, :act_as_student_score def act_as_system_message if self.commented.course @@ -66,13 +66,24 @@ class Comment < ActiveRecord::Base def set_notify_id(notify_id) @notify_id= notify_id end + def get_notify_id() return @notify_id end + def set_notify_is_read(notify_is_read) @notify_is_read = notify_is_read end + def get_notify_is_read() return @notify_is_read end + + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.author.allowed_to?(:as_teacher, self.commented.course) + course_member_score(self.commented.course.id, self.author_id, "NewReply") + end + end + end diff --git a/app/models/course.rb b/app/models/course.rb index 1350b8cf7..ec1afd611 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -40,8 +40,10 @@ class Course < ActiveRecord::Base has_many :course_activities # 课程消息 - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :exercises, :dependent => :destroy + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb new file mode 100644 index 000000000..f2b05458f --- /dev/null +++ b/app/models/course_contributor_score.rb @@ -0,0 +1,5 @@ +class CourseContributorScore < ActiveRecord::Base + attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score + belongs_to :course + belongs_to :user +end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 5e40267cb..eaece95ce 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -64,7 +64,7 @@ class JournalsForMessage < ActiveRecord::Base has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -263,4 +263,12 @@ class JournalsForMessage < ActiveRecord::Base end end + + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.user.allowed_to?(:as_teacher, self.jour) + course_member_score(self.jour_id, self.user_id, "JournalForMessage") + end + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 7af59815b..21e5e1c71 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -74,7 +74,7 @@ class Message < ActiveRecord::Base after_update :update_messages_board after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail + 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 #before_save :be_user_score scope :visible, lambda {|*args| @@ -285,4 +285,16 @@ class Message < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.author.allowed_to?(:as_teacher, self.course) + if self.parent_id.nil? + # 发帖 + course_member_score(self.course.id, self.author_id, "Message") + else + # 回帖 + course_member_score(self.course.id, self.author_id, "MessageReply") + end + end + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 94b7905c6..f50f37f31 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -40,7 +40,8 @@ class Repository < ActiveRecord::Base validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } #validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true - validates_uniqueness_of :identifier, :allow_blank => true + # 改成同一用户不能有两个相同名字的版本库 + # validates_uniqueness_of :identifier, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) # donwcase letters, digits, dashes, underscores but not digits only validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true @@ -52,7 +53,8 @@ class Repository < ActiveRecord::Base 'password', 'path_encoding', 'log_encoding', - 'is_default' + 'is_default', + 'type' safe_attributes 'url', :if => lambda {|repository, user| repository.new_record?} @@ -63,6 +65,10 @@ class Repository < ActiveRecord::Base end def repo_create_validation + # 之所以可以这样改,是因为Fork的时候不需要从Trustie创建版本库,只需从Gitlab关联即可 + if self.class.name.demodulize == "Repository" + return + end unless Setting.enabled_scm.include?(self.class.name.demodulize) errors.add(:type, :invalid) end diff --git a/app/models/user.rb b/app/models/user.rb index 3e7bc2ddb..cd8b96d47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,6 +153,8 @@ class User < Principal # 邮件邀请状态 has_many :invite_lists, :dependent => :destroy # end + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy ######added by nie has_many :project_infos, :dependent => :destroy diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb new file mode 100644 index 000000000..9a36b8efb --- /dev/null +++ b/app/views/courses/_tool_expand.html.erb @@ -0,0 +1,47 @@ +<% course_file_num = visable_attachemnts_incourse(@course).count%> +<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> +<% if show_nav?(@course.homework_commons.count) %> +
当前测验 - <% if question_count > 0 %>共有<%= question_count %>道题,其中<% end %> - <% if mc_count > 0 %><%= mc_count %>道单选、<% end %> - <% if mcq_count > 0 %><%= mcq_count %>道多选、<% end %> - <% if single_count > 0%><%= single_count %>道填空,<% end %> - 总分为<%=current_score %>分。 +
当前测验<%if question_count >0%>共有<%= question_count %>道题,其中<%end%><%if mc_count > 0%><%=mc_count %>道单选、<%end%><%if mcq_count > 0%><%=mcq_count %>道多选、<%end%><%if single_count > 0%><%=single_count %>道填空,<%end%>总分为<%=current_score %>分。
- 是否确定提交该测验?
+ <% if exercise.publish_time.nil? %>点击提交后测验将立即发布,<% end %>是否确定提交该测验?
- - | -
- - | -
<%=link_to student_score.user, user_path(student_score.user), :title => student_score.user %>
+<%= student_score.score.to_i %>
+