竞赛者加入,无需身份验证,发送消息通知给竞赛所有管理员即可

This commit is contained in:
cxt 2017-03-13 10:22:55 +08:00
parent b318c460d9
commit 77c25db233
3 changed files with 57 additions and 14 deletions

View File

@ -24,6 +24,21 @@ class ContestsService
if params[:invite_code].present?
role_ids = params[:role]
if role_ids.include?("15")
member = ContestMember.new(:user_id => current_user.id)
contest.contest_members << member
contest_member_roles = member.contest_member_roles
contest_member_roles << ContestMemberRole.new(:role_id => 15)
ContestantForContest.create(:student_id => current_user.id, :contest_id => contest.id)
# 给管理员发消息
admins = contest_managers contest
admins.each do |member|
course_join = ContestMessage.new(:user_id =>member.user_id, :contest_message_id=>current_user.id,:contest_id => contest.id,:contest_message_type=>"JoinContest", :content => role_ids, :viewed => false, :status => 2)
course_join.save
end
@state = 0
else
#如果已经发送过消息了,那么就要给个提示
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0
@state = 7
@ -37,6 +52,7 @@ class ContestsService
end
@state = 6
end
end
else
@state = 1
end

View File

@ -139,7 +139,10 @@
<li><a href="<%=contest_path(ma.contest) %>" target="_blank" title="<%=User.find(ma.contest_message_id).show_name %> 将您加入了竞赛:<%= ma.contest.name%>"><span class="shadowbox_news_user"><%=User.find(ma.contest_message_id).show_name %> </span>将您加入了竞赛:<%= ma.contest.name%></a></li>
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %>
<li><a href="<%=settings_contest_path(ma.contest_id, :tab=>'member') %>" target="_blank" title="系统提示 您增加了新的竞赛成员:<%= User.find(ma.contest_message_id).login+"("+User.find(ma.contest_message_id).show_name+")"%>"><span class="shadowbox_news_user">系统提示 </span>您增加了新的竞赛成员:<%= User.find(ma.contest_message_id).login+"("+User.find(ma.contest_message_id).show_name+")"%></a></li>
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %>
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 2 %>
<% user = User.find(ma.contest_message_id) %>
<li><a href="<%=contest_path(ma.contest) %>" target="_blank" title="<%=user.show_name %> <%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? '' : '来自'+user.user_extensions.school.name+'' %>以'参赛者'的身份加入了竞赛:<%= ma.contest.name%>"><span class="shadowbox_news_user"><%=user.show_name %> </span><%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? '' : '来自'+user.user_extensions.school.name+'' %>以'参赛者'的身份加入了竞赛:<%= ma.contest.name%></a></li>
<% elsif ma.contest_message_type == "RemoveFromContest" %>
<li><a href="<%=contest_path(ma.contest) %>" target="_blank" title="<%=User.find(ma.contest_message_id).show_name %> 将您移出了竞赛:<%= ma.contest.name%>"><span class="shadowbox_news_user"><%=User.find(ma.contest_message_id).show_name %> </span>将您移出了竞赛:<%= ma.contest.name%></a></li>
<% end %>
<% elsif ma.class == AppliedMessage %>

View File

@ -46,7 +46,7 @@
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<!--被管理员拉入竞赛-->
<!--被管理员拉入竞赛:学生身份-->
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 0 %>
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
@ -64,7 +64,7 @@
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<!--被管理员拉入竞赛-->
<!--被管理员拉入竞赛:老师身份-->
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %>
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
@ -85,6 +85,30 @@
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<!--主动加入竞赛-->
<% elsif ma.contest_message_type == "JoinContest" and ma.status == 2 %>
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
<li class="homepageNewsPortrait fl">
<div class="navHomepageLogo fl"><%= image_tag("/images/trustie_logo1.png", width: "30px", height: "30px", class: "mt3") %></div>
</li>
<li class="homepageNewsPubType fl">
<% user = User.find(ma.contest_message_id) %>
<span class="newsBlue homepageNewsPublisher">
<%=link_to user.show_name, user_path(user),
:class => "newsBlue homepageNewsPublisher", :target => '_blank' %></span>
<span class="homepageNewsType fl">
<%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? "" : "来自"+user.user_extensions.school.name+"" %>
以"参赛者"的身份加入了竞赛:
</span>
</li>
<li class="messageInformationContents">
<%= link_to ma.contest.name, contest_path(ma.contest), :class => "#{!ma.viewed ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
</li>
</div>
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<!--被老师移出课程-->
<% elsif ma.contest_message_type == "RemoveFromContest" %>
<ul class="homepageNewsList fl">