diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index cec419eba..90981b52a 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -51,6 +51,37 @@ class AdminController < ApplicationController end end + #管理员界面精品课程列表 + def excellent_courses + @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) + respond_to do |format| + format.html + end + end + + #管理员界面课程资源列表 + def course_resource_list + @resource = Attachment.where(:container_type => 'Course') + @resource = paginateHelper @resource,30 + @page = (params['page'] || 1).to_i - 1 + + respond_to do |format| + format.html + end + end + + #管理员界面項目资源列表 + def project_resource_list + @pro_resource = Attachment.where(:container_type => 'Project') + @pro_resource = paginateHelper @pro_resource,30 + @page = (params['page'] || 1).to_i - 1 + + respond_to do |format| + format.html + end + end + + def users sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 708ac9a14..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) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b288629c8..b6ac99f11 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -854,9 +854,7 @@ class FilesController < ApplicationController @result = visable_attachemnts @result if params[:other] @result = @result.select{|attachment| - attachment.tag_list.exclude?('软件') && - attachment.tag_list.exclude?('媒体') && - attachment.tag_list.exclude?('代码') + attachment.tag_list.index{|tag|tag != '软件' and tag != '媒体' and tag != '代码'}.present? } else @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index ba6c136bb..9f754a0fc 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -1,378 +1,378 @@ -class HomeworkCommonController < ApplicationController - require 'net/http' - require 'json' - require "base64" - layout "base_courses" - - include StudentWorkHelper - 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,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :member_of_course, :only => [:index] - - def index - @new_homework = HomeworkCommon.new - @new_homework.homework_detail_manual = HomeworkDetailManual.new - @new_homework.course = @course - @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("updated_at desc").limit(10).offset(@page * 10) - else - @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] - - #设置at已读 - @homeworks.each do |homework| - homework.journals_for_messages.each do |j| - User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} - end - end - - respond_to do |format| - format.js - format.html - end - end - - #新建作业,在个人作业列表创建作业 - def new - render_404 - end - - #新建作业,在个人作业列表创建作业 - def create - redirect_to user_homeworks_user_path(User.current.id) - end - - def edit - @user = User.current - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.html{render :layout => 'new_base_user'} - end - end - - def update - if params[:homework_common] - @homework.name = params[:homework_common][:name] - @homework.description = params[:homework_common][:description] - if params[:homework_common][:publish_time] == "" - @homework.publish_time = Date.today - else - @homework.publish_time = params[:homework_common][:publish_time] - end - @homework.end_time = params[:homework_common][:end_time] || Time.now - @homework.course_id = params[:course_id] - @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 - - homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new - if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 - homework_detail_manual.comment_status = 1 - end - homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] - homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] - - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - - #编程作业相关属性 - if @homework.homework_type == 2 - @homework.homework_detail_programing ||= HomeworkDetailPrograming.new - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_programing.language = params[:language_type].to_i - - @homework.homework_tests.delete_all - inputs = params[:program][:input] - if Array === inputs - inputs.each_with_index do |val, i| - @homework.homework_tests << HomeworkTest.new( - input: val, - output: params[:program][:output][i] - ) - end - end - end - - #分组作业 - if @homework.homework_type == 3 - @homework.homework_detail_group ||= HomeworkDetailGroup.new - @homework_detail_group = @homework.homework_detail_group - @homework_detail_group.min_num = params[:min_num].to_i - @homework_detail_group.max_num = params[:max_num].to_i - @homework_detail_group.base_on_project = params[:base_on_project].to_i - end - - if @homework.save - @homework_detail_manual.save if @homework_detail_manual - @homework_detail_programing.save if @homework_detail_programing - @homework_detail_group.save if @homework_detail_group - - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - end - end - end - - def destroy - if @homework.destroy - respond_to do |format| - format.html { - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - } - end - end - end - - #开启匿评 - #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 - def start_anonymous_comment - @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) - @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") - if @homework_detail_manual.comment_status == 1 - student_works = @homework.student_works - if student_works && student_works.size >= 2 - if @homework.homework_type == 3 - student_work_projects = @homework.student_work_projects.where("student_work_id is not null") - student_work_projects.each_with_index do |pro_work, pro_index| - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.id.to_i == pro_work.student_work_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - else - student_works.each_with_index do |work, index| - user = work.user - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - end - @homework_detail_manual.update_column('comment_status', 2) - @homework_detail_manual.update_column('evaluation_start', Date.today) - @statue = 1 - # 匿评开启消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 2) - Mailer.send_mail_anonymous_comment_open(@homework).deliver - else - @statue = 2 - - end - else - @statue = 3 - end - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - - #关闭匿评 - def stop_anonymous_comment - @homework_detail_manual.update_column('comment_status', 3) - @homework_detail_manual.update_column('evaluation_end', Date.today) - #计算缺评扣分 - work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" - @homework.student_works.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - # 匿评关闭消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 3) - Mailer.send_mail_anonymous_comment_close(@homework).deliver - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - # 开启/关闭匿评消息通知 - def send_message_anonymous_comment(homework, m_status ) - # status 标记匿评状态 1为关闭 0为开启 - course = homework.course - course.members.each do |m| - @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) - end - end - #提示 - def alert_anonymous_comment - @cur_size = 0 - @totle_size = 0 - if @homework_detail_manual.comment_status == 1 - @totle_size = @course.student.count - @cur_size = @homework.student_works.size - elsif @homework_detail_manual.comment_status == 2 - @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} - @cur_size = 0 - @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} - end - @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - def alert_forbidden_anonymous_comment - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def open_student_works - if @homework.is_open == 0 - @homework.update_attribute(:is_open, 1) - else - @homework.update_attribute(:is_open, 0) - end - @user_activity_id = params[:user_activity_id] - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - end - - def alert_open_student_works - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def programing_test - test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} - @index = params[:index] - uri = URI('http://192.168.80.21:8080/api/realtime.json') - body = test.to_json - res = Net::HTTP.new(uri.host, uri.port).start do |client| - request = Net::HTTP::Post.new(uri.path) - request.body = body - request["Content-Type"] = "application/json" - client.request(request) - end - result = JSON.parse(res.body) - @err_msg = result["compile_error_msg"] - result["results"].each do |re| - @result = re["status"] - end - end - - #启动匿评参数设置 - def start_evaluation_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - #设置匿评参数 - def set_evaluation_attr - if @homework_detail_manual - unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s - @homework_detail_manual.evaluation_start = params[:evaluation_start] - end - - unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s - @homework_detail_manual.evaluation_end = params[:evaluation_end] - end - - @homework_detail_manual.evaluation_num = params[:evaluation_num] - @homework_detail_manual.save - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - end - - #评分设置 - def score_rule_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - private - #获取课程 - def find_course - @course = Course.find params[:course] - rescue - render_404 - end - #获取作业 - def find_homework - @homework = HomeworkCommon.find params[:id] - @homework_detail_manual = @homework.homework_detail_manual - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_group = @homework.homework_detail_group - @course = @homework.course - rescue - render_404 - end - #是不是课程的老师 - def teacher_of_course - render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - end - - #当前用户是不是课程的成员 - def member_of_course - render_403 unless @course.is_public==1 || 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] - end -end +class HomeworkCommonController < ApplicationController + require 'net/http' + require 'json' + require "base64" + layout "base_courses" + + include StudentWorkHelper + 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,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :member_of_course, :only => [:index] + + def index + @new_homework = HomeworkCommon.new + @new_homework.homework_detail_manual = HomeworkDetailManual.new + @new_homework.course = @course + @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("updated_at desc").limit(10).offset(@page * 10) + else + @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] + + #设置at已读 + @homeworks.each do |homework| + homework.journals_for_messages.each do |j| + User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} + end + end + + respond_to do |format| + format.js + format.html + end + end + + #新建作业,在个人作业列表创建作业 + def new + render_404 + end + + #新建作业,在个人作业列表创建作业 + def create + redirect_to user_homeworks_user_path(User.current.id) + end + + def edit + @user = User.current + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.html{render :layout => 'new_base_user'} + end + end + + def update + if params[:homework_common] + @homework.name = params[:homework_common][:name] + @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end + @homework.end_time = params[:homework_common][:end_time] || Time.now + @homework.course_id = params[:course_id] + @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 + + homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + homework_detail_manual.comment_status = 1 + end + homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] + homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] + + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + #编程作业相关属性 + if @homework.homework_type == 2 + @homework.homework_detail_programing ||= HomeworkDetailPrograming.new + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_programing.language = params[:language_type].to_i + + @homework.homework_tests.delete_all + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + @homework.homework_tests << HomeworkTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if @homework.homework_type == 3 + @homework.homework_detail_group ||= HomeworkDetailGroup.new + @homework_detail_group = @homework.homework_detail_group + @homework_detail_group.min_num = params[:min_num].to_i + @homework_detail_group.max_num = params[:max_num].to_i + @homework_detail_group.base_on_project = params[:base_on_project].to_i + end + + if @homework.save + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + @homework_detail_group.save if @homework_detail_group + + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + end + end + end + + def destroy + if @homework.destroy + respond_to do |format| + format.html { + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + } + end + end + end + + #开启匿评 + #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 + def start_anonymous_comment + @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) + @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if @homework_detail_manual.comment_status == 1 + student_works = @homework.student_works + if student_works && student_works.size >= 2 + if @homework.homework_type == 3 + student_work_projects = @homework.student_work_projects.where("student_work_id is not null") + student_work_projects.each_with_index do |pro_work, pro_index| + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.id.to_i == pro_work.student_work_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + else + student_works.each_with_index do |work, index| + user = work.user + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + @homework_detail_manual.update_column('comment_status', 2) + @homework_detail_manual.update_column('evaluation_start', Date.today) + @statue = 1 + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) + Mailer.send_mail_anonymous_comment_open(@homework).deliver + else + @statue = 2 + + end + else + @statue = 3 + end + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + + #关闭匿评 + def stop_anonymous_comment + @homework_detail_manual.update_column('comment_status', 3) + @homework_detail_manual.update_column('evaluation_end', Date.today) + #计算缺评扣分 + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @homework.student_works.each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + # 匿评关闭消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 3) + Mailer.send_mail_anonymous_comment_close(@homework).deliver + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + # 开启/关闭匿评消息通知 + def send_message_anonymous_comment(homework, m_status ) + # status 标记匿评状态 1为关闭 0为开启 + course = homework.course + course.members.each do |m| + @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) + end + end + #提示 + def alert_anonymous_comment + @cur_size = 0 + @totle_size = 0 + if @homework_detail_manual.comment_status == 1 + @totle_size = @course.student.count + @cur_size = @homework.student_works.size + elsif @homework_detail_manual.comment_status == 2 + @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} + @cur_size = 0 + @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} + end + @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + def alert_forbidden_anonymous_comment + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def open_student_works + if @homework.is_open == 0 + @homework.update_attribute(:is_open, 1) + else + @homework.update_attribute(:is_open, 0) + end + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + end + + def alert_open_student_works + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def programing_test + test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} + @index = params[:index] + uri = URI('http://192.168.80.21:8080/api/realtime.json') + body = test.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + result = JSON.parse(res.body) + @err_msg = result["compile_error_msg"] + result["results"].each do |re| + @result = re["status"] + end + end + + #启动匿评参数设置 + def start_evaluation_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + #设置匿评参数 + def set_evaluation_attr + if @homework_detail_manual + unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s + @homework_detail_manual.evaluation_start = params[:evaluation_start] + end + + unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s + @homework_detail_manual.evaluation_end = params[:evaluation_end] + end + + @homework_detail_manual.evaluation_num = params[:evaluation_num] + @homework_detail_manual.save + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + end + + #评分设置 + def score_rule_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + private + #获取课程 + def find_course + @course = Course.find params[:course] + rescue + render_404 + end + #获取作业 + def find_homework + @homework = HomeworkCommon.find params[:id] + @homework_detail_manual = @homework.homework_detail_manual + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_group = @homework.homework_detail_group + @course = @homework.course + rescue + render_404 + end + #是不是课程的老师 + def teacher_of_course + render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + end + + #当前用户是不是课程的成员 + def member_of_course + render_403 unless @course.is_public==1 || 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] + end +end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index dbefd82cb..f45e1dbd7 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -107,28 +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 = ForgeMessage.where("forge_message_id =? and user_id =?", @news.id, User.current.id).first + # 更新新闻 + 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 = CourseMessage.where("course_message_id =? and user_id =?", @news.id, User.current.id).first + 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.update_attribute(:viewed, true) - # 更新项目新闻的评阅的消息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 3d5030c29..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 = { diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index e297bc3cd..aa77e2d51 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -99,16 +99,18 @@ class StudentWorkController < ApplicationController else student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')' end - #老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if @homework.is_open == 1 - @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?) + #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 + if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @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?) + if @order == 'lastname' + @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("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + elsif @order == 'student_id' + @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}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + else @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 #学生 && 未开启匿评 只看到自己的 + end + @show_all = true + elsif User.current.member_of_course?(@course) + if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 pro = @homework.student_work_projects.where(:user_id => User.current.id).first if pro.nil? @@ -145,7 +147,13 @@ class StudentWorkController < ApplicationController if my_work.empty? @stundet_works = [] else - @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 + if @order == 'lastname' + @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("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + elsif @order == 'student_id' + @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}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + else + @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 + end @show_all = true end else @@ -158,14 +166,17 @@ class StudentWorkController < ApplicationController @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,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?) #老师 || 超级管理员 显示所有列表 + if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @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?) + if @order == 'lastname' + @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).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + elsif @order == 'student_id' + @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("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + else @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 #学生 && 未开启匿评 只看到自己的 + end + @show_all = true + elsif User.current.member_of_course?(@course) + if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 if @homework.homework_type == 3 pro = @homework.student_work_projects.where(:user_id => User.current.id).first if pro.nil? @@ -202,7 +213,13 @@ class StudentWorkController < ApplicationController if my_work.empty? @stundet_works = [] else - @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 + if @order == 'lastname' + @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).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + elsif @order == 'student_id' + @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("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + else + @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 + end @show_all = true end else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bb5f3acb3..9a005cf16 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -377,13 +377,15 @@ class UsersController < ApplicationController #用户作业列表 def user_homeworks + @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" @user = User.current + @r_sort = @b_sort == "desc" ? "asc" : "desc" if(params[:type].blank? || params[:type] == "1") #公共题库 visible_course = Course.where("is_public = 1 && is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc") + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #我的题库 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") end @type = params[:type] @limit = 15 @@ -526,20 +528,22 @@ class UsersController < ApplicationController end def user_homework_type + @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" + @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current if(params[:type].blank? || params[:type] == "1") #公共题库 visible_course = Course.where("is_public = 1 && is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc") + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #我的题库 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") end if params[:property] && params[:property] == "1" - @homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") elsif params[:property] && params[:property] == "2" - @homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") elsif params[:property] && params[:property] == "3" - @homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") end @type = params[:type] @property = params[:property] @@ -565,6 +569,8 @@ class UsersController < ApplicationController #用户主页过滤作业 def user_search_homeworks + @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" + @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current search = params[:name].to_s.strip.downcase if(params[:type].blank? || params[:type] == "1") #全部 @@ -574,16 +580,16 @@ class UsersController < ApplicationController all_user_ids = all_homeworks.map{|hw| hw.user_id} user_str_ids = search_user_by_name all_user_ids, search user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("created_at desc") + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #课程资源 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc") + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("#{@order} #{@b_sort}") end if params[:property] && params[:property] == "1" - @homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") elsif params[:property] && params[:property] == "2" - @homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") elsif params[:property] && params[:property] == "3" - @homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc") + @homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") end @type = params[:type] @limit = 15 @@ -593,6 +599,8 @@ class UsersController < ApplicationController @offset ||= @hw_pages.offset @homeworks = paginateHelper @homeworks,15 @is_import = params[:is_import] + @property = params[:property] + @search = search respond_to do |format| format.js end @@ -818,18 +826,18 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") #全部 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 7 @@ -939,12 +947,7 @@ class UsersController < ApplicationController return end # 自己访问自己的页面才更新消息状态 - if User.current == @user - journals_messages = UserFeedbackMessage.where("user_id =? and journals_for_message_type =? and viewed =?", User.current.id, "JournalsForMessage", 0) - journals_messages.each do |journals_message| - journals_message.update_attributes(:viewed => true) - end - end + UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) # end @page = params[:page] ? params[:page].to_i + 1 : 0 if params[:type].present? @@ -1175,6 +1178,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 =?", @@ -1544,41 +1551,41 @@ class UsersController < ApplicationController @user = User.find(params[:id]) #@user.save_attachments(params[:attachments],User.current) # Container_type为Principal - Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) + attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end end @status = params[:status] @@ -1610,37 +1617,37 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order]) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order]) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources params[:id], params[:order] elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources params[:id], params[:order] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order]) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order]) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public params[:order] elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public params[:order] else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end end @status = params[:status] @@ -2328,61 +2335,73 @@ class UsersController < ApplicationController end # 获取公共资源 - def get_public_resources user_course_ids, user_project_ids - attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc") + def get_public_resources user_course_ids, user_project_ids, order, score + attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的资源 - def get_my_resources author_id, user_course_ids, user_project_ids + def get_my_resources author_id, user_course_ids, user_project_ids, order, score attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc") + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的资源查询结果 + def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) + @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的课程资源 - def get_course_resources author_id, user_course_ids - attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_course_resources author_id, user_course_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源课程 - def get_course_resources_public user_course_ids - attchments = Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_course_resources_public user_course_ids, order, score + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的项目资源 - def get_project_resources author_id, user_project_ids - attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_project_resources author_id, user_project_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源的项目资源 - def get_project_resources_public user_project_ids - attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_project_resources_public user_project_ids, order, score + attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我上传的附件 - def get_attch_resources author_id - attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + def get_attch_resources author_id, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', + 'Document','Message','News','StudentWorkScore','HomewCommon')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源中我上传的附件 - def get_attch_resources_public - attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + def get_attch_resources_public order, score + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 - def get_principal_resources author_id - attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") + def get_principal_resources author_id, order, score + attchments = Attachment.where("author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 - def get_principal_resources_public - attchments = Attachment.where("container_type = 'Principal'").order("created_on desc") + def get_principal_resources_public order, score + attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end # 资源库 分为全部 课程资源 项目资源 附件 def user_resource + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 @@ -2394,37 +2413,37 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, params[:order], @score) elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, params[:order], @score) elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources(params[:id], params[:order], @score) elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources(params[:id], params[:order], @score) elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, params[:order], @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, params[:order], @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public(params[:order], @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public(params[:order], @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -2454,10 +2473,10 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, params[:order]) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 10 @@ -2490,10 +2509,10 @@ class UsersController < ApplicationController # user_org_ids = User.current.organizations.map {|o| o.id} @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{params[:order].nil? ? 'created_on' : params[:order]} desc") elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order]) end @type = params[:type] @limit = 10 @@ -2563,57 +2582,71 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search - search = "%#{params[:search].strip.downcase}%" + @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{switch_search.strip.downcase}%" user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部 - if User.current.id.to_i == params[:id].to_i - - @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") + if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 + if params[:status] == "2" + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "3" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "4" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "5" + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" + - " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+ - " or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )" + - " and (filename like :p) ",:p=>search).order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + get_my_resources_search(@user.id, user_course_ids, user_project_ids, @order, @score, search) end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("created_on desc") + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type = 'Course') "+ "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )"+ - " and (filename like :p) ",:p=>search).order("created_on desc") + " and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "3" #项目资源 + elsif params[:type] == "3" # 项目资源 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "4" #附件 + elsif params[:type] == "4" # 附件 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") end - elsif params[:type] == "5" #用户资源 + elsif params[:type] == "5" # 用户资源 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + end + elsif params[:type] == "6" # 全部资源 + if params[:status] == "2" + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "3" + @attachments = Attachment.where("container_type = 'Project' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "4" + @attachments = Attachment.where("container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + elsif params[:status] == "5" + @attachments = Attachment.where("container_type = 'Principal' and (filename like :p)",:p=>search).order("#{params[:order].nil? ? 'created_on' : params[:order]} #{@score}") + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("created_on desc") end - elsif params[:type] == "6" #全部资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") end + @status = params[:status] + @type = params[:type] @type = params[:type] @limit = 25 @is_remote = true diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 477e18f41..ca8e0fc28 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2951,3 +2951,33 @@ def user_url_in_org(user_id) return "https://www.trustie.net/users/" + user_id.to_s end end + +def logout_url_without_domain + if Rails.env.development? + return "http://localhost:3000/logout" + elsif Rails.env.test? + return "https://test.forge.trustie.net/logout" + else + return "https://www.trustie.net/logout" + end +end + +def signin_url_without_domain + if Rails.env.development? + return "http://localhost:3000/login?login=true" + elsif Rails.env.test? + return "https://test.forge.trustie.net/login?login=true" + else + return "https://www.trustie.net/login?login=true" + end +end + +def register_url_without_domain + if Rails.env.development? + return "http://localhost:3000/login?login=false" + elsif Rails.env.test? + return "https://test.forge.trustie.net/login?login=false" + else + return "https://www.trustie.net/login?login=false" + end +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index cbc514df6..d98de27f6 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -71,6 +71,11 @@ module CoursesHelper project.members.count end + # 统计课程中作品的数量 + def student_works_num course + StudentWork.find_by_sql("SELECT * FROM student_works WHERE homework_common_id IN (SELECT id FROM homework_commons WHERE course_id = '#{course.id}')").count + end + # 返回教师数量,即roles表中定义的Manager def teacherCount project project ? project.members.count - studentCount(project).to_i : 0 @@ -601,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 = [] @@ -762,7 +785,7 @@ module CoursesHelper return[] unless course result = [] course.attachments.each do |attachment| - if attachment.is_public? ||User.current == attachment.author ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? + if (attachment.is_public? && attachment.is_publish == 1) ||User.current == attachment.author ||User.current.allowed_to?(:as_teacher,course)|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? result << attachment end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 238999a71..913c49310 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -121,7 +121,8 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || + if (attachment.is_public? && attachment.container_type != "Course") || + (attachment.is_public? && attachment.container_type == "Course" && attachment.is_publish == 1)|| (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || (attachment.container_type == "Course" && User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id)))|| (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)) && attachment.is_publish == 1)|| diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 44b919121..bdd34d80d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,7 +62,7 @@ module UsersHelper when 'Course' result = current_time_and_term_resource content when 'Project' - result = content.name + result = content.name + "(" + content.id.to_s + ")" when 'Issue' result = content.subject when 'Message' diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 9f0c2c559..1cc0d3b7a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -499,6 +499,12 @@ class Attachment < ActiveRecord::Base result end + def self.attach_filesex_public(obj, attachments,attachment_type, is_public) + result = obj.save_attachmentsex_public(attachments, User.current,attachment_type, is_public) + obj.attach_saved_attachments + result + end + def self.latest_attach(attachments, filename) attachments.sort_by(&:created_on).reverse.detect { |att| att.filename.downcase == filename.downcase diff --git a/app/models/member.rb b/app/models/member.rb index ee329def8..9eac21fa7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,185 +1,185 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class Member < ActiveRecord::Base - belongs_to :user - belongs_to :principal, :foreign_key => 'user_id' - has_many :member_roles, :dependent => :destroy - has_many :roles, :through => :member_roles - - belongs_to :project - belongs_to :course - - belongs_to :course_group - validates_presence_of :principal - validates_uniqueness_of :user_id, :scope => [:project_id,:course_id] - validate :validate_role - - before_destroy :set_issue_category_nil - # 删除项目成员一并删除该成员的邀请记录 - after_destroy :delete_ivite_list - - - - def role - end - - def role= - end - - def name - self.user.name - end - - alias :base_role_ids= :role_ids= - def role_ids=(arg) - ids = (arg || []).collect(&:to_i) - [0] - # Keep inherited roles - ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) - - new_role_ids = ids - role_ids - # Add new roles - new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) } - # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy) - member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)} - if member_roles_to_destroy.any? - member_roles_to_destroy.each(&:destroy) - end - end - - def <=>(member) - a, b = roles.sort.first, member.roles.sort.first - if a == b - if principal - principal <=> member.principal - else - 1 - end - elsif a - a <=> b - else - 1 - end - end - - def deletable? - member_roles.detect {|mr| mr.inherited_from}.nil? - end - - def include?(user) - if principal.is_a?(Group) - !user.nil? && user.groups.include?(principal) - else - self.user == user - end - end - - def set_issue_category_nil - if user - # remove category based auto assignments for this member - #modify by nwb - if project - IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] - elsif course - #IssueCategory.update_all "assigned_to_id = NULL", ["course_id = ? AND assigned_to_id = ?", course.id, user.id] - end - - end - end - - # 删除成员一并删除该成员的邀请信息 - def delete_ivite_list - member_invite_lists = InviteList.where("user_id =? and project_id =?", self.user_id, self.project_id) - unless member_invite_lists.nil? - member_invite_lists.each do |member_invite_list| - member_invite_list.destroy - end - end - end - - # Find or initilize a Member with an id, attributes, and for a Principal - def self.edit_membership(id, new_attributes, principal=nil) - @membership = id.present? ? Member.find(id) : Member.new(:principal => principal) - @membership.attributes = new_attributes - @membership - end - - # Finds or initilizes a Member for the given project and principal - def self.find_or_new(project, principal) - project_id = project.is_a?(Project) ? project.id : project - principal_id = principal.is_a?(Principal) ? principal.id : principal - - member = Member.find_by_project_id_and_user_id(project_id, principal_id) - member ||= Member.new(:project_id => project_id, :user_id => principal_id) - member - end - - # 查找每个学生每个作业的评分 - def student_homework_score - homework_score = StudentWork.find_by_sql("SELECT homework_commons.name,student_works.final_score as score - FROM student_works,homework_commons - WHERE student_works.homework_common_id = homework_commons.id - AND homework_commons.course_id = #{self.course_id} - AND student_works.user_id = #{self.user_id}") - score_count = 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 - [homework_score, format("%0.2f", score_count)] - end - - def student_work_score - 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("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 - 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 - - def student_work_score_sum - 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} - AND student_works.user_id = #{self.user_id}" - score = StudentWork.find_by_sql(sql_select) - end - - protected - - def validate_role - errors.add_on_empty :role if member_roles.empty? && roles.empty? - end - - - - def searchTeacherAndAssistant project - #searchPeopleByRoles(project, TeacherRoles) - members = [] - project.members.each do |m| - members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) - end - members - end -end +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class Member < ActiveRecord::Base + belongs_to :user + belongs_to :principal, :foreign_key => 'user_id' + has_many :member_roles, :dependent => :destroy + has_many :roles, :through => :member_roles + + belongs_to :project + belongs_to :course + + belongs_to :course_group + validates_presence_of :principal + validates_uniqueness_of :user_id, :scope => [:project_id,:course_id] + validate :validate_role + + before_destroy :set_issue_category_nil + # 删除项目成员一并删除该成员的邀请记录 + after_destroy :delete_ivite_list + + + + def role + end + + def role= + end + + def name + self.user.name + end + + alias :base_role_ids= :role_ids= + def role_ids=(arg) + ids = (arg || []).collect(&:to_i) - [0] + # Keep inherited roles + ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) + + new_role_ids = ids - role_ids + # Add new roles + new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) } + # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy) + member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)} + if member_roles_to_destroy.any? + member_roles_to_destroy.each(&:destroy) + end + end + + def <=>(member) + a, b = roles.sort.first, member.roles.sort.first + if a == b + if principal + principal <=> member.principal + else + 1 + end + elsif a + a <=> b + else + 1 + end + end + + def deletable? + member_roles.detect {|mr| mr.inherited_from}.nil? + end + + def include?(user) + if principal.is_a?(Group) + !user.nil? && user.groups.include?(principal) + else + self.user == user + end + end + + def set_issue_category_nil + if user + # remove category based auto assignments for this member + #modify by nwb + if project + IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] + elsif course + #IssueCategory.update_all "assigned_to_id = NULL", ["course_id = ? AND assigned_to_id = ?", course.id, user.id] + end + + end + end + + # 删除成员一并删除该成员的邀请信息 + def delete_ivite_list + member_invite_lists = InviteList.where("user_id =? and project_id =?", self.user_id, self.project_id) + unless member_invite_lists.nil? + member_invite_lists.each do |member_invite_list| + member_invite_list.destroy + end + end + end + + # Find or initilize a Member with an id, attributes, and for a Principal + def self.edit_membership(id, new_attributes, principal=nil) + @membership = id.present? ? Member.find(id) : Member.new(:principal => principal) + @membership.attributes = new_attributes + @membership + end + + # Finds or initilizes a Member for the given project and principal + def self.find_or_new(project, principal) + project_id = project.is_a?(Project) ? project.id : project + principal_id = principal.is_a?(Principal) ? principal.id : principal + + member = Member.find_by_project_id_and_user_id(project_id, principal_id) + member ||= Member.new(:project_id => project_id, :user_id => principal_id) + member + end + + # 查找每个学生每个作业的评分 + def student_homework_score + homework_score = StudentWork.find_by_sql("SELECT homework_commons.name,student_works.final_score as score + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = #{self.course_id} + AND student_works.user_id = #{self.user_id}") + score_count = 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 + [homework_score, format("%0.2f", score_count)] + end + + def student_work_score + 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("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 + 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 + + def student_work_score_sum + 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} + AND student_works.user_id = #{self.user_id}" + score = StudentWork.find_by_sql(sql_select) + end + + protected + + def validate_role + errors.add_on_empty :role if member_roles.empty? && roles.empty? + end + + + + def searchTeacherAndAssistant project + #searchPeopleByRoles(project, TeacherRoles) + members = [] + project.members.each do |m| + members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) + end + members + end +end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 3df5c72d9..b1b7e0908 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -2,8 +2,8 @@ class PraiseTread < ActiveRecord::Base attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread belongs_to :user belongs_to :praise_tread_object, polymorphic: true - after_create :be_user_score - after_destroy :down_user_score + #after_create :be_user_score + #after_destroy :down_user_score include UserScoreHelper def self.find_object_by_type_and_id(type,id) @obj = nil diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb new file mode 100644 index 000000000..4316555f7 --- /dev/null +++ b/app/views/admin/course_resource_list.html.erb @@ -0,0 +1,64 @@ +

