diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 9e935ae40..68386de44 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -461,8 +461,8 @@ class AdminController < ApplicationController scope = User.order('last_login_on desc') scope = scope.where("last_login_on>= '#{params[:startdate]} 00:00:00'") if params[:startdate].present? scope =scope.where("last_login_on <= '#{params[:enddate]} 23:59:59'") if params[:enddate].present? - @user = scope - @user = paginateHelper @user,30 + @users = scope + @users = paginateHelper @users,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cbf2c30bb..d6470ce51 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -312,7 +312,8 @@ class ApplicationController < ActionController::Base elsif @course allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global) else - allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) + # allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) + allowed = true end allowed end @@ -769,6 +770,7 @@ class ApplicationController < ActionController::Base end def api_request? + return false if params[:controller] == 'at' %w(xml json).include? params[:format] end diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 25e731754..456306c64 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -34,6 +34,12 @@ class AtController < ApplicationController find_homework(id) when 'Topic' find_topic(id) + when 'JournalsForMessage' + find_journals_for_message(id) + when 'Principal' + find_principal(id) + when 'All' + nil else nil end @@ -120,7 +126,11 @@ class AtController < ApplicationController #JournalsForMessage def find_journals_for_message(id) jounrnal = JournalsForMessage.find(id) - find_at_users(jounrnal.jour_type, jounrnal.jour_id) + if jounrnal.jour_type == 'Principal' + [jounrnal.user] + (JournalsForMessage.where(m_reply_id: id).map(&:user) || []) + else + find_at_users(jounrnal.jour_type, jounrnal.jour_id) + end end #Poll @@ -129,8 +139,6 @@ class AtController < ApplicationController #Journal def find_journal(id) - journal = Journal.find(id) - find_at_users(journal.journalized_type, journal.journalized_id) end #Document @@ -145,7 +153,6 @@ class AtController < ApplicationController #Principal def find_principal(id) - end #BlogComment diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 23fe19333..cf4e6a8e9 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -74,6 +74,45 @@ class AttachmentsController < ApplicationController :disposition => 'attachment' #inline can open in browser end + def direct_download_history + @attachment_history = AttachmentHistory.find(params[:id]) + @attachment_history.increment_download + send_file @attachment_history.diskfile_history, :filename => filename_for_content_disposition(@attachment_history.filename), + :type => detect_content_type(@attachment_history), + :disposition => 'attachment' #inline can open in browser + end + + def download_history + @attachment_history = AttachmentHistory.find(params[:id]) + candown = attachment_history_candown @attachment_history + if candown || User.current.admin? || User.current.id == @attachment_history.author_id + if stale?(:etag => @attachment_history.digest) + if params[:preview] == 'true' + convered_file = @attachment_history.diskfile_history + #如果本身不是pdf文件,则先寻找是不是已转换化,如果没有则转化 + unless pdf?(convered_file) + convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf") + unless File.exist?(convered_file) + office = Trustie::Utils::Office.new(@attachment_history.diskfile) + office.conver(convered_file) + end + end + if File.exist?(convered_file) && pdf?(convered_file) + send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline' + else + direct_download_history + end + else + direct_download_history + end + end + else + render_403 :message => :notice_not_authorized + end + rescue => e + redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" + end + def download # modify by nwb # 下载添加权限设置 @@ -212,7 +251,7 @@ class AttachmentsController < ApplicationController @history.version = @old_history.nil? ? 1 : @old_history.version + 1 @history.save #历史记录保存完毕 #将最新保存的记录 数据替换到 需要修改的文件记录 - @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public") + @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads") @old_attachment.save #删除当前记录 @attachment.delete diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index ae6aff794..f5e3314bb 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -52,10 +52,14 @@ class BlogCommentsController < ApplicationController render_attachment_warning_if_needed(@article) else end - if params[:is_homepage] - redirect_to user_blogs_path(params[:user_id]) + if params[:in_act] + redirect_to user_path(params[:user_id]) else - redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id]) + if @article.id.eql?(User.find(params[:user_id]).blog.homepage_id) + redirect_to user_path(params[:user_id]) + else + redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id]) + end end end def destroy @@ -123,6 +127,7 @@ class BlogCommentsController < ApplicationController @blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title] @article.children << @blogComment @article.save + # @article.update_attribute(:updated_on, @blogComment.updated_on) @user_activity_id = params[:user_activity_id] user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first if user_activity diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 0202224ed..842433ec6 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -2,7 +2,6 @@ class BlogsController < ApplicationController before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_user def index - @articls = @user.blog.articles @article = BlogComment.new respond_to do |format| format.html {render :layout=>'new_base_user'} diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 43a49c7d9..36060d41c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -321,11 +321,12 @@ class CoursesController < ApplicationController def export_course_member_excel @all_members = student_homework_score(0,0,0,"desc") + @homeworks = @course.homework_commons.order("created_at desc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; respond_to do |format| format.xls { - send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present", + send_data(member_to_xls(@homeworks,@course,@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present", :filename => filename_for_content_disposition("#{filename}.xls")) } end @@ -441,7 +442,14 @@ class CoursesController < ApplicationController @course = cs.create_course(params,User.current)[:course] if params[:copy_course] copy_course = Course.find params[:copy_course].to_i - @course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource) + @course.is_copy = params[:copy_course].to_i + @course.open_student = copy_course.open_student + @course.publish_resource = copy_course.publish_resource + @course.save + + #copy avatar + copy_avatar(@course, copy_course) + if params[:checkAll] attachments = copy_course.attachments attachments.each do |attachment| @@ -903,6 +911,17 @@ class CoursesController < ApplicationController return 404 end end + #搜索作业 + def homework_search + @search = "%#{params[:search].strip.downcase}%" + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + @page = params[:page] ? params[:page].to_i + 1 : 0 + if @is_teacher + @homeworks = @course.homework_commons.where("name like '%#{@search}%'").order("created_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("name like '%#{@search}%' and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end + end private def update_quotes attachment @@ -960,7 +979,7 @@ class CoursesController < ApplicationController sql_select = "" if groupid == 0 sql_select = "SELECT members.*,( - SELECT SUM(student_works.final_score) + SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} @@ -972,7 +991,7 @@ class CoursesController < ApplicationController WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*,( - SELECT SUM(student_works.final_score) + SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} @@ -1006,16 +1025,54 @@ class CoursesController < ApplicationController end - def member_to_xls members,groups + def member_to_xls homeworks, course, members,groups xls_report = StringIO.new book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => "student" - blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 - sheet1.row(0).default_format = blue + #sheet1.row(0).default_format = blue + #sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)]) + sheet1[0,0] = "课程编号" + sheet1[0,1] = course.id + sheet1[1,0] = "课程学期" + sheet1[1,1] = course.time.to_s+"年"+course.term + sheet1[2,0] = "课程名称" + sheet1[2,1] = course.name + sheet1[3,0] = "教师团队" + sheet1[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、') + sheet1[4,0] = "主讲教师" + sheet1[4,1] = course.teacher.show_name + sheet1[5,0] = "排名" + sheet1[5,1] = "学生姓名" + sheet1[5,2] = "昵称" + sheet1[5,3] = "学号" + for i in 0 ... homeworks.count + sheet1[5,i+4] = "第"+(i+1).to_s+"次" + end + sheet1[5,homeworks.count+4] = "总成绩" + sheet1[5,0] = "排名" + sheet1[5,0] = "排名" + count_row = 6 + members.each_with_index do |member, i| + sheet1[count_row,0]= i+1 + sheet1[count_row,1] = member.user.lastname.to_s + member.user.firstname.to_s + sheet1[count_row,2] = member.user.login + sheet1[count_row,3] = member.user.user_extensions.student_id + homeworks.each_with_index do |homework, j| + student_works = homework.student_works.where("user_id = #{member.user.id}") + if student_works.empty? + sheet1[count_row,j+4] = format("%0.2f",0) + else + final_score = student_works.first.final_score.nil? ? 0 : student_works.first.final_score + score = final_score - student_works.first.absence_penalty - student_works.first.late_penalty + sheet1[count_row,j+4] = format("%0.2f",score <0 ? 0:score) + end + end + sheet1[count_row,homeworks.count+4] = format("%0.2f",member.score.nil? ? 0:member.score.to_s) + count_row += 1 + end - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_score)]) - count_row = 1 +=begin group0 = CourseGroup.new(); group0.id = 0; group0.name = l(:excel_member_with_out_class) @@ -1037,6 +1094,7 @@ class CoursesController < ApplicationController end end end +=end book.write xls_report xls_report.string end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d345fba5f..a891d3354 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -15,8 +15,12 @@ class HomeworkCommonController < ApplicationController @new_homework.homework_detail_manual = HomeworkDetailManual.new @new_homework.course = @course @page = params[:page] ? params[:page].to_i + 1 : 0 - @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + if @is_teacher + @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_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] @@ -340,7 +344,7 @@ class HomeworkCommonController < ApplicationController #当前用户是不是课程的成员 def member_of_course - render_403 unless @course.is_public || User.current.member_of_course?(@course) || User.current.admin? + 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) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 72dd0a741..eb78c4c5b 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -81,7 +81,7 @@ class IssuesController < ApplicationController @priority_id = params[:priority_id] @status_id = params[:status_id] @subject = params[:subject] - @done_ratio = parmas[:done_ratio] + @done_ratio = params[:done_ratio] @issue_count = @query.issue_count @issue_pages = Paginator.new @issue_count, @limit, params['page'] params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1 @@ -222,7 +222,7 @@ class IssuesController < ApplicationController def update if params[:issue_detail] - issue = Issue.find(params[:issue_id]) + issue = Issue.find(params[:id]) issue = update_user_issue_detail(issue, params) @saved = update_user_issue_detail(issue, params) return diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index d051a91f7..bae0232a5 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -109,7 +109,8 @@ class OrgSubfieldsController < ApplicationController if SubfieldSubdomainDir.find_by_sql(sql).count == 0 if @org_subfield.subfield_subdomain_dir @sub_dir = @org_subfield.subfield_subdomain_dir - @sub_dir.update_attribute(:name, params[:sub_dir_name]) + @sub_dir = SubfieldSubdomainDir.update(@sub_dir.id, :name => params[:sub_dir_name]) + #@sub_dir.update_attribute(:name, params[:sub_dir_name]) else @sub_dir = SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name]) end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 361303833..6e2da311f 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -55,6 +55,7 @@ class OrganizationsController < ApplicationController @organization.name = params[:organization][:name] @organization.description = params[:organization][:description] @organization.is_public = params[:organization][:is_public] + @organization.allow_guest_download = params[:organization][:allow_guest_download] == '1' ? 1 : 0 @organization.creator_id = User.current.id member = OrgMember.new(:user_id => User.current.id) @@ -301,7 +302,7 @@ class OrganizationsController < ApplicationController def org_resources_subfield @org = Organization.find(params[:id]) - if params[:send_type].present? and params[:send_type] == 'news' + if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') @subfield = @org.org_subfields.where("field_type = 'Post'") else @subfield = @org.org_subfields.where('field_type = "Resource" ') diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 78babc43c..1d7b4117d 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -214,6 +214,7 @@ class PollController < ApplicationController def publish_poll @poll.polls_status = 2 @poll.published_at = Time.now + @poll.show_result = params[:show_result] if @poll.save if params[:is_remote] redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index cafec1c62..707e87fd1 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -360,6 +360,9 @@ update end # end @changesets_latest_coimmit = @changesets[0] + unless @changesets[0].blank? + update_commits_date(@project, @changesets_latest_coimmit) + end @properties = @repository.properties(@path, @rev) @repositories = @project.repositories @course_tag = params[:course] @@ -589,6 +592,11 @@ update project.project_score.update_attribute(:changeset_num, count) end + # 更新项目提交次数时间 + def update_commits_date project, date + project.project_score.update_attribute(:commit_time, date.created_at) + end + def find_repository @repository = Repository.find(params[:id]) @project = @repository.project diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d785a608a..9eabc95f2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -192,11 +192,13 @@ class UsersController < ApplicationController forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0) user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0) forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0) + org_querys = OrgMessage.where("user_id=? and viewed=0", user) if User.current.id == @user.id course_querys.update_all(:viewed => true) forge_querys.update_all(:viewed => true) user_querys.update_all(:viewed => true) forum_querys.update_all(:viewed => true) + org_querys.update_all(:viewed => true) end end @@ -403,8 +405,47 @@ class UsersController < ApplicationController #导入作业 def user_import_homeworks + @user = User.current @select_course = params[:select_course] ? 1 : 0 - @user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc") + #@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc") + 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") + @type = params[:type] + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 + respond_to do |format| + format.js + end + end + + def user_homework_type + @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") + elsif params[:type] == "2" #我的题库 + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") + end + @type = params[:type] + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 + respond_to do |format| + format.js + end + end + + def show_homework_detail + @homework = HomeworkCommon.find params[:homework].to_i respond_to do |format| format.js end @@ -412,7 +453,22 @@ class UsersController < ApplicationController #用户主页过滤作业 def user_search_homeworks - @user_homeworks = HomeworkCommon.where("user_id = '#{@user.id}' and lower(name) like '%#{params[:name].to_s.downcase}%'").order("created_at desc") + @user = User.current + search = params[:name].to_s.strip.downcase + 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}' and (name like '%#{search}%')").order("created_at desc") + elsif params[:type] == "2" #课程资源 + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc") + end + @type = params[:type] + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 respond_to do |format| format.js end @@ -426,6 +482,7 @@ class UsersController < ApplicationController @homework = HomeworkCommon.new @select_course = params[:select_course] || 0 if homework + @ref_homework = homework @homework.name = homework.name @homework.description = homework.description @homework.end_time = homework.end_time @@ -583,13 +640,15 @@ class UsersController < ApplicationController 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[:quotes] && !params[:quotes].blank? + homework = HomeworkCommon.find params[:quotes].to_i + homework.update_attribute(:quotes, homework.quotes+1) + end if params[:is_in_course] == "1" redirect_to homework_common_index_path(:course => homework.course_id) else redirect_to user_homeworks_user_path(User.current.id) end - end end else @@ -755,23 +814,17 @@ class UsersController < ApplicationController if params[:type].present? case params[:type] when "public" - jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('created_on DESC') - @jour_count = jours.count - @jour = jours.limit(10).offset(@page * 10) + jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('updated_on DESC') when "private" - jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('created_on DESC') - @jour_count = jours.count - @jour = jours.limit(10).offset(@page * 10) + jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('updated_on DESC') else - jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @jour_count = jours.count - @jour = jours.limit(10).offset(@page * 10) + jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC') end else - jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @jour_count = jours.count - @jour = jours.limit(10).offset(@page * 10) + jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC') end + @jour_count = jours.count + @jour = jours.limit(10).offset(@page * 10) @type = params[:type] if User.current == @user jours.update_all(:is_readed => true, :status => false) @@ -1633,6 +1686,10 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end attach_copied_obj.save + unless Project.find(project_id).project_score.nil? + Project.find(project_id).project_score.update_attribute(:attach_num, + Project.find(project_id).project_score.attach_num + 1) + end end end elsif params[:send_ids].present? @@ -1668,6 +1725,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end attach_copied_obj.save + unless Project.find(project_id).project_score.nil? + Project.find(project_id).project_score.update_attribute(:attach_num, Project.find(project_id).project_score.attach_num + 1) + end end end end @@ -1797,12 +1857,13 @@ class UsersController < ApplicationController news = News.find(params[:send_id]) project_ids = params[:project_ids] project_ids.each do |project_id| - if Project.find(project_id).news.map(&:id).exclude?(news.id) - project_news = News.create(:project_id => project_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now) + project = Project.find(project_id) + if project.news.map(&:id).exclude?(news.id) + message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id) news.attachments.each do |attach| - project_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end end end @@ -1820,6 +1881,53 @@ class UsersController < ApplicationController OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id) end + def share_message_to_course + @message = Message.find(params[:send_id]) + course_ids = params[:course_ids] + course_ids.each do |course_id| + course = Course.find(course_id) + if course.news.map(&:id).exclude?(@message.id) + message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + @message.attachments.each do |attach| + message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + end + end + end + + def share_message_to_project + @message = Message.find(params[:send_id]) + project_ids = params[:project_ids] + project_ids.each do |project_id| + project = Project.find(project_id) + if project.news.map(&:id).exclude?(@message.id) + message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + @message.attachments.each do |attach| + message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + end + end + end + + def share_message_to_org + field_id = params[:subfield] + @message = Message.find(params[:send_id]) + @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1) + @message.save + board = OrgSubfield.find(field_id).boards.first + mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + @message.attachments.each do |attach| + mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) + end + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id) + end + def change_org_subfield end @@ -2061,9 +2169,9 @@ class UsersController < ApplicationController end 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('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").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','OrgSubfield','Principal')").order("created_on desc") end elsif params[:type] == "5" #用户资源 if User.current.id.to_i == params[:id].to_i @@ -2169,7 +2277,7 @@ class UsersController < ApplicationController @user = User.current if !params[:search].nil? #发送到有栏目类型为资源的组织中 search = "%#{params[:search].to_s.strip.downcase}%" - if params[:send_type].present? and params[:send_type] == 'news' + if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} else @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 8115f3f91..351be4e64 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -62,6 +62,7 @@ class WordsController < ApplicationController update_forge_activity('JournalsForMessage',parent_id) update_org_activity('JournalsForMessage',parent_id) update_principal_activity('JournalsForMessage',parent_id) + (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) end respond_to do |format| # format.html { @@ -73,9 +74,9 @@ class WordsController < ApplicationController # render 'test/index' # } format.js { - @reply_type = params[:reply_type] @user_activity_id = params[:user_activity_id] @activity = JournalsForMessage.find(parent_id) + @is_activity = params[:is_activity] } end @@ -94,6 +95,9 @@ class WordsController < ApplicationController @user = User.find(@journal_destroyed.jour_id) @jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count @is_user = true + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @is_activity = params[:is_activity].to_i if params[:is_activity] + @activity = @journal_destroyed.parent if @journal_destroyed.parent elsif @journal_destroyed.jour_type == 'HomeworkCommon' @homework = HomeworkCommon.find @journal_destroyed.jour_id if params[:user_activity_id] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 51138f2ef..9d08be378 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,11 @@ module ApplicationHelper end end + def link_to_user_version(version, options = {}) + return '' unless version && version.is_a?(Version) + link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => "linkBlue" + end + # 判断课程是否为精品课程 def is_excellent_course course (course.is_excellent? or course.excellent_option?) ? true : false @@ -62,7 +67,7 @@ module ApplicationHelper # 获取项目/课程总分 # 发布缺陷 4分 回复缺陷 1分 提交一次 4分 讨论帖子 2分 回复帖子 1分 发布新闻 1分 def static_project_score obj - score = obj.issue_num * 4 + obj.issue_journal_num + obj.changeset_num * 4 + obj.board_num * 2 + obj.board_message_num + obj.news_num + obj.attach_num * 5 + score = obj.issue_num * 4 + obj.issue_journal_num + (obj.changeset_num||0) * 4 + obj.board_num * 2 + obj.board_message_num + obj.news_num + obj.attach_num * 5 end # 获取组织成员中文名字 @@ -1992,6 +1997,18 @@ module ApplicationHelper courses_doing end + def attachment_history_candown attachment_history + if attachment_history.container_type == "Course" + course = Course.find(attachment_history.container_id) + candown = User.current.member_of?(course) || (course.is_public && attachment_history.is_public == 1) + elsif attachment_history.container_type == "Project" + project = Project.find(attachment_history.container_id) + candown = User.current.member_of?(project) || (project.is_public && attachment_history.is_public == 1) + elsif attachment_history.container_type == "OrgSubfield" + org = OrgSubfield.find(attachment_history.container_id) + candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1) + end + end def attachment_candown attachment candown = false @@ -2803,7 +2820,7 @@ int main(int argc, char** argv){ end if opt[:init_activity] - ss += javascript_include_tag "init_activity_KindEditor" + ss += javascript_include_tag "create_kindeditor" end ss.html_safe diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index 3f6802f59..0291d177f 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -1,9 +1,24 @@ module AvatarHelper AVATAR_SIZE="50x50" + + def copy_avatar(des, src) + src_file = disk_filename(src.class,src.id) + des_file = disk_filename(des.class,des.id) + + FileUtils.cp(src_file, des_file) if File.exist?(src_file) + end - def avatar_image(source) - File.join(relative_path, avatar_directory(source.class), source.id.to_s) + def avatar_image(source, copyed=false) + source_type = source.class + source_id = source.id + + course = Course.find(source_id) rescue nil + if course && copyed + source_id = course.is_copy + end + + File.join(relative_path, avatar_directory(source_type), source_id.to_s) end def relative_path @@ -23,7 +38,18 @@ module AvatarHelper end def disk_filename(source_type,source_id,image_file=nil) - File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file)) + File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file)) + end + + def copy_course?(source_type, source_id) + file= disk_filename(source_type, source_id) + if source_type == Course && !File.exist?(file) + course = Course.find(source_id) rescue nil + if course && course.is_copy>0 + return true + end + end + false end def file_extension(filename=nil) @@ -35,7 +61,9 @@ module AvatarHelper return File.join(relative_path,'AnonymousUser','0') end if source.class && source.id && File.exist?(disk_filename(source.class,source.id)) - avatar_image(source) + avatar_image(source, false) + elsif copy_course?(source.class, source.id) + avatar_image(source, true) else File.join(relative_path,avatar_directory(source.class),'0') end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index fb7214fce..40ed4a21a 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -35,14 +35,29 @@ module CoursesHelper # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)} # 通过elastic结果获取精品课程 a_courses = [] - courses = Course.search(keywords) - courses.each do |c| - a_courses << c.id - end + #courses = Course.search(keywords) + #courses.each do |c| + # a_courses << c.id + #end a_courses << a_tags unless a_tags.length == 0 + # 课程本身不能搜索显示自己 + excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id} + limit = 5 - excellent_ids.length.to_i + sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id + and c.is_excellent =1 and c.id != #{current_course.id} order by cs.updated_at desc;" + default_ecourse_ids = Course.find_by_sql(sql).flatten + # REDO:时间紧,待优化 + default_ids =[] + default_ecourse_ids.each do |de| + default_ids << de.id + end + default_ids = default_ids - excellent_ids + #default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten + arr_result = excellent_ids << default_ids + arr_result = arr_result.flatten.first(5) + return arr_result # 过滤条件:精品课程、本身不在搜索范围 - e_courses = Course.where("is_excellent =? and id in (?)",1,a_courses.flatten.uniq).where("id !=?",current_course.id) - e_courses + #e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id) end # 判断精品课程是否可见,非课程成员无法查看私有课程 @@ -101,6 +116,34 @@ module CoursesHelper @course.journals_for_messages.where('m_parent_id IS NULL').count end + #当前学期 + def current_time_and_term course + str = "" + term = cur_course_term + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = course.time.to_s + course.term.to_s + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = course.time.to_s + course.term.to_s + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = course.end_time.to_s + course.end_term.to_s + else + str = Time.now.year.to_s + cur_course_term.to_s + end + str + end + + def set_term_value term + val = 0 + if term == "春季学期" + val = 1 + elsif term == "夏季学期" + val = 2 + elsif term == "秋季学期" + val = 3 + end + val + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count @@ -547,7 +590,7 @@ module CoursesHelper type = [] month = Time.now.month now_year = year.nil? ? Time.now.year : (Time.now.year <= year ? Time.now.year : year) - year = month < 3 && now_year >=Time.now.year ? now_year - 1 : now_year + year = month < 2 && now_year >=Time.now.year ? now_year - 1 : now_year for i in (year..year + 10) option = [] option << i @@ -577,8 +620,10 @@ module CoursesHelper def cur_course_term month = Time.now.month - if month >= 9 || month < 3 + if month >= 9 || month < 2 term = "秋季学期" + elsif (month >= 7 && Time.now.day >= 15) || month == 8 + term = "夏季学期" else term = "春季学期" end @@ -588,7 +633,7 @@ module CoursesHelper def course_in_current_or_next_term course is_current_term = false is_next_term = false - year_now = Time.now.month < 3 ? Time.now.year - 1:Time.now.year + year_now = Time.now.month < 2 ? Time.now.year - 1:Time.now.year if course.time == year_now && course.term == cur_course_term is_current_term = true end @@ -597,6 +642,7 @@ module CoursesHelper elsif cur_course_term == "春季学期" && course.time == year_now && course.term == "夏季学期" is_next_term = true elsif cur_course_term == "夏季学期" && course.time == year_now && course.term == "秋季学期" + is_next_term = true end is_current_term || is_next_term end @@ -682,17 +728,16 @@ module CoursesHelper def join_in_course_header(course, user, options=[]) if user.logged? joined = course.members.map{|member| member.user_id}.include? user.id - text = joined ? ("".html_safe + l(:label_course_exit_student)) : ("".html_safe + l(:label_course_join_student)) + text = joined ? l(:label_course_exit_student) : l(:label_course_join_student) url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) method = joined ? 'delete' : 'post' if joined - link = "#{l(:label_course_join_student)}" + link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) + link = link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) else - link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a") + "#{l(:label_course_exit_student)}".html_safe + link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a") end else - link = "#{l(:label_course_join_student)}" + - "#{l(:label_course_exit_student)}" + link = "#{l(:label_course_join_student)}" end link.html_safe end @@ -781,7 +826,7 @@ module CoursesHelper # 学生按作业总分排序,取前8个 def hero_homework_score(course, score_sort_by) sql_select = "SELECT members.*,( - SELECT SUM(student_works.final_score) + SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{course.id} diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 43ef7cefc..4edfed578 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -85,19 +85,15 @@ module UsersHelper end end - def link_to_user_version(version, options = {}) - return '' unless version && version.is_a?(Version) - link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => " f16 fb c_dblue " - end - # 统计未读消息数 def unviewed_message(user) course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count + org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count at_count = user.at_messages.where(viewed: false).count - messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + org_count end def user_mail_notification_options(user) diff --git a/app/models/at_message.rb b/app/models/at_message.rb index 3d20ffafb..bca2c7ba4 100644 --- a/app/models/at_message.rb +++ b/app/models/at_message.rb @@ -47,7 +47,11 @@ class AtMessage < ActiveRecord::Base "回复帖子: " end + at_message.subject when 'JournalsForMessage' - "作业: #{at_message.jour.name} 中留言" + if at_message.jour_type == 'Principal' + "留言: 在#{at_message.at_user.show_name}主页中留言" + else + "作业: #{at_message.jour.name} 中留言" + end else logger.error "error type: #{at_message_type}" end @@ -92,7 +96,12 @@ class AtMessage < ActiveRecord::Base when 'Message' {controller: :boards, action: :show, project_id: at_message.board.project, id: at_message.board} when 'JournalsForMessage' - {controller: :homework_common, action: :index, course: at_message.jour.course_id} + if at_message.jour_type == 'Principal' + {controller: :users, action: :user_messages, id: at_message.at_user} + else + {controller: :homework_common, action: :index, course: at_message.jour.course_id} + end + else logger.error "error type: #{at_message_type}" end diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb index 2160d242d..fb4e762ba 100644 --- a/app/models/attachment_history.rb +++ b/app/models/attachment_history.rb @@ -1,3 +1,14 @@ class AttachmentHistory < ActiveRecord::Base belongs_to :attachment,foreign_key: 'attachment_id' + cattr_accessor :storage_history_path + @@storage_history_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files") + + # Returns file's location on disk + def diskfile_history + File.join(self.class.storage_history_path, disk_directory.to_s, disk_filename.to_s) + end + + def increment_download + increment!(:downloads) + end end diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index db28e55d6..2b31af604 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -18,6 +18,7 @@ class BlogComment < ActiveRecord::Base after_save :add_user_activity after_update :update_activity + after_create :update_parent_time before_destroy :destroy_user_activity scope :like, lambda {|arg| @@ -64,6 +65,11 @@ class BlogComment < ActiveRecord::Base (user && user.logged? && (self.author == user) ) || user.admin? end + def update_parent_time + if !self.parent.nil? + self.root.update_attribute(:updated_on, self.updated_on) + end + end def project end end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 194e1183a..c9c6cec4b 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -72,7 +72,7 @@ class CourseActivity < ActiveRecord::Base # message的status状态为0为正常,为1表示创建课程时发送的message message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => self.course.tea_id , :sticky => true, :status => true ) # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直 - message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) + message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 9e0ce2dd2..cdcf9d19e 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -70,7 +70,7 @@ class JournalsForMessage < ActiveRecord::Base validates :notes, presence: true, if: :is_homework_jour? after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score after_create :reset_counters! - after_update :update_ativity + #after_update :update_activity after_destroy :reset_counters! after_save :be_user_score after_destroy :down_user_score diff --git a/app/models/mailer.rb b/app/models/mailer.rb index ee37927d3..05b0349ec 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -380,7 +380,15 @@ class Mailer < ActionMailer::Base end # issue截止时间提醒 - def issue_due_date(issue, recipients) + def issue_due_date(issue) + recipients ||= [] + if issue.author.id != issue.assigned_to_id + recipients << issue.author.mail + end + + # 被指派人邮箱地址加入数组 + recipients << issue.assigned_to.mail + # cc = wiki_content.page.wiki.watcher_recipients - recipients @author = issue.author @issue_name = issue.subject @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id) diff --git a/app/models/member.rb b/app/models/member.rb index ed7ee81e6..413fedc07 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -150,7 +150,7 @@ class Member < ActiveRecord::Base #当前学生在指定作业内的得分 def homework_common_score homework_common - StudentWork.select("final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + StudentWork.select("IF(final_score is null,null,final_score - absence_penalty - late_penalty) as final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) end def student_work_score_avg @@ -158,7 +158,12 @@ class Member < ActiveRecord::Base end def student_work_score_sum - StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").sum(:final_score).try(:round, 2).to_f + sql_select = "SELECT (SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) as score + 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 diff --git a/app/models/secdomain.rb b/app/models/secdomain.rb new file mode 100644 index 000000000..4d0abe5db --- /dev/null +++ b/app/models/secdomain.rb @@ -0,0 +1,18 @@ +class Secdomain < ActiveRecord::Base + attr_accessible :pid, :subname, :sub_type, :desc + + validates_presence_of :subname, :sub_type + validates_uniqueness_of :subname + + def controller + return 'organizations' if sub_type == 2 + return 'users' if sub_type == 3 + nil + end + + def action + return 'show' if sub_type == 2 + return 'show' if sub_type == 3 + nil + end +end diff --git a/app/models/subfield_subdomain_dir.rb b/app/models/subfield_subdomain_dir.rb index 9897e19ac..2ec93fe05 100644 --- a/app/models/subfield_subdomain_dir.rb +++ b/app/models/subfield_subdomain_dir.rb @@ -1,4 +1,5 @@ class SubfieldSubdomainDir < ActiveRecord::Base # attr_accessible :title, :body belongs_to :org_subfield + validates_exclusion_of :name, :in => %w(setting members org_document_comments) end diff --git a/app/models/user.rb b/app/models/user.rb index f3367db59..a74c20751 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -345,7 +345,8 @@ class User < Principal user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count system_messages_count = SystemMessage.where("created_at >?", User.current.onclick_time.onclick_time).count at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count - messages_count = course_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", User.current.id,0, User.current.onclick_time.onclick_time).count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count end # 查询指派给我的缺陷记录 @@ -825,6 +826,9 @@ class User < Principal end def admin_of_org?(org) + if self.admin? + return true + end if OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count == 0 return false end diff --git a/app/views/admin/latest_login_users.html.erb b/app/views/admin/latest_login_users.html.erb index a32bdd33a..594f554b4 100644 --- a/app/views/admin/latest_login_users.html.erb +++ b/app/views/admin/latest_login_users.html.erb @@ -47,7 +47,7 @@
<% @count=@page * 30 %> - <% for user in @user do %> + <% for user in @users do %>- - <%= l(:label_cancel_with_space) %> - - - <%= l(:label_comment_with_space) %> - -
- <% end %> - -+ + <%= l(:label_cancel_with_space) %> + + + <%= l(:label_comment_with_space) %> + +
+ <% end %> + +