课程动态
暂无内容,敬请期待!
+ + <%= link_to "More", organization_path(@organization, :list =>1), :class => "more-btn-center mt30" , :target => "_blank" %> + + <% else %> +diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index f8ca1d0e2..e1e99447d 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -24,7 +24,7 @@ class AdminController < ApplicationController before_filter :require_admin helper :sort helper :Users - helper :Settings + helper :Settings,SchoolHelper include SortHelper def index @@ -65,7 +65,17 @@ class AdminController < ApplicationController #管理员界面课程资源列表 def course_resource_list - @resource = Attachment.where(:container_type => 'Course') + + if params[:sort] == 'file_size' + @resource = Attachment.where(:container_type => 'Course').order("filesize desc") + elsif params[:sort] == 'file_upload' + @resource = Attachment.where(:container_type => 'Course').order("created_on desc") + elsif params[:sort] == 'file_download_times' + @resource = Attachment.where(:container_type => 'Course').order("downloads desc") + else + @resource = Attachment.where(:container_type => 'Course').order("created_on desc") + end + @resource = paginateHelper @resource,30 @page = (params['page'] || 1).to_i - 1 @@ -76,7 +86,17 @@ class AdminController < ApplicationController #管理员界面項目资源列表 def project_resource_list - @pro_resource = Attachment.where(:container_type => 'Project') + + if params[:sort] == 'file_size' + @pro_resource = Attachment.where(:container_type => 'Project').order("filesize desc") + elsif params[:sort] == 'file_upload' + @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc") + elsif params[:sort] == 'file_download_times' + @pro_resource = Attachment.where(:container_type => 'Project').order("downloads desc") + else + @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc") + end + @pro_resource = paginateHelper @pro_resource,30 @page = (params['page'] || 1).to_i - 1 @@ -92,9 +112,9 @@ class AdminController < ApplicationController case params[:format] when 'xml', 'json' - @offset, @limit = api_offset_and_limit({:limit => 15}) + @offset, @limit = api_offset_and_limit({:limit => 50}) else - @limit = 15#per_page_option + @limit = 50 #per_page_option end @status = params[:status] || 1 @@ -374,7 +394,13 @@ class AdminController < ApplicationController #组织 def organization - @organizations = Organization.all + @organizations = Organization.find_by_sql("SELECT * FROM organizations ORDER BY created_at DESC") + #@organizations = Organization.all.order("created_at desc") + @organization_count = @organizations.count + @organization_pages = Paginator.new @organization_count, 30, params['page'] || 1 + @organizations = paginateHelper @organizations,30 + + @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html end @@ -382,17 +408,14 @@ class AdminController < ApplicationController #学校列表 def schools - @school_name = params[:school_name] - if @school_name && @school_name != '' - @schools = School.where("name like '%#{@school_name}%'") - elsif @school_name.nil? - @schools = [] - else @school_name && @school_name == ' ' - @schools = School.where('1=1') - end + + @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC") @school_count = @schools.count - @school_pages = Paginator.new @school_count, 100, params['page'] || 1 - @schools = paginateHelper @schools,100 + + @school_pages = Paginator.new @school_count, 30, params['page'] || 1 + @schools = paginateHelper @schools,30 + + @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html end @@ -525,7 +548,8 @@ class AdminController < ApplicationController #作业 def homework - @homework = HomeworkCommon.order('end_time desc') + #@homework = HomeworkCommon.order('end_time desc') + @homework = HomeworkCommon.order( 'created_at desc ') @homework = paginateHelper @homework,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 9853b4dc1..1dacffb6f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -70,8 +70,8 @@ class AttachmentsController < ApplicationController def direct_download @attachment.increment_download send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), - :type => detect_content_type(@attachment), - :disposition => 'attachment' #inline can open in browser + :type => detect_content_type(@attachment), + :disposition => 'attachment' #inline can open in browser end def direct_download_history @@ -175,7 +175,7 @@ class AttachmentsController < ApplicationController @attachment = Attachment.find(params[:attachmentid]) if @attachment != nil filedense = params[:newtype].to_s - # d = Iconv.conv("unicodebig","utf-8",filedense) + # d = Iconv.conv("unicodebig","utf-8",filedense) if filedense == "%E5%85%AC%E5%BC%80" #l(:field_is_public) @attachment.is_public = 1 else @@ -210,9 +210,9 @@ class AttachmentsController < ApplicationController if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size]) if stale?(:etag => thumbnail) send_file thumbnail, - :filename => filename_for_content_disposition(@attachment.filename), - :type => detect_content_type(@attachment), - :disposition => 'inline' + :filename => filename_for_content_disposition(@attachment.filename), + :type => detect_content_type(@attachment), + :disposition => 'inline' end else # No thumbnail for the attachment or thumbnail could not be created @@ -292,10 +292,10 @@ class AttachmentsController < ApplicationController respond_to do |format| if !@attachment.container.nil? && - (@attachment.container.is_a?(Course) || ((@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id) ) && - @attachment.container.course ) || ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && - @attachment.container.board && @attachment.container.board.course ) || @attachment.container.is_a?(StudentWorksScore) || @attachment.container.is_a?(HomeworkCommon) || - @attachment.container.is_a?(StudentWork)) + (@attachment.container.is_a?(Course) || ((@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id) ) && + @attachment.container.course ) || ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && + @attachment.container.board && @attachment.container.board.course ) || @attachment.container.is_a?(StudentWorksScore) || @attachment.container.is_a?(HomeworkCommon) || + @attachment.container.is_a?(StudentWork)) if @attachment.container.is_a?(News) format.html { redirect_to_referer_or news_path(@attachment.container) } elsif @attachment.container.is_a?(StudentWorksScore) @@ -327,25 +327,25 @@ class AttachmentsController < ApplicationController elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment) format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)} else - if @project.nil? - format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } - else + if @project.nil? + format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } + else format.html { redirect_to_referer_or project_path(@project) } - end + end end format.js - end + end end def delete_homework - @bid = @attachment.container.bid - # Make sure association callbacks are called - container = @attachment.container - @attachment.container.attachments.delete(@attachment) - #if container.attachments.empty? - #container.delete - #end + @bid = @attachment.container.bid + # Make sure association callbacks are called + container = @attachment.container + @attachment.container.attachments.delete(@attachment) + #if container.attachments.empty? + #container.delete + #end respond_to do |format| format.html { redirect_to_referer_or respond_path(@bid) } @@ -594,7 +594,7 @@ class AttachmentsController < ApplicationController end end -private + private def find_project @attachment = Attachment.find(params[:id]) # Show 404 if the filename in the url is wrong @@ -608,7 +608,7 @@ private @attachment.container.board.course) @course = @attachment.container.board.course else - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' + unless @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' @project = @attachment.project end end @@ -628,7 +628,7 @@ private def read_authorize if @attachment.container_type == "HomeworkAttach" || @attachment.container_type == 'Bid' - true + true #User.current.allowed_to?(:view_homework_attaches, @attachment.project) ? true : deny_access else @attachment.visible? ? true : deny_access @@ -654,14 +654,16 @@ private def renderTag @attachmentNew = Attachment.find(params[:attchmentId]) - respond_to do |format| + respond_to do |format| format.js end end def has_login - unless @attachment && @attachment.container_type == "PhoneAppVersion" - render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download) + unless @attachment && @attachment.container_type == "Organization" + unless @attachment && @attachment.container_type == "PhoneAppVersion" + render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download) + end end end end diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 7220eec27..0224a587d 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -71,18 +71,18 @@ class BlogCommentsController < ApplicationController @course.save redirect_to course_path(:id=>params[:course_id]) else - @article.children.delete - @article.delete + @article.children.destroy + @article.destroy redirect_to user_blogs_path(:user_id=>User.current) end else#如果是回复被删, if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的 - @article.delete + @article.destroy redirect_to syllabus_course_path(:id=>params[:course_id]) else root = @article.root - @article.delete + @article.destroy redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id) end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index c8518e8a3..a77346d89 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -70,31 +70,16 @@ class BoardsController < ApplicationController def show # 讨论区消息状态更新(已读和未读) if @project - query_forge_messages = @board.messages - query_forge_messages.each do |query_forge_message| - query = query_forge_message.forge_messages - query.each do |forge_message| - if User.current.id == forge_message.user_id - forge_message.update_attributes(:viewed => true) - end - end - end + ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true) # 更新@消息为已读 - @project.boards.each do |board| - board.messages.each do |m| - User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!} - end - end + # 注释掉这句是因为和上面的方法代码重复,一个类型的消息,已经更新就不需要再更新 + # @project.boards.each do |board| + # board.messages.each do |m| + # User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!} + # end + # end elsif @course - query_course_messages = @board.messages - query_course_messages.each do |query_course_message| - query = query_course_message.course_messages - query.each do |course_message| - if User.current.id == course_message.user_id - course_message.update_attributes(:viewed => true) - end - end - end + CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true) end sort_init 'updated_on', 'desc' diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index dfa30915e..515b94392 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -852,7 +852,7 @@ class CoursesController < ApplicationController # return # end # 统计访问量 - @course.update_attribute(:visits, @course.visits.to_i + 1) + @course.update_column(: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 7ae1b85f8..cf94da8d9 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -458,10 +458,16 @@ class FilesController < ApplicationController if params[:in_project_toolbar] @in_project_toolbar = params[:in_project_toolbar] end - # 发送邮件 attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type]) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') + # 发送邮件 Mailer.run.attachments_added(attachments[:files]) + # 生成动态 + attachments[:files].each do |file| + ForgeActivity.create(:user_id => User.current.id, :project_id => @project.id, :forge_act_id => file.id, :forge_act_type => "Attachment") + end + # 更新资源总数, 根据上传的附件数累加 + @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) unless @project.project_score.nil? end # end if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array) @@ -485,11 +491,6 @@ class FilesController < ApplicationController end end end - # 更新资源总数, 根据上传的附件数累加 - unless @project.project_score.nil? - @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) - end - # end # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -622,6 +623,36 @@ class FilesController < ApplicationController @attachtype = 0 @contenttype = 0 + respond_to do |format| + format.js + # format.html { + # redirect_to org_subfield_files_url(@org_subfield) + # } + end + # 组织添加附件,为了修改图片 + elsif params[:organization_id] + @organization = Organization.find(params[:organization_id]) + @addTag=false + # atttchment_type = 0为logo 1为banner + if params[:logo] + attachments = Attachment.attach_filesex(@organization, params[:attachments], false) + else + attachments = Attachment.attach_filesex(@organization, params[:attachments], true) + end + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [Organization.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@organization.id)] + + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @attachtype = 0 + @contenttype = 0 + respond_to do |format| format.js # format.html { diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 17111b3f3..b1d16debb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -37,16 +37,6 @@ class MessagesController < ApplicationController # Show a topic and its replies def show -=begin - if @course - topic_id = params[:r]?params[:r]:params[:id] - parent_id = params[:id] - url = course_boards_path(@course,:topic_id => topic_id,:parent_id=>parent_id); - redirect_to url - return; - end -=end - @isReply = true page = params[:page] # Find the page of the requested reply @@ -54,16 +44,7 @@ class MessagesController < ApplicationController offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) page = 1 + offset / REPLIES_PER_PAGE end - @reply_count = @topic.children.count - # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - # @replies = @topic.children. - # includes(:author, :attachments, {:board => :project}). - # reorder("#{Message.table_name}.created_on DESC"). - # limit(@reply_pages.per_page). - # offset(@reply_pages.offset). - # all - @reply = Message.new(:subject => "RE: #{@message.subject}") if @course messages_replies = @topic.children. diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index ba4c1f18f..661073cdc 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -11,7 +11,7 @@ class OrgSubfieldsController < ApplicationController sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" if SubfieldSubdomainDir.find_by_sql(sql).count == 0 - SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir]) + SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase) end end @subfield.update_attributes(:field_type => params[:field_type]) @@ -130,6 +130,12 @@ class OrgSubfieldsController < ApplicationController @organization = @org_subfield.organization end + def update_status + @subfield = OrgSubfield.find(params[:id]) + @organization = Organization.find(@subfield.organization_id) + @subfield.update_attributes(:status => params[:status]) + end + def show_attachments obj @attachments = [] obj.each do |container| diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 239253d82..a24bcd9a4 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -28,18 +28,25 @@ class OrganizationsController < ApplicationController helper :project_score helper :issues include UsersHelper - before_filter :find_organization, :only => [:show, :members, :apply_subdomain] + before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout] layout 'base_org' def index end + + def new @organization = Organization.new render :layout => 'new_base' end def edit - @organization = Organization.find(params[:id]) + # @organization = Organization.find(params[:id]) + begin + @organization = Organization.where("id =?", params[:id]) + ensure + render_404 + end end def destroy @@ -56,6 +63,7 @@ class OrganizationsController < ApplicationController @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.show_mode = 0 @organization.creator_id = User.current.id member = OrgMember.new(:user_id => User.current.id) @@ -67,50 +75,170 @@ class OrganizationsController < ApplicationController end 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 - @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) + # 组织新类型 show_mode:判断标准 1为新类型,0为旧 + if @organization.show_mode == 1 && params[:org_subfield_id].nil? && params[:list] .nil? + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + # REDO:时间紧,暂时先这样 + @org_logo_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 0 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first + @org_banner_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 1 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first + + @subfield_content = @organization.org_subfields.order("priority") + @organization = Organization.find(params[:id]) + # 统计访问量 + @organization.update_column(:visits, @organization.visits.to_i + 1) + + # @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + # @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 + # @org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) + + shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) + project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 + course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + @project_acts = get_project_activities_org @organization, project_ids + @course_acts = get_course_activities_org @organization, course_ids + #@org_acts = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc') + #@project_acts = OrgActivity.where("(container_id =? and container_type =?) " + + # "or (container_type ='Project' and org_act_type in ('Issue','Message') and container_id in (#{project_ids.join(',')})) ", + # @organization.id, 'Organization').order('updated_at desc').limit(8) + + #@course_acts = OrgActivity.where("(container_id =? and container_type =?) " + + # "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + # @organization.id, 'Organization').order('updated_at desc').limit(8) + + + + # 项目两种动态 + #@project_acts = get_project_activities_org @organization + + # 课程动态 + #@project_acts_issues = get_project_activities_org @organization + #@course_acts = get_course_activities_org @organization + + render :layout => 'base_org_newstyle' else - shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) - project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 - course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - case params[:type] - when nil - @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + - "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ - "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", - @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_issue' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'project_message' - @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'org' - @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_homework' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_news' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_message' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - when 'course_poll' - @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) - end - end - @page = params[:page] ? params[:page].to_i : 1 - respond_to do |format| - format.html - format.js + render_403 end else - render_403 + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @organization = Organization.find(params[:id]) + # 统计访问量 + @organization.update_column(: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 + @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) + else + shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) + project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 + course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + case params[:type] + when nil + @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + + "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ + "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_issue' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'project_message' + @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'org' + @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_homework' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_news' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_message' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + when 'course_poll' + @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) + end + end + @page = params[:page] ? params[:page].to_i : 1 + respond_to do |format| + format.html + format.js + end + else + render_403 + end end + + end + + def get_project_message_activities_org org + project_ids = org.projects.map{|project| project.id}.join(",") + unless project_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids}) and container_type = 'project' and org_act_type = 'Message' order by updated_at desc limit 2;") + else + project_acts = nil + end + end + + def get_project_issue_activities_org org + project_ids = org.projects.map{|project| project.id}.join(",") + unless project_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids}) and container_type = 'project' and org_act_type = 'issue' order by updated_at desc limit 4;") + else + project_acts = nil + end + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids}) and container_type = 'project' and org_act_type = 'issue' order by updated_at desc limit 4;") + end + + # 获取整过项目的动态 + def get_project_activities_org org, project_ids + unless project_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids.join(',')}) and container_type = 'project' + and org_act_type in ('Message', 'Issue') order by updated_at desc limit 8;") + else + project_acts = nil + end + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids}) and container_type = 'project' and org_act_type = 'issue' order by updated_at desc limit 4;") + end + + # 获取整过课程的动态 + def get_course_activities_org org, course_ids + unless course_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids.join(',')}) and container_type = 'course' + and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 8;") + else + project_acts = nil + end + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' order by updated_at desc limit 5;") + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'HomeworkCommon' order by updated_at desc limit 1;") + end + + def get_course_homework_activities_org org + course_ids = org.courses.map{|course| course.id}.join(",") + unless course_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'HomeworkCommon' order by updated_at desc limit 1;") + else + project_acts = nil + end + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' order by updated_at desc limit 5;") + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'HomeworkCommon' order by updated_at desc limit 1;") + end + + def get_course_message_activities_org org + course_ids = org.courses.map{|course| course.id}.join(",") + unless course_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'Message' order by updated_at desc limit 1;") + else + project_acts = nil + end + end + + def get_course_news_activities_org org + course_ids = org.courses.map{|course| course.id}.join(",") + unless course_ids.blank? + project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'News' order by updated_at desc limit 1;") + else + project_acts = nil + end + #project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids}) and container_type = 'course' and org_act_type = 'News' order by updated_at desc limit 1;") end def update @@ -120,12 +248,17 @@ class OrganizationsController < ApplicationController # @organization.domain = params[:organization][:domain] @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 @organization.allow_guest_download = params[:organization][:allow_guest_download] == 'on' ? 1 : 0 + @organization.show_mode = params[:show_mode] #@organization.name = params[:organization][:name] @organization.save respond_to do |format| + if @organization.show_mode == 1 + format.html { redirect_to organization_path(@organization)} + else format.html { redirect_to setting_organization_path(@organization)} end end + end def check_uniq @check = false; @@ -157,11 +290,6 @@ class OrganizationsController < ApplicationController end end - - def clear_org_avatar_temp - - end - def set_homepage @org = Organization.find(params[:id]) @org.home_id = params[:home_id] @@ -224,8 +352,8 @@ class OrganizationsController < ApplicationController if !params[:name].nil? condition = "%#{params[:name].strip}%".gsub(" ","") end - sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+ - "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})" + sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.is_public = 1 and courses.name like '#{condition}'"+ + "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id}) and courses.is_delete=0" #user_courses = Course.find_by_sql(sql) @courses = Course.find_by_sql(sql) # @added_course_ids = @organization.courses.map(&:id) @@ -268,8 +396,8 @@ class OrganizationsController < ApplicationController if !params[:name].nil? condition = "%#{params[:name].strip}%".gsub(" ","") end - sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" + - " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})" + sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.is_public = 1 and projects.name like '#{condition}'" + + " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id}) and status=1" #user_projects = Course.find_by_sql(sql) @projects = Course.find_by_sql(sql) # @added_course_ids = @organization.projects.map(&:id) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2ced977be..113e37af3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -295,34 +295,32 @@ class ProjectsController < ApplicationController def show # 更新消息为已读 update_message_status(User.current, @project) + # over if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end # 统计访问量 - @project.update_attribute(:visits, @project.visits.to_i + 1) + @project.update_column(:visits, @project.visits + 1) + # over @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) @page = params[:page] ? params[:page].to_i + 1 : 0 # 根据私密性,取出符合条件的所有数据 if User.current.member_of?(@project) || User.current.admin? case params[:type] when nil - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo', 'Attachment')",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'issue' - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'news' - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'message' - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'attachment' - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'",@project).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Attachment'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) end else - @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public - = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc") - .page(params['page'|| 1]).per(10); + @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); end - boards = @project.boards.includes(:last_message => :author).all - @topic_count = @project.boards.count # 根据对应的请求,返回对应的数据 respond_to do |format| format.html @@ -560,18 +558,9 @@ class ProjectsController < ApplicationController end def update_message_status(user, project) - project_invite_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =?", user, project, "ProjectInvite") - project_invite_messages.each do |project_invite_message| - project_invite_message.update_attribute(:viewed, true) - end - #更新被加入项目消息的viewed字段 - join_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "JoinProject") - join_project_messages.each do |join_project| - join_project.update_attribute(:viewed, true) - end - #更新被移出项目消息的viewed字段 - remove_project_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type=?", user, project, "RemoveFromProject") - remove_project_messages.update_all(:viewed => true) + # 更新加入项目消息 + project__messages = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'JoinProject', 'RemoveFromProject') and user_id =? and project_id =? ", user, project) + project__messages.update_all(:viewed => true) unless project__messages.blank? end def message_invite(message_id, key) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index a698823e5..36a48f2a3 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -5,14 +5,14 @@ class StudentWorkController < ApplicationController include ApplicationHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] before_filter :is_logged, :only => [:index] - ### + ### def program_test is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} @@ -49,13 +49,127 @@ class StudentWorkController < ApplicationController resultObj[:time] = student_work_test.created_at.to_s(:db) resultObj[:index] = student_work.student_work_tests.count end - end end render :json => resultObj end + #行尾空格替换成□ + def space_replace_1(str) + for i in 0 .. str.size + tChar = str[i] + if tChar != ' ' && tChar != "\n" + sFlag = false + eFlag = false + elsif tChar == ' ' && sFlag == false + tStart = i + sFlag = true + elsif tChar == "\n" + tEnd = i - 1 + if sFlag == true + for j in tStart .. tEnd + str[j] = "□" + end + sFlag = false + end + end + end + end + +#由于负载问题 不要使用全局变量 +#根据传入的tIndex确定是第几次测试 +#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 + def program_test_ex + is_test = params[:is_test] == 'true' + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 + + student_work = find_or_save_student_work(is_test) + + resultObj[:tcount] = @homework.homework_tests.size + + unless student_work + resultObj[:status] = 100 + else + if @homework.homework_type == 2 && @homework.homework_detail_programing + #找到第index个测试的输入输出 + index = params[:tIndex].to_i + resultObj[:tseq] = index + test = @homework.homework_tests[index - 1] + + #请求测试 + result = test_realtime_ex(test, params[:src]) + + if result["status"].to_i != -2 + #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") + #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") + space_replace_1(result["results"].first['output']) + space_replace_1(result["results"].first['result']) + end + + logger.debug result + + #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 + resultObj[:status] = -1 + resultObj[:results] = result["results"].first #本次测试结果 + resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 + + if result["status"].to_i == -2 #编译错误 + resultObj[:results] = result["error_msg"] + resultObj[:status] = -2 + elsif result["results"][0]["status"].to_i == 2 + resultObj[:status] = 2 + end + + unless student_work.save + resultObj[:status] = 200 + else + student_work.name = params[:title] + student_work.description = params[:src] + + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty + else + student_work.late_penalty = 0 + end + + #每次从数据库取出上次的结果加上本次的结果再存入数据库 + status = result["status"] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: status, + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + #先从数据库取出result + student_work_test = StudentWorkTest.find(params[:testid]) + results = student_work_test.results + results << resultObj[:results] + student_work_test.results = results + student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) + student_work_test.save! + status = student_work_test.status + resultObj[:testid] = student_work_test.id + end + + #超时或编译错误则直接返回了并存入数据库 + if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size + if status == 0 + resultObj[:status] = 0 + end + student_work.save! + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + #渲染返回结果 + render :json => resultObj + end + end + end + end + + def index # 作业消息状态更新 @homework.course_messages.each do |homework_message| @@ -63,6 +177,13 @@ class StudentWorkController < ApplicationController homework_message.update_attributes(:viewed => true) if homework_message.viewed == 0 end end + + #修改作品提示消息更新 + student_work_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, StudentWork.name, 0) + student_work_messages.each do |message| + message.update_attribute(:viewed, true) + end + # 作品打分消息状态更新 studentworks_scores = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "StudentWorksScore", 0) studentworks_scores.each do |studentworks_score| @@ -230,12 +351,12 @@ class StudentWorkController < ApplicationController render_403 return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" - + # 消息传过来的ID + @message_student_work_id = params[:student_work_id] respond_to do |format| format.js format.html @@ -369,6 +490,8 @@ class StudentWorkController < ApplicationController @work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@work) if @work.save + #如果学生作品被打分后修改,应该给老师提示 + send_message_to_teacher(@work) if @homework.homework_type == 3 @student_work_project = @homework.student_work_projects.where("user_id=?",User.current.id).first student_work_projects = @homework.student_work_projects.where("student_work_id=? and is_leader =?",@work.id,0) @@ -457,7 +580,7 @@ class StudentWorkController < ApplicationController end end end - redirect_to user_homeworks_user_path(User.current.id) + redirect_to student_homeworks_user_path(User.current.id) end def retry_work @@ -987,7 +1110,6 @@ class StudentWorkController < ApplicationController student_work end - def test_realtime(student_work, src) url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json" @@ -1011,6 +1133,28 @@ class StudentWorkController < ApplicationController JSON.parse(res.body) end + def test_realtime_ex(test, src) + url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json" + + factor = [] + factor << {input: test.input, output: test.output} + + solutions = { + src:src, + language:@homework.homework_detail_programing.language, + factor: factor + } + uri = URI(url) + body = solutions.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 + JSON.parse(res.body) + end + #成绩计算 def set_final_score homework,student_work if homework && homework.homework_detail_manual diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9039fd041..e59e33516 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -119,49 +119,46 @@ class UsersController < ApplicationController # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count case params[:type] when nil + # 系统消息为管理员发送,我的消息中包含有系统消息 @message_alls = [] - messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user, "SystemMessage", "SystemMessage").order("created_at desc") + messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") messages.each do |message_all| @message_alls << message_all.message end when 'unviewed' @message_alls = [] - messages = MessageAll.where("user_id =?", @user).order("created_at desc") + messages = MessageAll.where("user_id =?", @user.id).includes(:message).order("created_at desc") messages.each do |message_all| # 在点击或者刷新消息列表后未读的消息存放在数组 if message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0 @message_alls << message_all.message end end - #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?", @user.id).order("created_at desc") when 'course_message' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user.id).order("created_at desc") when 'course_news' # 课程通知包含发布的通知和回复的通知 - @message_alls = CourseMessage.where("course_message_type in (?, ? ,?)", "News", "Comment", "Course").where("user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =?", @user.id).order("created_at desc") when 'poll' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") - + @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user.id).order("created_at desc") #项目相关消息 when 'issue' - @message_alls = ForgeMessage.where("forge_message_type =? or forge_message_type =?" , "Issue", "Journal").where("user_id=?", @user).order("created_at desc") + @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc") when 'forge_message' - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user.id).order("created_at desc") when 'forge_news' - @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user).order("created_at desc") + @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user.id).order("created_at desc") when 'apply' - @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user).order("created_at desc") - + @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user.id).order("created_at desc") #贴吧消息 when 'forum' - @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") - + @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user.id).order("created_at desc") #用户留言 when 'user_feedback' - @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") + @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user.id).order("created_at desc") else render_404 return @@ -717,6 +714,7 @@ class UsersController < ApplicationController end student_work.save + send_message_to_teacher(student_work) homework.update_attributes(:updated_at => Time.now) update_course_activity(homework.class,homework.id) update_user_activity(homework.class,homework.id) @@ -838,8 +836,8 @@ class UsersController < ApplicationController render_403 return end - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 @@ -888,11 +886,11 @@ class UsersController < ApplicationController def user_ref_resource_search search = params[:search].to_s.strip.downcase if(params[:type].blank? || params[:type] == "1") #全部 - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','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 (filename like '%#{search}%') ").order("created_on desc") elsif params[:type] == "2" #课程资源 - user_course_ids = User.current.courses.map { |c| c.id} + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && 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 '%#{search}%') ").order("created_on desc") elsif params[:type] == "3" #项目资源 @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc") @@ -1209,21 +1207,19 @@ class UsersController < ApplicationController def show # 统计访问量 - unless User.current == @user - @user.update_attribute(:visits, @user.visits.to_i + 1) - end + @user.update_column(:visits, @user.visits.to_i + 1) unless User.current == @user #更新用户申请成为课程老师或教辅消息的状态 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 =?", params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) join_course_messages.update_all(:viewed => true) end - shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) @page = params[:page] ? params[:page].to_i + 1 : 0 user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" + course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" project_types = "('Message','Issue','ProjectCreateInfo')" principal_types = "JournalsForMessage" if params[:type].present? @@ -1236,6 +1232,8 @@ class UsersController < ApplicationController @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) when "course_poll" @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + when "course_journals" + @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) when "project_issue" @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) when "project_message" @@ -1253,7 +1251,13 @@ class UsersController < ApplicationController end else # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # 减少数据库交互 + watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) + user_ids = "(" + @user.id.to_s + watched_user_ids + ")" + watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") + blog_ids = "(" + watched_user_blog_ids + ")" + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + @@ -1575,16 +1579,14 @@ class UsersController < ApplicationController # 上传用户资源 def user_resource_create - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} @user = User.find(params[:id]) # 保存文件 attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @score = @b_sort == "desc" ? "asc" : "desc" - 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].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 @@ -1614,8 +1616,10 @@ class UsersController < ApplicationController @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end + @status = params[:status] @type = params[:type] + @path = user_resource_user_path(User.current, :type => @type) @limit = 25 @is_remote = true @atta_count = @attachments.count @@ -1673,6 +1677,7 @@ class UsersController < ApplicationController end @status = params[:status] @type = params[:type] + @path = user_resource_user_path(User.current, :type => @type) @limit = 25 @is_remote = true @atta_count = @attachments.count @@ -1697,6 +1702,7 @@ class UsersController < ApplicationController .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 } end @search = params[:search] + @type = params[:type] #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] @@ -1715,6 +1721,7 @@ class UsersController < ApplicationController @projects = @user.projects.visible end @search = params[:search] + @type = params[:type] #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids @@ -1811,11 +1818,41 @@ class UsersController < ApplicationController else @flag = false end + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(params[:id], @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(params[:id], @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + end @type = params[:type] @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) @user = User.current @is_remote = true @atta_count = @attachments.count @@ -1922,11 +1959,42 @@ class UsersController < ApplicationController else @flag=true end + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(params[:id], @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(params[:id], @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + end + @status = params[:status] @type = params[:type] @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) @user = User.current @is_remote = true @atta_count = @attachments.count @@ -2020,11 +2088,41 @@ class UsersController < ApplicationController else @flag=true end + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(params[:id], @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(params[:id], @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + end @type = params[:type] @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) @user = User.current @is_remote = true @atta_count = @attachments.count @@ -2367,7 +2465,7 @@ class UsersController < ApplicationController # 获取我的资源 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')) "+ + attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','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("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2473,15 +2571,15 @@ class UsersController < ApplicationController # 资源库 分为全部 课程资源 项目资源 附件 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 return end - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 @@ -2538,8 +2636,8 @@ class UsersController < ApplicationController @user = User.find(params[:id]) @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @score = @b_sort == "desc" ? "asc" : "desc" - 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} + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # 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, @order, @score) @@ -2563,6 +2661,10 @@ class UsersController < ApplicationController end def import_resources_search + if User.current.id.to_i != params[:id].to_i + render_403 + return + end @resource_id = params[:mul_id] @resource_type = params[:mul_type] @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -2571,15 +2673,10 @@ class UsersController < ApplicationController @switch_search = params[:name].nil? ? " " : params[:name] search = "%#{@switch_search.strip.downcase}%" # 别人的资源库是没有权限去看的 - if User.current.id.to_i != params[:id].to_i - render_403 - return - end - @resource_id = params[:mul_id] if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) elsif params[:type] == "6" # 公共资源 @@ -2659,8 +2756,8 @@ class UsersController < ApplicationController @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_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 if params[:status] == "2" @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search) @@ -2718,6 +2815,7 @@ class UsersController < ApplicationController name = "%"+name+"%" @orgs = User.current.organizations.where("name like ?", name) @user = User.current + @type = params[:type] respond_to do |format| format.html {render :layout => 'static_base'} format.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3a5cdb1a1..828123675 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -764,7 +764,7 @@ module ApplicationHelper # 判断版本库是否初始为gitlab def rep_is_gitlab?(project) - rep = Repository.where("project_id =? and type =?", project, "Repository::Gitlab") + rep = project.repositories.where("type =?", "Repository::Gitlab") return rep.blank? ? true :false end @@ -2104,6 +2104,8 @@ module ApplicationHelper attachment.container.board.course course = attachment.container.board.course candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.class.to_s=="Organization" + candown = true elsif attachment.container.class.to_s=="HomeworkAttach" candown = true elsif attachment.container.class.to_s=="StudentWorksScore" @@ -2137,6 +2139,20 @@ module ApplicationHelper end + #如果学生作品被打分后修改,应该给老师提示 + def send_message_to_teacher student_work + if StudentWork === student_work + if student_work.student_works_scores.any? + course = student_work.homework_common.course + course.members.map(&:user_id).uniq.each do|user_id| + if User.find(user_id).allowed_to?(:as_teacher, course) + student_work.course_messages << CourseMessage.new(:user_id => user_id, :course_id => course.id, :viewed => false, :status => 1) + end + end + end + end + end + private def wiki_helper @@ -3044,3 +3060,7 @@ def is_default_field? field (field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default' end +def host_with_protocol + return Setting.protocol + "://" + Setting.host_name +end + diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 37c7deb4c..64531a6f4 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -24,40 +24,20 @@ module CoursesHelper def find_excelletn_course keywords, current_course # 获取tag匹配结果ID a_tags = [] - # kc = keywords.to_a - Course.visible.where("is_excellent =? and is_public =?", 1, 1).each do |ec| + Course.where("is_excellent =? and is_public =?", 1, 1).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end end - # sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and - # ts.taggable_type = 'Course' and t.name like '%#{keywords}%'" - # 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 - 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 + excellent_ids = a_tags.uniq.delete_if{|i| i == current_course.id} sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id - and c.is_excellent =1 and c.is_public = 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, arr_result).where("id !=?", current_course.id) + and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" + default_ids = Course.find_by_sql(sql).flatten.map { |c| c.id } + excellent_ids << default_ids.flatten + arr_result = excellent_ids.flatten.uniq.first(5) + excellent_courses = Course.find(arr_result) + return excellent_courses end # 判断精品课程是否可见,非课程成员无法查看私有课程 @@ -258,7 +238,7 @@ module CoursesHelper # 学生人数计算 # add by nwb def studentCount course - course ? course.student.count.to_s : 0#course.student.count + course ? course.student.count.to_i : 0#course.student.count end #课程成员数计算 @@ -293,12 +273,17 @@ module CoursesHelper def searchTeacherAndAssistant project #searchPeopleByRoles(project, TeacherRoles) members = [] - project.members.each do |m| + project.members.includes(:user).each do |m| members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) end members end + def TeacherAndAssistantCount course + students_count = course.student.count + number = course.members.count - students_count + end + def search_student_in_group(project, course_group_id) #searchPeopleByRoles(project, StudentRoles) members = [] @@ -766,7 +751,7 @@ module CoursesHelper #加入课程、退出课程按钮 def join_in_course_header(course, user, options=[]) if user.logged? - joined = course.members.map{|member| member.user_id}.include? user.id + joined = course.members.includes(:user).map{|member| member.user_id}.include? user.id 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' diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index bef6b580c..b161e29e9 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -111,9 +111,9 @@ module IssuesHelper def principals_options_for_isuue_list(project) if User.current.member_of?(project) - project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) + project.members.includes(:user).order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) else - project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0]) + project.members.includes(:user).order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0]) end end diff --git a/app/helpers/org_member_helper.rb b/app/helpers/org_member_helper.rb index fd70a0516..e16051eaf 100644 --- a/app/helpers/org_member_helper.rb +++ b/app/helpers/org_member_helper.rb @@ -9,7 +9,7 @@ module OrgMemberHelper principals = paginateHelper scope,10 s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| - link_to text, org_member_autocomplete_org_member_index_path(parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js')), :remote => true + link_to text, host_with_protocol + "/org_member/org_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js').to_query, :remote => true } s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) end diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 69c355313..4faa802a5 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -1,6 +1,7 @@ # encoding: utf-8 module OrganizationsHelper include ApplicationHelper + include FilesHelper def find_user_not_in_current_org_by_name org @@ -28,4 +29,48 @@ module OrganizationsHelper end end + def get_message_org(org_id, field_id) + OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and org_subfield_id = #{field_id} and parent_id is null order by updated_at desc limit 8;") + end + + def get_message_reply_org(org_id, ids) + # OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and parent_id is not null order by updated_at desc limit 1;") + OrgDocumentComment.find_by_sql("SELECT * FROM org_document_comments where organization_id = #{org_id} and parent_id in (#{ids}) order by updated_at desc limit 1;") + end + + def get_attach_org(field_id) + Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;") + end + + def get_attach_org2(field) + org_attachments = field.attachments + attachments = User.current.admin? ? org_attachments : visable_attachemnts(org_attachments) + return attachments.sort_by{|x| x.created_on}.reverse.first(6) + # Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;") + end + + # 从内容中获取路径 + def get_image_path_from_content content + r = Regexp.new(/src="\/files\/uploads\/image(.+?)"/) + if r.match(content).nil? + image_path = nil + else + image_path = r.match(content)[1] + end + end + + #排列下拉框 + def subfield_status_option + type = [] + option1 = [] + option1 << "列表" + option1 << "1" + type << option1 + option2 = [] + option2 << "图片" + option2 << "0" + type << option2 + type + end + end diff --git a/app/helpers/school_helper.rb b/app/helpers/school_helper.rb index 0528cb7ac..075d2b039 100644 --- a/app/helpers/school_helper.rb +++ b/app/helpers/school_helper.rb @@ -1,2 +1,15 @@ module SchoolHelper + def schoolMember_num school + count = student_num(school) + teacher_num(school) + count.to_s + end + + def student_num school + UserExtensions.find_by_sql("SELECT * FROM user_extensions WHERE occupation = '#{school.name}' AND identity = '1'").count + end + + def teacher_num school + UserExtensions.find_by_sql("SELECT * FROM user_extensions AS ue, schools AS s WHERE ue.school_id = s.id AND s.name = '#{school.name}' AND ue.identity = '0'").count + end + end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index df5c872f8..4e11e153e 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -130,7 +130,7 @@ module StudentWorkHelper def revise_attachment_status homework, attach date = Time.parse(format_time(attach.created_on.to_s)).strftime("%Y-%m-%d") status = "" - if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time < date)) + if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time.to_s < date)) status = "此时其他同学作品已公开" else status = "此时其他同学作品尚未公开" diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 714da9920..754bd4dee 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -23,6 +23,7 @@ class Attachment < ActiveRecord::Base belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'" belongs_to :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'" + belongs_to :organization, foreign_key: 'container_id', conditions: "attachements.container_type = 'Organization'" belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" @@ -90,7 +91,7 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") before_save :files_to_final_location - after_save :act_as_course_activity,:act_as_forge_activity + after_save :act_as_course_activity after_create :office_conver, :be_user_score,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score diff --git a/app/models/organization.rb b/app/models/organization.rb index 248783a26..427cd4c10 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -8,6 +8,8 @@ class Organization < ActiveRecord::Base has_many :org_courses, :dependent => :destroy has_many :org_subfields, :dependent => :destroy has_many :users, :through => :org_members + has_many :files + acts_as_attachable validates_uniqueness_of :name after_create :save_as_org_activity, :add_default_subfields diff --git a/app/models/principal.rb b/app/models/principal.rb index dd376f609..0c87ec0c6 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -42,9 +42,9 @@ class Principal < ActiveRecord::Base if q.blank? where({}) else - pattern = "%#{q}%" + pattern = "%#{q}%".gsub("/","//").gsub("_","/_") # sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") - sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p)" + sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) escape '/' or LOWER(login) LIKE LOWER(:p) escape '/' or LOWER(mail) LIKE LOWER(:p) escape '/'" params = {:p => pattern} if q =~ /^(.+)\s+(.+)$/ a, b = "#{$1}%", "#{$2}%" diff --git a/app/models/project.rb b/app/models/project.rb index 32677143d..184b3c7af 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -108,7 +108,8 @@ class Project < ActiveRecord::Base has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' # 动态级联删除 - has_many :forge_activities, :class_name => 'ForgeActivity', :dependent => :destroy + has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy + #has_many :forge_activities, :class_name => 'ForgeActivity', :as =>:forge_act, :dependent => :destroy # 关联虚拟表 has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy @@ -1212,9 +1213,7 @@ class Project < ActiveRecord::Base # Author lizanle # Description 新建项目要在ForgeActivities中加一条数据。 def acts_as_forge_activities - fa = ForgeActivity.new(:user_id => User.current.id,:project_id => self.id, - :forge_act_id => self.id,:forge_act_type => "ProjectCreateInfo") - fa.save! + self.forge_acts << ForgeActivity.new(:user_id => User.current.id, :project_id => self.id) end diff --git a/app/models/user.rb b/app/models/user.rb index 4e62f3bd0..dc7a3e741 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -340,13 +340,15 @@ class User < Principal message_new_time.onclick_time = User.current.last_login_on.nil? ? Time.now : User.current.last_login_on message_new_time.save end - course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count - forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count - user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", User.current.id, 0, User.current.onclick_time.onclick_time).count - 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 - org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", User.current.id,0, User.current.onclick_time.onclick_time).count + user = User.current + onclick_time = user.onclick_time.onclick_time + course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + system_messages_count = SystemMessage.where("created_at >?", onclick_time).count + at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", user.id,0, onclick_time).count messages_count = course_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count end diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb index 4316555f7..2e83a96aa 100644 --- a/app/views/admin/course_resource_list.html.erb +++ b/app/views/admin/course_resource_list.html.erb @@ -10,16 +10,16 @@ 资源名称
+ | 序号 | -+ | LOGO | -+ | 学校名称 | -+ | + 用户数 + | ++ 创建时间 + | ++ 编辑高校信息 + | |
---|---|---|---|---|---|---|---|---|---|---|
- <%= school.id %> + + + <% @count +=1 %> + | + <%=@count %> | +<%= image_tag(school.logo_link,width:40,height:40) %> + | + -+ | + <%= schoolMember_num(school) %> + | ++ <%= format_time(school.created_at) %> + | +<%= link_to("修改", upload_logo_school_path(school.id,:school_name => @school_name), :class => 'icon icon-copy') %> <%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> | @@ -50,4 +71,4 @@ <%= pagination_links_full @school_pages, @school_count ,:per_page_links => true, :remote => false, :flag => true %> -<% html_title(l(:label_project_plural)) -%> +<% html_title(l(:label_school_plural)) -%> diff --git a/app/views/admin/users.html.erb b/app/views/admin/users.html.erb index 12aa95a16..2a757fdee 100644 --- a/app/views/admin/users.html.erb +++ b/app/views/admin/users.html.erb @@ -40,7 +40,10 @@ <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %> <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %> -+ <%#= sort_header_tag('user_occupation', :caption => l(:field_occupation), :default_order => 'desc') %> + | 用户单位 | ++ | <%= change_status_link(user) %> - <%= delete_link user_path(user, :back_url => admin_users_path(params)) unless User.current == user %> | + <% occupation = user.user_extensions.identity == 0 ? School.where("id=?",user.user_extensions.school_id).first.try(:name) : user.user_extensions.occupation %> + + + + <% end -%> diff --git a/app/views/attachments/_activity_attach.html.erb b/app/views/attachments/_activity_attach.html.erb index 32e796382..3cc429185 100644 --- a/app/views/attachments/_activity_attach.html.erb +++ b/app/views/attachments/_activity_attach.html.erb @@ -3,14 +3,14 @@