<%=l(:label_course_resource_list)%>

+ + +
+ + + + + + + + + + + + + + + <% @resource.each do |resource| %> + "> + + + + + + + + + <% end %> + +
+ 资源名称 + + 资源大小 + + 资源类型 + + 上传时间 + + 下载次数 + + 上传者 + + 所属课程 +
+ <%= link_to truncate(resource.filename, :length => 18), download_named_attachment_path(resource.id, resource.filename ), :title => resource.filename,:class=>'resourcesBlack'%> + + <%= number_to_human_size(resource.filesize)%> + + 课程资源 + + <%= format_date(resource.created_on)%> + + <%= resource.downloads %> + + <%= link_to(User.find(resource.author_id).realname, user_path(User.find(resource.author_id)) ) %> + + <%=link_to truncate(Course.find(resource.container_id).name, :length => 10), course_path(Course.find(resource.container_id)), :title => Course.find(resource.container_id).name, :class => "hidden fl w170" %> +
+
+ + \ No newline at end of file diff --git a/app/views/admin/excellent_courses.html.erb b/app/views/admin/excellent_courses.html.erb new file mode 100644 index 000000000..e21ba32aa --- /dev/null +++ b/app/views/admin/excellent_courses.html.erb @@ -0,0 +1,75 @@ +

