diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 24cbecb81..784066378 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -96,14 +96,14 @@ class WelcomeController < ApplicationController @projects = Project.all_public.active render :layout => false, :content_type => 'text/plain' end - + def course redirect_to signin_path return - - @course_page = FirstPage.find_by_page_type('course') - @school_id = params[:school_id] || User.current.user_extensions.school.try(:id) || 117 - @logoLink ||= logolink() + # + # @course_page = FirstPage.find_by_page_type('course') + # @school_id = params[:school_id] || User.current.user_extensions.school.try(:id) || 117 + # @logoLink ||= logolink() end def logolink() @@ -146,8 +146,8 @@ class WelcomeController < ApplicationController redirect_to signin_path return - @contest_page = FirstPage.find_by_page_type('contest') - @contest_notifications = Contestnotification.order("created_at desc").limit(5) + # @contest_page = FirstPage.find_by_page_type('contest') + # @contest_notifications = Contestnotification.order("created_at desc").limit(5) end def search @@ -187,28 +187,28 @@ class WelcomeController < ApplicationController private # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 def entry_select - url = request.original_url.gsub('/','') - if url.include?(Setting.url_course.gsub('/','')) - if @first_page.show_course == 1 - course - render :course - else - render_404 - end - - return 0 - elsif url.include?(Setting.url_contest.gsub('/','')) - if @first_page.show_contest == 1 - contest - render :contest - else - render_404 - end - - return 0 - elsif url.include?(Setting.url_user.gsub('/','')) - #redirect_to(:controller => "users", :action => "index") - end + # url = request.original_url.gsub('/','') + # if url.include?(Setting.url_course.gsub('/','')) + # if @first_page.show_course == 1 + # course + # render :course + # else + # render_404 + # end + # + # return 0 + # elsif url.include?(Setting.url_contest.gsub('/','')) + # if @first_page.show_contest == 1 + # contest + # render :contest + # else + # render_404 + # end + # + # return 0 + # elsif url.include?(Setting.url_user.gsub('/','')) + # #redirect_to(:controller => "users", :action => "index") + # end end diff --git a/app/models/course.rb b/app/models/course.rb index 26220f245..501d958e4 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -37,7 +37,8 @@ class Course < ActiveRecord::Base has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy has_many :course_activities - has_many :course_messages + # 课程消息 + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 95ce3a56b..4f62d24c2 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -11,6 +11,7 @@ class CourseMessage < ActiveRecord::Base validates :course_id,presence: true validates :course_message_id,presence: true validates :course_message_type, presence: true + validates_length_of :content, :maximum => 100 after_create :add_user_message def add_user_message diff --git a/app/models/project.rb b/app/models/project.rb index 77711edff..0618dd145 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -92,7 +92,7 @@ class Project < ActiveRecord::Base has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' # 关联虚拟表 - has_many :forge_messages + has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy belongs_to :organization diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index 2d23c6dd6..207572a1c 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -44,7 +44,7 @@ <%= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :title => "#{ma.course_message.title}" %> -
  • <%= time_tag(ma.course_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.course_message_type == "Comment" %> @@ -55,7 +55,7 @@ <%= link_to ma.course_message.comments.html_safe, {:controller => 'news', :action => 'show', :id => ma.course_message.commented.id }, :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :title => "#{ma.course_message.comments.html_safe}" %> -
  • <%= time_tag(ma.course_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.course_message_type == "HomeworkCommon" %> @@ -64,7 +64,7 @@
  • <%=link_to ma.course_message.user, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">发布了作业:
  • <%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),:class => "newsGrey", :title => "#{ma.course_message.name}" %>
  • -
  • <%= time_tag(ma.course_message.created_at).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.course_message_type == "Poll" %> @@ -75,7 +75,7 @@ <%= link_to format_activity_title(" #{ma.course_message.polls_name.nil? ? "未命名问卷" : ma.course_message.polls_name}"), poll_path(ma.course_message.id), :class=>"#{ma.viewed==0?"newsBlack":"newsGrey"}", :title => "#{ma.course_message.polls_name}" %> -
  • <%= time_tag(ma.course_message.created_at).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.course_message_type == "Message" %> @@ -86,7 +86,7 @@ <%=link_to ma.course_message.subject.html_safe, course_boards_path(ma.course_message.course,:parent_id => ma.course_message.parent_id ? ma.course_message.parent_id : ma.course_message.id, :topic_id => ma.course_message.id),:class=>"#{ma.viewed==0?"newsBlack":"newsGrey"}", :title => "#{ma.course_message.subject.html_safe}" %> -
  • <%= time_tag(ma.course_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> @@ -107,7 +107,7 @@
  • <%=link_to ma.course_message.user, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">回复了作品评论:
  • <%= link_to ma.course_message.notes, student_work_index_path(:homework => ma.course_message.jour.student_work.homework_common_id),:class=>"newsGrey",:title => "#{ma.course_message.notes}" %>
  • -
  • <%= time_tag(ma.course_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% end %> @@ -143,7 +143,7 @@ issue_path(:id => ma.forge_message.journalized_id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :title => "#{get_issue_des_update(ma.forge_message).html_safe}" %> -
  • <%= time_tag(ma.forge_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.forge_message_type == "Message" %> @@ -156,7 +156,7 @@ :parent_id => ma.forge_message.parent_id ? ma.forge_message.parent_id : ma.forge_message.id, :topic_id => ma.forge_message.id),:class=>"#{ma.viewed==0?"newsBlack":"newsGrey"}", :title => "#{ma.forge_message.subject.html_safe}" %> -
  • <%= time_tag(ma.forge_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.forge_message_type == "News" %> @@ -171,7 +171,7 @@
  • <%= link_to ("#{ma.forge_message.title.html_safe}"), {:controller => 'news', :action => 'show', :id => ma.forge_message.id}, :class => "newsGrey", :title => "#{ma.forge_message.title.html_safe}" %>
  • -
  • <%= time_tag(ma.forge_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% if ma.forge_message_type == "Comment" %> @@ -182,7 +182,7 @@
  • <%= link_to "#{ma.forge_message.comments.html_safe}", {:controller => 'news', :action => 'show', :id => ma.forge_message.commented.id },:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :title => "#{ma.forge_message.comments.html_safe}"%>
  • -
  • <%= time_tag(ma.forge_message.created_on).html_safe %>
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> <% end %> diff --git a/db/migrate/20150829023459_forge_messages.rb b/db/migrate/20150829023459_forge_messages.rb new file mode 100644 index 000000000..c468ad68f --- /dev/null +++ b/db/migrate/20150829023459_forge_messages.rb @@ -0,0 +1,80 @@ +# encoding: UTF-8 +class ForgeMessages < ActiveRecord::Migration + def up + Project.all.each do |project| + transaction do + project.forge_messages << ForgeMessage.new(:user_id => project.user_id, :project_id => project.id) + + # 新闻 + project.news.each do |new| + new.project.members.each do |m| + if m.user_id != new.author_id + if m.created_on < new.created_on # 在成员加入项目之后 + new.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => new.project_id, :viewed => true) + end + end + end + end + + # 新闻回复 + project.news.each do |new| + if new.comments + new.comments.each do |comment| + if comment.author_id != comment.commented.author_id + comment.forge_messages << ForgeMessage.new(:user_id => comment.commented.author_id, :project_id => comment.commented.project.id, :viewed => true) + end + end + end + end + + # 讨论区 + if project.boards.first + project.boards.first.messages.each do |message| + if message.parent_id.nil? # 主贴 + message.project.members.each do |m| + if m.user_id != message.author_id + if m.created_on < message.created_on + message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) + end + end + end + else # 回帖 + message.project.members.each do |m| + if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 + if m.created_on < message.created_on + message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) + end + end + end + end + end + end + + # 缺陷 + project.issues.each do |issue| + unless issue.author_id == issue.assigned_to_id + issue.forge_messages << ForgeMessage.new(:user_id => issue.assigned_to_id, :project_id => issue.project_id, :viewed => true) + end + end + + # 缺陷更新 + project.issues.each do |issue| + if issue.journals + issue.journals.each do |journal| + if journal.user_id != journal.issue.author_id + journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.author_id, :project_id => journal.issue.project_id, :viewed => true) + end + if journal.user_id != journal.issue.assigned_to_id && journal.issue.assigned_to_id != journal.issue.author_id # 指派人不是自己的话,则给指派人发送 + journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.assigned_to_id, :project_id => journal.issue.project_id, :viewed => true) + end + end + end + end + + end + end + end + + def down + end +end diff --git a/db/migrate/20150829024549_course_messages.rb b/db/migrate/20150829024549_course_messages.rb new file mode 100644 index 000000000..666ccdaeb --- /dev/null +++ b/db/migrate/20150829024549_course_messages.rb @@ -0,0 +1,115 @@ +# encoding: UTF-8 +class CourseMessages < ActiveRecord::Migration + def up + Course.all.each do |course| + transaction do + course.course_messages << CourseMessage.new(:user_id => course.tea_id,:course_id => course.id) + # 作业 + course.homework_commons.each do |homework_common| + homework_common.course.members.each do |m| + if m.user_id != homework_common.user_id + if m.created_on < homework_common.created_at + homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + end + end + end + end + + # 通知 + course.news.each do |new| + new.course.members.each do |m| + if m.user_id != new.author_id + if m.created_on < new.created_on # 在成员加入课程之后 + new.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + end + end + end + end + + # 通知的回复 + course.news.each do |new| + if new.comments + new.comments.each do |comment| + if comment.author_id != comment.commented.author_id + comment.course_messages << CourseMessage.new(:user_id => comment.commented.author_id, :course_id => course.id, :viewed => true) + end + end + end + end + + # 讨论区 + if course.boards.first + course.boards.first.messages.each do |message| + if message.parent_id.nil? # 主贴 + message.course.members.each do |m| + if message.author.allowed_to?(:as_teacher, message.course) && m.user_id != message.author_id # 老师 自己的帖子不给自己发送消息 + if m.created_on < message.created_on + message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + end + end + end + else # 回帖 + message.course.members.each do |m| + if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 + if m.created_on < message.created_on + message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + end + end + end + end + end + end + + # 问卷 + Poll.where("polls_type = 'Course' and polls_group_id = #{course.id}").each do |poll| + if poll.polls_status == 2 #问卷是发布状态 + Course.find(poll.polls_group_id).members.each do |m| + if m.user_id != poll.user_id + if m.created_on < poll.created_at + poll.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + end + end + end + elsif poll.polls_status == 1 #问卷是新建状态 + poll.course_messages.destroy_all + end + end + + # 作品评阅 + # course.homework_commons.each do |homework_common| + # if homework_common.student_works + # homework_common.student_works.each do |student_work| + # if student_work.student_works_scores + # student_work.student_works_scores.each do |student_works_score| + # receiver = student_works_score.student_work.user + # if student_works_score.created_at == student_works_score.updated_at + # if student_works_score.comment.nil? + # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, + # :viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true) + # else + # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, + # :viewed => true, :content => "作业评分:#{student_works_score.score}    评语:#{student_works_score.comment}", :status=> true) + # end + # else # 更新 + # if student_works_score.comment.nil? + # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, + # :viewed => true, :content => "作业评分:#{student_works_score.score}", :status=> true) + # else + # student_works_score.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => course.id, + # :viewed => true, :content => "作业评分:#{student_works_score.score}    评语:#{student_works_score.comment}", :status=> true) + # end + # end + # end + # end + # end + # end + # end + # 作品讨论 + + end + end + end + + def down + end +end diff --git a/db/migrate/20150829081822_update_message_time.rb b/db/migrate/20150829081822_update_message_time.rb new file mode 100644 index 000000000..fe670e9b8 --- /dev/null +++ b/db/migrate/20150829081822_update_message_time.rb @@ -0,0 +1,26 @@ +class UpdateMessageTime < ActiveRecord::Migration + def up + course_count = CourseMessage.all.count / 30 + 1 + transaction do + for i in 1 ... course_count do i + CourseMessage.page(i).per(30).each do |cmessage| + if cmessage.course_message + if cmessage.course_message.respond_to?("created_at") + cmessage.created_at = cmessage.course_message.created_at + elsif cmessage.course_message.respond_to?("created_on") + cmessage.created_at = cmessage.course_message.created_on + end + cmessage.save + + course_all_message = MessageAll.where("message_type = '#{cmessage.class.to_s}' and message_id = '#{cmessage.id}'").first + course_all_message.created_at = cmessage.created_at + course_all_message.save + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20150829130302_update_forge_message_time.rb b/db/migrate/20150829130302_update_forge_message_time.rb new file mode 100644 index 000000000..70811c307 --- /dev/null +++ b/db/migrate/20150829130302_update_forge_message_time.rb @@ -0,0 +1,26 @@ +class UpdateForgeMessageTime < ActiveRecord::Migration + def up + forge_count = ForgeMessage.all.count / 30 + 1 + transaction do + for i in 1 ... forge_count do i + ForgeMessage.page(i).per(30).each do |fmessage| + if fmessage.forge_message + if fmessage.forge_message.respond_to?("created_at") + fmessage.created_at = fmessage.forge_message.created_at + elsif fmessage.forge_message.respond_to?("created_on") + fmessage.created_at = fmessage.forge_message.created_on + end + fmessage.save + + forge_all_message = MessageAll.where("message_type = '#{fmessage.class.to_s}' and message_id = '#{fmessage.id}'").first + forge_all_message.created_at = fmessage.created_at + forge_all_message.save + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 3c43292e5..05825bd5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150826061843) do +ActiveRecord::Schema.define(:version => 20150829070453) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1317,7 +1317,6 @@ ActiveRecord::Schema.define(:version => 20150826061843) do t.datetime "updated_at", :null => false t.integer "late_penalty", :default => 0 t.integer "absence_penalty", :default => 0 - t.integer "system_score" end create_table "student_works_evaluation_distributions", :force => true do |t| @@ -1535,6 +1534,7 @@ ActiveRecord::Schema.define(:version => 20150826061843) do t.string "identity_url" t.string "mail_notification", :default => "", :null => false t.string "salt", :limit => 64 + t.integer "gid" end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id"