竞赛消息的调整
This commit is contained in:
parent
c4927070a0
commit
9331525304
|
@ -73,13 +73,21 @@ class ContestsController < ApplicationController
|
|||
end
|
||||
case params[:agree]
|
||||
when 'Y'
|
||||
members = []
|
||||
members << ContestMember.new(:role_ids => integer_ids, :user_id => apply_user.id)
|
||||
Contest.find(applied_contest.contest_id).contest_members << members
|
||||
member = ContestMember.new(:user_id => apply_user.id)
|
||||
Contest.find(applied_contest.contest_id).contest_members << member
|
||||
|
||||
contest_member_roles = member.contest_member_roles
|
||||
if integer_ids.include?(14) && integer_ids.include?(13)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 13)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 14, :is_current => 0)
|
||||
else
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => integer_ids[0])
|
||||
end
|
||||
|
||||
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>1)
|
||||
applied_contest.applied_messages.update_all(:status => 1, :viewed => 1)
|
||||
applied_contest.update_attributes(:status => 1)
|
||||
if integer_ids.include?("15")
|
||||
if integer_ids.include?(15)
|
||||
ContestantForContest.create(:student_id => apply_user.id, :contest_id =>applied_contest.contest_id)
|
||||
end
|
||||
|
||||
|
|
|
@ -2091,7 +2091,7 @@ class UsersController < ApplicationController
|
|||
@message_alls << mess
|
||||
end
|
||||
elsif (message_all.message_type == "AppliedMessage" )
|
||||
if (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
|
||||
if (mess.applied_type == "AppliedContest" && mess.status == 0) || (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
|
||||
@message_alls << mess
|
||||
end
|
||||
elsif message_all.message_type == "CourseMessage"
|
||||
|
|
|
@ -2829,7 +2829,7 @@ module ApplicationHelper
|
|||
|
||||
# 用户竞赛总数
|
||||
def user_contest_count
|
||||
count = @user.contests.where(:is_delete => false).count
|
||||
count = @user.favorite_contests.visible.where("is_delete =?", 0).count
|
||||
return count
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class AppliedContest < ActiveRecord::Base
|
||||
include ContestsHelper
|
||||
belongs_to :contest
|
||||
belongs_to :user
|
||||
#status :0 新建 1 已批准 2 拒绝
|
||||
|
@ -9,8 +10,18 @@ class AppliedContest < ActiveRecord::Base
|
|||
|
||||
# 仅仅给项目管理人员发送消息
|
||||
def send_appliled_message
|
||||
self.contest.contest_managers.each do |member|
|
||||
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => self.role)
|
||||
case self.role
|
||||
when '13'
|
||||
role = 1
|
||||
when '14'
|
||||
role = 2
|
||||
when '15'
|
||||
role = 3
|
||||
else
|
||||
role = 4
|
||||
end
|
||||
contest_managers(self.contest).each do |member|
|
||||
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => role)
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -22,30 +22,30 @@ class ContestMember < ActiveRecord::Base
|
|||
self.user.name
|
||||
end
|
||||
|
||||
alias :base_role_ids= :role_ids=
|
||||
def role_ids=(arg)
|
||||
ids = (arg || []).collect(&:to_i) - [0]
|
||||
|
||||
new_role_ids = ids - role_ids
|
||||
if (new_role_ids.include?(14) || new_role_ids.include?(13)) && role_ids.include?(15)
|
||||
contest_member_roles.where("role_id = 15").first.update_column('is_current', 0)
|
||||
end
|
||||
# Add new roles
|
||||
if new_role_ids.include?(14) && new_role_ids.include?(13)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 14)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
|
||||
elsif new_role_ids.include?(13) && new_role_ids.include?(15)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 13)
|
||||
contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
|
||||
else
|
||||
new_role_ids.each {|id| contest_member_roles << ContestMemberRole.new(:role_id => id) }
|
||||
end
|
||||
# Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
|
||||
member_roles_to_destroy = contest_member_roles.select {|mr| !ids.include?(mr.role_id)}
|
||||
if member_roles_to_destroy.any?
|
||||
member_roles_to_destroy.each(&:destroy)
|
||||
end
|
||||
end
|
||||
# alias :base_role_ids= :role_ids=
|
||||
# def role_ids=(arg)
|
||||
# ids = (arg || []).collect(&:to_i) - [0]
|
||||
#
|
||||
# new_role_ids = ids - role_ids
|
||||
# if (new_role_ids.include?(14) || new_role_ids.include?(13)) && role_ids.include?(15)
|
||||
# contest_member_roles.where("role_id = 15").first.update_column('is_current', 0)
|
||||
# end
|
||||
# # Add new roles
|
||||
# if new_role_ids.include?(14) && new_role_ids.include?(13)
|
||||
# contest_member_roles << ContestMemberRole.new(:role_id => 14)
|
||||
# contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
|
||||
# elsif new_role_ids.include?(13) && new_role_ids.include?(15)
|
||||
# contest_member_roles << ContestMemberRole.new(:role_id => 13)
|
||||
# contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
|
||||
# else
|
||||
# new_role_ids.each {|id| contest_member_roles << ContestMemberRole.new(:role_id => id) }
|
||||
# end
|
||||
# # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
|
||||
# member_roles_to_destroy = contest_member_roles.select {|mr| !ids.include?(mr.role_id)}
|
||||
# if member_roles_to_destroy.any?
|
||||
# member_roles_to_destroy.each(&:destroy)
|
||||
# end
|
||||
# end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class ContestMessage < ActiveRecord::Base
|
||||
attr_accessible :content, :contest_message_id, :course_message_type, :status, :viewed
|
||||
attr_accessible :content, :contest_message_id, :contest_message_type, :status, :viewed, :user_id, :contest_id
|
||||
|
||||
belongs_to :contest_message ,:polymorphic => true
|
||||
belongs_to :user
|
||||
|
|
|
@ -4,5 +4,5 @@ class ContestantForContest < ActiveRecord::Base
|
|||
|
||||
belongs_to :contestants, :class_name => 'User', :foreign_key => :student_id
|
||||
validates_presence_of :contest_id, :student_id
|
||||
validates_uniqueness_of :student_id, :scope => :course_id
|
||||
validates_uniqueness_of :student_id, :scope => :contest_id
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class ContestsService
|
|||
else
|
||||
if params[:invite_code].present?
|
||||
role_ids = params[:role]
|
||||
role_str = role_ids.join(",")
|
||||
role_str = role_ids.join(",").to_s
|
||||
|
||||
#如果已经发送过消息了,那么就要给个提示
|
||||
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0).count != 0
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
role_str = "参赛者"
|
||||
end
|
||||
end %>
|
||||
申请以<%= role_str %>的身份加入班级:
|
||||
申请以<%= role_str %>的身份加入竞赛:
|
||||
</span>
|
||||
</li>
|
||||
<li class="messageInformationContents">
|
||||
|
@ -36,7 +36,7 @@
|
|||
</div>
|
||||
<li class="messageOperateContents fl">
|
||||
<span id="deal_info_<%=ma.id%>">
|
||||
<% if ma.status == 0 || ma.status.nil?%>
|
||||
<% if ma.status == 0 %>
|
||||
<%= link_to '同意',dealwith_apply_request_contest_path(contest,:agree=>'Y',:msg_id=>ma.id),:remote=>'true',:class=>'linkBlue'%>
|
||||
|
|
||||
<%= link_to '拒绝',dealwith_apply_request_contest_path(contest,:agree=>'N',:msg_id=>ma.id),:remote=>'true',:class=>'linkBlue'%>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<% if ma.contest_message_type == "ContestRequestDealResult" %>
|
||||
<% if ma.class == ContestMessage %>
|
||||
<% if ma.contest_message_type == "ContestRequestDealResult" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<div class="longMessageWidth">
|
||||
<li class="homepageNewsPortrait fl">
|
||||
|
@ -23,12 +24,13 @@
|
|||
end
|
||||
end %>
|
||||
<%= link_to ma.status == 1 ?
|
||||
'您申请成为竞赛"'+Course.find(ma.course_id).name+'"的'+ role_str +'申请已通过'
|
||||
'您申请成为竞赛"'+Contest.find(ma.contest_id).name+'"的'+ role_str +'申请已通过'
|
||||
:
|
||||
'您申请成为竞赛"'+Course.find(ma.course_id).name+'"的'+ role_str +'的申请被拒绝', contest_path(Contest.find(ma.contest_id)),
|
||||
'您申请成为竞赛"'+Contest.find(ma.contest_id).name+'"的'+ role_str +'的申请被拒绝', contest_path(Contest.find(ma.contest_id)),
|
||||
:class => "#{ma.viewed==0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
|
||||
</li>
|
||||
</div>
|
||||
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -4,7 +4,7 @@ class CreateContestMessages < ActiveRecord::Migration
|
|||
t.references :user
|
||||
t.references :contest
|
||||
t.integer :contest_message_id
|
||||
t.string :course_message_type
|
||||
t.string :contest_message_type
|
||||
t.boolean :viewed, :default => false
|
||||
t.text :content
|
||||
t.integer :status
|
||||
|
|
|
@ -3,7 +3,7 @@ class CreateAppliedContests < ActiveRecord::Migration
|
|||
create_table :applied_contests do |t|
|
||||
t.references :contest
|
||||
t.references :user
|
||||
t.integer :role
|
||||
t.string :role
|
||||
t.integer :status
|
||||
|
||||
t.timestamps
|
||||
|
|
116
db/schema.rb
116
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20161222033007) do
|
||||
ActiveRecord::Schema.define(:version => 20161222063638) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -52,6 +52,18 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token"
|
||||
add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id"
|
||||
|
||||
create_table "applied_contests", :force => true do |t|
|
||||
t.integer "contest_id"
|
||||
t.integer "user_id"
|
||||
t.string "role"
|
||||
t.integer "status"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "applied_contests", ["contest_id"], :name => "index_applied_contests_on_contest_id"
|
||||
add_index "applied_contests", ["user_id"], :name => "index_applied_contests_on_user_id"
|
||||
|
||||
create_table "applied_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "applied_id"
|
||||
|
@ -325,16 +337,14 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids"
|
||||
|
||||
create_table "changesets", :force => true do |t|
|
||||
t.integer "repository_id", :null => false
|
||||
t.string "revision", :null => false
|
||||
t.integer "repository_id", :null => false
|
||||
t.string "revision", :null => false
|
||||
t.string "committer"
|
||||
t.datetime "committed_on", :null => false
|
||||
t.datetime "committed_on", :null => false
|
||||
t.text "comments"
|
||||
t.date "commit_date"
|
||||
t.string "scmid"
|
||||
t.integer "user_id"
|
||||
t.integer "project_id"
|
||||
t.integer "type", :default => 0
|
||||
end
|
||||
|
||||
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on"
|
||||
|
@ -485,12 +495,12 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.integer "user_id"
|
||||
t.integer "contest_id"
|
||||
t.integer "contest_message_id"
|
||||
t.string "course_message_type"
|
||||
t.boolean "viewed", :default => false
|
||||
t.string "contest_message_type"
|
||||
t.boolean "viewed", :default => false
|
||||
t.text "content"
|
||||
t.integer "status"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "contest_messages", ["contest_id"], :name => "index_contest_messages_on_contest_id"
|
||||
|
@ -595,6 +605,20 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.integer "container_id", :default => 0
|
||||
end
|
||||
|
||||
create_table "course_class_post", :id => false, :force => true do |t|
|
||||
t.integer "班级id", :default => 0, :null => false
|
||||
t.string "班级名"
|
||||
t.integer "帖子id", :default => 0, :null => false
|
||||
t.integer "主贴id"
|
||||
t.string "帖子标题", :default => "", :null => false
|
||||
t.text "帖子内容"
|
||||
t.integer "帖子用户id"
|
||||
t.integer "帖子回复数", :default => 0, :null => false
|
||||
t.integer "最后回帖id"
|
||||
t.datetime "发帖时间", :null => false
|
||||
t.datetime "帖子更新时间", :null => false
|
||||
end
|
||||
|
||||
create_table "course_contributor_scores", :force => true do |t|
|
||||
t.integer "course_id"
|
||||
t.integer "user_id"
|
||||
|
@ -663,8 +687,8 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.string "code"
|
||||
t.integer "time"
|
||||
t.string "extra"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "location"
|
||||
t.string "term"
|
||||
t.string "string"
|
||||
|
@ -674,28 +698,27 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.string "class_period"
|
||||
t.integer "school_id"
|
||||
t.text "description"
|
||||
t.integer "status", :default => 1
|
||||
t.integer "attachmenttype", :default => 2
|
||||
t.integer "status", :default => 1
|
||||
t.integer "attachmenttype", :default => 2
|
||||
t.integer "lft"
|
||||
t.integer "rgt"
|
||||
t.integer "is_public", :limit => 1, :default => 1
|
||||
t.integer "inherit_members", :limit => 1, :default => 1
|
||||
t.integer "open_student", :default => 0
|
||||
t.integer "outline", :default => 0
|
||||
t.integer "publish_resource", :default => 0
|
||||
t.integer "is_delete", :default => 0
|
||||
t.integer "is_public", :limit => 1, :default => 1
|
||||
t.integer "inherit_members", :limit => 1, :default => 1
|
||||
t.integer "open_student", :default => 0
|
||||
t.integer "outline", :default => 0
|
||||
t.integer "publish_resource", :default => 0
|
||||
t.integer "is_delete", :default => 0
|
||||
t.integer "end_time"
|
||||
t.string "end_term"
|
||||
t.integer "is_excellent", :default => 0
|
||||
t.integer "excellent_option", :default => 0
|
||||
t.integer "is_copy", :default => 0
|
||||
t.integer "visits", :default => 0
|
||||
t.integer "is_excellent", :default => 0
|
||||
t.integer "excellent_option", :default => 0
|
||||
t.integer "is_copy", :default => 0
|
||||
t.integer "visits", :default => 0
|
||||
t.integer "syllabus_id"
|
||||
t.string "invite_code"
|
||||
t.string "qrcode"
|
||||
t.integer "qrcode_expiretime", :default => 0
|
||||
t.integer "professional_level_id", :limit => 1
|
||||
t.integer "invite_code_halt", :limit => 1, :default => 0
|
||||
t.integer "qrcode_expiretime", :default => 0
|
||||
t.integer "invite_code_halt", :limit => 1, :default => 0
|
||||
end
|
||||
|
||||
add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true
|
||||
|
@ -770,11 +793,6 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
|
||||
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
||||
|
||||
create_table "disciplines", :force => true do |t|
|
||||
t.string "name"
|
||||
t.integer "professional_level_id", :limit => 1
|
||||
end
|
||||
|
||||
create_table "discuss_demos", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
|
@ -900,11 +918,13 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.integer "exercise_status"
|
||||
t.integer "user_id"
|
||||
t.integer "time"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "publish_time"
|
||||
t.datetime "end_time"
|
||||
t.integer "show_result"
|
||||
t.integer "question_random", :default => 0
|
||||
t.integer "choice_random", :default => 0
|
||||
end
|
||||
|
||||
create_table "first_pages", :force => true do |t|
|
||||
|
@ -1093,10 +1113,6 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "innodb_monitor", :id => false, :force => true do |t|
|
||||
t.integer "a"
|
||||
end
|
||||
|
||||
create_table "invite_lists", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.integer "user_id"
|
||||
|
@ -1628,12 +1644,9 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
end
|
||||
|
||||
create_table "professional_levels", :force => true do |t|
|
||||
t.integer "level"
|
||||
end
|
||||
|
||||
create_table "professions", :force => true do |t|
|
||||
t.string "name"
|
||||
t.integer "discipline_id", :limit => 1
|
||||
t.string "level"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "project_infos", :force => true do |t|
|
||||
|
@ -1696,6 +1709,7 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.boolean "hidden_repo", :default => false, :null => false
|
||||
t.integer "attachmenttype", :default => 1
|
||||
t.integer "user_id"
|
||||
t.integer "dts_test", :default => 0
|
||||
t.string "enterprise_name"
|
||||
t.integer "organization_id"
|
||||
t.integer "project_new_type"
|
||||
|
@ -1703,11 +1717,6 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.integer "forked_from_project_id"
|
||||
t.integer "forked_count"
|
||||
t.integer "publish_resource", :default => 0
|
||||
t.integer "boards_count", :default => 0
|
||||
t.integer "news_count", :default => 0
|
||||
t.integer "acts_count", :default => 0
|
||||
t.integer "journals_count", :default => 0
|
||||
t.integer "boards_reply_count", :default => 0
|
||||
t.integer "visits", :default => 0
|
||||
t.integer "hot", :default => 0
|
||||
t.string "invite_code"
|
||||
|
@ -2105,8 +2114,8 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.string "title"
|
||||
t.text "description"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "eng_name"
|
||||
t.integer "syllabus_type"
|
||||
t.integer "credit"
|
||||
|
@ -2115,9 +2124,8 @@ ActiveRecord::Schema.define(:version => 20161222033007) do
|
|||
t.integer "practice_hours"
|
||||
t.string "applicable_major"
|
||||
t.string "pre_course"
|
||||
t.integer "visits", :default => 0
|
||||
t.integer "des_status", :default => 0
|
||||
t.integer "professional_level_id", :limit => 1
|
||||
t.integer "visits", :default => 0
|
||||
t.integer "des_status", :default => 0
|
||||
end
|
||||
|
||||
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"
|
||||
|
|
Loading…
Reference in New Issue