+ <%=l(:label_excellent_courses_list)%> +

+ +
+ + + + + + + + + + + + + + + + <% @courses.each do |course| %> + "> + + + + + + + + + + + <% end %> + +
+ 序号 + + 课程名 + + 主讲老师 + + 学生数 + + 作业数 + + 作品数 + + 资源数 + + 帖子数 + + 动态数 +
+ <%= course.id %> + + + <%= link_to(course.name, course_path(course.id)) %> + + + <%= link_to(course.try(:teacher).try(:realname).truncate(6, omission: '...'), user_path(course.teacher)) %> + + <%= studentCount(course) %> + + <%= course.homework_commons.count%> + + <%= student_works_num(course) %> + + <%= visable_attachemnts_incourse(course).count%> + + <%= course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", course.boards.first.id, nil).count %> + + + <%= course.course_activities.count%> +
+
\ No newline at end of file diff --git a/app/views/admin/project_resource_list.html.erb b/app/views/admin/project_resource_list.html.erb new file mode 100644 index 000000000..c245f73b8 --- /dev/null +++ b/app/views/admin/project_resource_list.html.erb @@ -0,0 +1,64 @@ +

<%=l(:label_project_resource_list)%>

+ + +
+ + + + + + + + + + + + + + + <% @pro_resource.each do |pro_resource| %> + "> + + + + + + + + + <% end %> + +
+ 资源名称 + + 资源大小 + + 资源类型 + + 上传时间 + + 下载次数 + + 上传者 + + 所属项目 +
+ <%= link_to truncate(pro_resource.filename, :length => 18), download_named_attachment_path(pro_resource.id, pro_resource.filename ), :title => pro_resource.filename,:class=>'resourcesBlack'%> + + <%= number_to_human_size(pro_resource.filesize)%> + + 项目资源 + + <%= format_date(pro_resource.created_on)%> + + <%= pro_resource.downloads %> + + <%= link_to(User.find(pro_resource.author_id).realname, user_path(User.find(pro_resource.author_id)) ) %> + + <%=link_to truncate(Project.find(pro_resource.container_id).name, :length => 10), project_path(Project.find(pro_resource.container_id)), :title => Project.find(pro_resource.container_id).name, :class => "hidden fl w170" %> +
+
+ + \ No newline at end of file diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index e222d8e56..ac953b254 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -1,21 +1,21 @@ -
-
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
-
-
- <%= form_for @blog_comment, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => @blogComment.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> - - <% if course_id%> - - <% end %> - -
- - -
-

