diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2a772a949..09ca29178 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -23,6 +23,7 @@ class AttachmentsController < ApplicationController before_filter :delete_authorize, :only => [:destroy] before_filter :authorize_global, :only => [:upload] before_filter :authorize_attachment_download1, :only => [:download] + before_filter :has_login #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' @@ -67,6 +68,7 @@ class AttachmentsController < ApplicationController end def direct_download + @attachment.increment_download send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), :type => detect_content_type(@attachment), :disposition => 'attachment' #inline can open in browser @@ -77,7 +79,6 @@ class AttachmentsController < ApplicationController # 下载添加权限设置 candown = attachment_candown @attachment if candown || User.current.admin? || User.current.id == @attachment.author_id - @attachment.increment_download if stale?(:etag => @attachment.digest) if params[:preview] == 'true' convered_file = @attachment.diskfile @@ -511,4 +512,8 @@ private format.js end end + + def has_login + render_403 unless User.current.logged? + end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f58d6ea24..524bde9d7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -343,8 +343,8 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; - # 如果是ie11 需要转码 - if(/rv\:11\.0/.match(request.env["HTTP_USER_AGENT"]) != nil) + # 如果是ie 需要转码 + if(/trident/.match(request.env["HTTP_USER_AGENT"]) != nil) filename= URI::encode(filename) end respond_to do |format| @@ -695,21 +695,28 @@ class CoursesController < ApplicationController # 显示老师和助教的活动 # @authors = searchTeacherAndAssistant(@course) @authors = course_all_member(@course) + Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require file } events = [] - @authors.each do |author| - @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subprojects => false, - :author => author.user) - - @activity.scope_select {|t| has["show_#{t}"]} - # modify by nwb - # 添加私密性判断 - if User.current.member_of_course?(@course)|| User.current.admin? - events += @activity.events(@days, @course.created_at) - else - events += @activity.events(@days, @course.created_at, :is_public => 1) + key = "course_events_#{@course.id}".to_sym + if Rails.env.production? && Setting.course_cahce_enabled? + events = Rails.cache.read(key) || [] + end + if events.empty? + @authors.each do |author| + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => author.user) + + @activity.scope_select {|t| has["show_#{t}"]} + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events += @activity.events(@days, @course.created_at) + else + events += @activity.events(@days, @course.created_at, :is_public => 1) + end end - + Rails.cache.write(key, events) if Rails.env.production? && Setting.course_cahce_enabled? end else # @author = @course.teacher diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 06bc1fd38..d5e62127d 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -3,6 +3,7 @@ class HomeworkCommonController < ApplicationController before_filter :find_course, :only => [:index,:new,:create] before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment] + before_filter :member_of_course, :only => [:index] def index homeworks = @course.homework_commons.order("created_at desc") @@ -203,6 +204,11 @@ class HomeworkCommonController < ApplicationController render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? end + #当前用户是不是课程的成员 + def member_of_course + render_403 unless User.current.member_of_course?(@course) || User.current.admin? + end + def get_assigned_homeworks(student_works, n, index) student_works += student_works student_works[index + 1 .. index + n] diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index a222314ab..d8a9d88c3 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -483,6 +483,24 @@ class PollController < ApplicationController count_row += 1 end end + + sheet1.row(count_row).default_format = blue + sheet1[count_row ,0] = l(:label_bidding_user_studentname) + poll_questions.each_with_index do |poll_question, i| + sheet1[count_row ,i + 1] = poll_question.question_title + end + count_row += 1 + @poll.users.each do |user| + sheet1[count_row ,0] = user.show_name + poll_questions.each_with_index do |poll_question, i| + if poll_question.question_type == 1 || poll_question.question_type == 2 + sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") if poll_vote.poll_answer}.join(";") + else + sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ")}.join(";") + end + end + count_row += 1 + end book.write xls_report xls_report.string end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 30fd0ff50..c8cbde626 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,7 +2,7 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper require 'bigdecimal' - before_filter :find_homework, :only => [:new, :index, :create] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -233,6 +233,25 @@ class StudentWorkController < ApplicationController end end + #评价列表显示 + def student_work_absence_penalty + render_403 unless User.current.allowed_to?(:as_teacher,@course) + order = params[:order] || "desc" + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM( + SELECT * , + (SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count, + (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count + FROM `student_works` + WHERE homework_common_id = 213 + ) AS table_1 + ORDER BY absence #{order}") + @order = order == "desc" ? "asc" : "desc" + respond_to do |format| + format.html + end + end + private #获取作业 def find_homework diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 20b855fd8..9ce107f8b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -219,7 +219,7 @@ class WelcomeController < ApplicationController # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 def entry_select url = request.original_url.gsub('/','') - if url.include?(Setting.host_course.gsub('/','')) + if url.include?(Setting.url_course.gsub('/','')) if @first_page.show_course == 1 course render :course @@ -228,7 +228,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_contest.gsub('/','')) + elsif url.include?(Setting.url_contest.gsub('/','')) if @first_page.show_contest == 1 contest render :contest @@ -237,7 +237,7 @@ class WelcomeController < ApplicationController end return 0 - elsif url.include?(Setting.host_user.gsub('/','')) + elsif url.include?(Setting.url_user.gsub('/','')) #redirect_to(:controller => "users", :action => "index") end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ae70fd7c..5af4e2038 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2330,4 +2330,11 @@ module ApplicationHelper def cur_user_works_for_homework homework homework.student_works.where("user_id = ?",User.current).first end + + def file_preview_tag(file, html_options={}) + if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)} + link_to '预览', download_named_attachment_path(file.id, file.filename, preview: true),html_options + end + end + end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 990a563c4..7c85dc5c4 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -60,4 +60,14 @@ module StudentWorkHelper def is_praise_homework user_id, obj_id PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty? end + + #获取指定学生在指定作业内应匿评的数量 + def all_evaluation_count user,homework + StudentWorksEvaluationDistribution.joins(:student_work).where("student_works_evaluation_distributions.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count + end + + #获取指定学生在指定作业内已匿评的数量 + def has_evaluation_count user,homework + StudentWorksScore.joins(:student_work).where("student_works_scores.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count + end end \ No newline at end of file diff --git a/app/models/activity.rb b/app/models/activity.rb index e871ae735..5ec778641 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -5,4 +5,6 @@ class Activity < ActiveRecord::Base validates :act_id, presence: true validates :act_type, presence: true validates :user_id, presence: true + + include Trustie::Cache::ClearCourseEvent end diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index e94a29867..6b75552c0 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -19,4 +19,5 @@ class ForgeActivity < ActiveRecord::Base validates :project_id,presence: true validates :forge_act_id,presence: true validates :forge_act_type, presence: true + end diff --git a/app/models/member.rb b/app/models/member.rb index 5b1e277d7..057ea9570 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -129,6 +129,16 @@ class Member < ActiveRecord::Base StudentWork.select("homework_commons.name, student_works.final_score").joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}") end + #当前课程的作业列表 + def homework_common_list + HomeworkCommon.where(:course_id => self.course_id) + end + + #当前学生在指定作业内的得分 + def homework_common_score homework_common + StudentWork.select("final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + end + def student_work_score_avg StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").average(:final_score).try(:round, 2).to_f end diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 845e2b6a0..3dbc8d8ba 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -1,11 +1,13 @@ +
<% if defined?(container) && container && container.saved_attachments %> <% container.attachments.each_with_index do |attachment, i| %> - <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %> - <%= l(:field_is_public) %>: + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %><%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %><%= l(:field_is_public) %>: <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, attachment.is_public == 1 ? true : false, :class => 'is_public') %> <%= if attachment.id.nil? #待补充代码 diff --git a/app/views/bids/edit.html.erb b/app/views/bids/edit.html.erb index 37121d720..da3d19267 100644 --- a/app/views/bids/edit.html.erb +++ b/app/views/bids/edit.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= labelled_form_for @bid,:html => { :multipart => true } do |f| %> <%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 5beee8601..7eed593d9 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -66,7 +66,31 @@
@@ -92,7 +116,7 @@
-