- <% end%> -
-
-
-
+
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
+
+
+ <%= form_for @blog_comment, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => @blogComment.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> + + <% if course_id%> + + <% end %> + +
+ + +
+

+ <% end%> +
+
+
+
\ No newline at end of file diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 05f69055f..a5aa8b780 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -1,226 +1,226 @@ -
-
-
- <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
-
- <% if activity.author.id == User.current.id%> - - <%end%> -
- <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% end %> - TO - <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%> - <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> - 已设为首页 - <% end %> -
-
- - <% if activity.sticky == 1%> - 置顶 - <% end%> - <% if activity.locked%> -        - <% end%> -
-
- 发帖时间:<%= format_time(activity.created_on) %> -
-
- 更新时间:<%= format_time(activity.updated_on) %> -
-
- <% if activity.parent_id.nil? %> - <% content= activity.content%> - <% else %> - <% content= activity.parent.content%> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> - -
- - - -
-
- <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
- -
-
-
- <% count=0 %> - <% if activity.parent %> - <% count=activity.parent.children.count%> - <% else %> - <% count=activity.children.count%> - <% end %> -
-
-
回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
-
<%#=format_date(activity.updated_on)%>
- <%if count > 3 %> - - <% end %> -
- - <% activity= activity.parent ? activity.parent : activity%> - <% replies_all_i = 0 %> - <% if count > 0 %> -
-
    - <% activity.children.reorder("created_on desc").each do |reply|%> - - <% replies_all_i=replies_all_i+1 %> -
  • -
    - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
    -
    -
    - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
    -
    - <%= reply.content.html_safe %> -
    -
    -
    -
  • - <% end %> -
-
- <% end %> - - <% if !activity.locked? %> -
-
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
-
-
- <%= form_for('new_form',:url => {:controller=>'blog_comments',:action => 'reply', :id => activity.id, :blog_id => activity.blog.id, :user_id => activity.author_id},:method => "post",:remote=>true) do |f|%> - - - - - -
- - -
-

- <% end%> -
-
-
-
-
-
- <% end %> -
-
- +
+
+
+ <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
+
+ <% if activity.author.id == User.current.id%> + + <%end%> +
+ <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%> + <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> + 已设为首页 + <% end %> +
+
+ + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
+
+ 发帖时间:<%= format_time(activity.created_on) %> +
+
+ 更新时间:<%= format_time(activity.updated_on) %> +
+
+ <% if activity.parent_id.nil? %> + <% content= activity.content%> + <% else %> + <% content= activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> + +
+ + + +
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
+ +
+
+
+ <% count=0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
+
+
回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
+
<%#=format_date(activity.updated_on)%>
+ <%if count > 3 %> + + <% end %> +
+ + <% activity= activity.parent ? activity.parent : activity%> + <% replies_all_i = 0 %> + <% if count > 0 %> +
+
    + <% activity.children.reorder("created_on desc").each do |reply|%> + + <% replies_all_i=replies_all_i+1 %> +
  • +
    + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
    +
    +
    + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
    +
    + <%= reply.content.html_safe %> +
    +
    +
    +
  • + <% end %> +
+
+ <% end %> + + <% if !activity.locked? %> +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
+
+
+ <%= form_for('new_form',:url => {:controller=>'blog_comments',:action => 'reply', :id => activity.id, :blog_id => activity.blog.id, :user_id => activity.author_id},:method => "post",:remote=>true) do |f|%> + + + + + +
+ + +
+

+ <% end%> +
+
+
+
+
+
+ <% end %> +
+
+ diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index fd33d5a19..bf69c3a61 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -24,7 +24,8 @@ + <% if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %> + <% if @course.course_groups.nil? || @group %> +
+ +
+ <% else %> + <%= form_tag({:controller => 'courses', :action => 'teacher_assign_group', :id => @course.id,:user_id => member.user_id},:remote=>'true', :method => 'post', :id=>"join_group_form_#{member.id}", :class => 'query_form') do %> +
+ +
+ <%= select( :name,:group_id, course_group_option(@course), + { :include_blank => false,:selected => member.course_group_id}, + {:onchange=>"join_group_function('#join_group_form_#{member.id}');", :id =>"course_group_id", :name => "course_group_id",:class=>"w125 undis class-edit fl", :style => "margin-left: 105px;"}) %> + <% end %> + <% end %> + <% else %> +
+ +
+ <% end %> <%= link_to format("%0.2f",member.score.nil? ? 0 : member.score.to_s), { :action => 'show_member_score', :member_id => member.id, :remote => true}, - :class => 'ml258 c_red' %> + :class => 'ml25 c_red' %> <%= format_date(member.created_on)%> <%= call_hook(:view_projects_settings_members_table_row, { :course => @course, :member => member}) %>
@@ -79,3 +100,40 @@

<% end%> + + diff --git a/app/views/courses/syllabus.html.erb b/app/views/courses/syllabus.html.erb index e12876ce9..8be245958 100644 --- a/app/views/courses/syllabus.html.erb +++ b/app/views/courses/syllabus.html.erb @@ -1,218 +1,218 @@ - -<%= content_for(:header_tags) do %> - <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> - <%= javascript_include_tag 'blog' %> -<% end %> - - - -
-
-
- <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %> -
-
- <% if User.current && @article.author.id == User.current.id%> -
-
    -
  • -
      -
    • - 重设大纲 -
    • -
    • - <%= link_to( - '取消大纲', - {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id}, - :method => :delete, - :data => {:confirm => '您确定要取消么?'}, - :class => 'postOptionLink' - ) if User.current && User.current.id == @article.author.id %> -
    • -
    -
  • -
-
- - - - - - - - - <%end%> - -
- -
- <% if @article.try(:author).try(:realname) == ' ' %> - <%= link_to @article.try(:author), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> - <% else %> - <%= link_to @article.try(:author).try(:realname), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> - <% end %> -
-
<%= format_time( @article.created_on)%>
-
-
- <%= @article.content.html_safe%> -
-
-
- <%#= link_to_attachments_course @topic, :author => false %> - <% if @article.attachments.any?%> - <% options = {:author => true, :deletable => false} %> - <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => @article.attachments, :options => options, :is_float => true} %> - <% end %> -
-
-
-
-
- <% count=0 %> - <% if @article.parent %> - <% count=@article.parent.children.count%> - <% else %> - <% count=@article.children.count%> - <% end %> -
- <% unless count == 0 %> -
-
回复(<%=count %>)
-
- -
-
- <%@article.children.reorder('created_on desc').each_with_index do |reply,i| %> - -
-
- <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> -
-
-
- <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> -
-
- <%= reply.content.html_safe%> -
-
- <%= format_time(reply.created_on) %> - -
-

-
-
-
- <% end %> -
- - <% end %> -
- <% if !@article.locked? && User.current.logged?%> - - - - - - - - - - - - - -
-
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %>
-
-
- <%= form_for 'blog_comment',:url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%> - - - - - -
- - -
-

- <% end%> -
-
-
-
-
- <% end %> -
-
- + +
+
+
+ <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %> +
+
+ <% if User.current && @article.author.id == User.current.id%> +
+
    +
  • +
      +
    • + 重设大纲 +
    • +
    • + <%= link_to( + '取消大纲', + {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id}, + :method => :delete, + :data => {:confirm => '您确定要取消么?'}, + :class => 'postOptionLink' + ) if User.current && User.current.id == @article.author.id %> +
    • +
    +
  • +
+
+ + + + + + + + + <%end%> + +
+ +
+ <% if @article.try(:author).try(:realname) == ' ' %> + <%= link_to @article.try(:author), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% else %> + <%= link_to @article.try(:author).try(:realname), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% end %> +
+
<%= format_time( @article.created_on)%>
+
+
+ <%= @article.content.html_safe%> +
+
+
+ <%#= link_to_attachments_course @topic, :author => false %> + <% if @article.attachments.any?%> + <% options = {:author => true, :deletable => false} %> + <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => @article.attachments, :options => options, :is_float => true} %> + <% end %> +
+
+
+
+
+ <% count=0 %> + <% if @article.parent %> + <% count=@article.parent.children.count%> + <% else %> + <% count=@article.children.count%> + <% end %> +
+ <% unless count == 0 %> +
+
回复(<%=count %>)
+
+ +
+
+ <%@article.children.reorder('created_on desc').each_with_index do |reply,i| %> + +
+
+ <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> +
+
+
+ <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> +
+
+ <%= reply.content.html_safe%> +
+
+ <%= format_time(reply.created_on) %> + +
+

+
+
+
+ <% end %> +
+ + <% end %> +
+ <% if !@article.locked? && User.current.logged?%> + + + + + + + + + + + + + +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %>
+
+
+ <%= form_for 'blog_comment',:url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%> + + + + + +
+ + +
+

+ <% end%> +
+
+
+
+
+ <% end %> +
+
+ \ No newline at end of file diff --git a/app/views/courses/teacher_assign_group.js.erb b/app/views/courses/teacher_assign_group.js.erb new file mode 100644 index 000000000..1429bb753 --- /dev/null +++ b/app/views/courses/teacher_assign_group.js.erb @@ -0,0 +1 @@ +$("#st_groups").html("<%=escape_javascript(render :partial => 'new_groups_name', :locals => {:course_groups => @course_groups}) %>"); \ No newline at end of file diff --git a/app/views/issues/_issue_replies.html.erb b/app/views/issues/_issue_replies.html.erb index 4c5c922f0..4c8dfa1d9 100644 --- a/app/views/issues/_issue_replies.html.erb +++ b/app/views/issues/_issue_replies.html.erb @@ -1,86 +1,86 @@ - -
- -
- <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> -
- -
-
- <%= form_for('new_form',:url => add_journal_issue_path(@issue.id),:method => "post", :remote => true) do |f| %> - <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> - - -
-
- -
-
- <%= render :partial => 'attachments/issue_reply', :locals => {:container => @issue} %> -
- - -
- <% end %> -
- -
- -
-
+ +
+ +
+ <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> +
+ +
+
+ <%= form_for('new_form',:url => add_journal_issue_path(@issue.id),:method => "post", :remote => true) do |f| %> + <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> + + +
+
+ +
+
+ <%= render :partial => 'attachments/issue_reply', :locals => {:container => @issue} %> +
+ + +
+ <% end %> +
+ +
+ +
+
\ No newline at end of file diff --git a/app/views/issues/_issue_reply_ke_form.html.erb b/app/views/issues/_issue_reply_ke_form.html.erb index e84d5905c..a2975237b 100644 --- a/app/views/issues/_issue_reply_ke_form.html.erb +++ b/app/views/issues/_issue_reply_ke_form.html.erb @@ -1,27 +1,27 @@ -
- -
- <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> -
- -
-
- <%= form_for('new_form',:url => add_reply_issue_path(@issue.id),:method => "post", :remote => true) do |f|%> - <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> - - - -
-
- -
- - -
- <% end %> -
- -
- -
+
+ +
+ <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@issue.author_id), :alt => "用户头像" %> +
+ +
+
+ <%= form_for('new_form',:url => add_reply_issue_path(@issue.id),:method => "post", :remote => true) do |f|%> + <%#= kindeditor_tag :notes,"",:height=>"33",:minHeight=>"33",:editor_id=>"issues_reply_editor"%> + + + +
+
+ +
+ + +
+ <% end %> +
+ +
+ +
\ No newline at end of file diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index c0b3002f6..315b1d300 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -100,7 +100,7 @@
  • - <%= link_to "退出",signout_path,:class => "menuGrey",:method => "post"%> + <%= link_to "退出",logout_url_without_domain,:class => "menuGrey",:method => "post"%>
  • diff --git a/app/views/layouts/_unlogin_header.html.erb b/app/views/layouts/_unlogin_header.html.erb index 2f0d2732b..0675c8a4a 100644 --- a/app/views/layouts/_unlogin_header.html.erb +++ b/app/views/layouts/_unlogin_header.html.erb @@ -77,10 +77,10 @@
    - 登录 + 登录
    - 注册 + 注册
    diff --git a/app/views/layouts/_user_courses.html.erb b/app/views/layouts/_user_courses.html.erb index 7aa591aae..30a911d09 100644 --- a/app/views/layouts/_user_courses.html.erb +++ b/app/views/layouts/_user_courses.html.erb @@ -2,7 +2,7 @@
  • <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) %> <%= link_to course.name, course_path(course.id,:host=>Setting.host_course), :class => "coursesLineGrey hidden #{course_endTime_timeout?(course) ? 'c_dark_grey' : ''}", - :id => "show_course_#{course.id}",:title => (course.is_public? ? "公开课程:":"私有课程:")+course.name+"("+current_time_and_term(course)+")"%> + :id => "show_course_#{course.id}", :target => '_blank', :title => (course.is_public? ? "公开课程:":"私有课程:")+course.name+"("+current_time_and_term(course)+")"%> <% count = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count %>