开启/关闭匿评邮件通知

This commit is contained in:
huang 2015-09-19 10:54:50 +08:00
parent 32f90ea591
commit 961b2bd564
6 changed files with 80 additions and 18 deletions

View File

@ -206,7 +206,8 @@ class HomeworkCommonController < ApplicationController
end
@homework_detail_manual.update_column('comment_status', 2)
@statue = 1
send_message_anonymous_comment(@homework, open=true)
# 匿评开启消息邮件通知
send_message_anonymous_comment(@homework, m_status = 2)
Mailer.send_mail_anonymous_comment_open(@homework).deliver
else
@statue = 2
@ -226,7 +227,8 @@ class HomeworkCommonController < ApplicationController
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0
student_work.save
end
send_message_anonymous_comment(@homework, open = false)
# 匿评关闭消息邮件通知
send_message_anonymous_comment(@homework, m_status = 3)
Mailer.send_mail_anonymous_comment_close(@homework).deliver
respond_to do |format|
format.js
@ -234,11 +236,11 @@ class HomeworkCommonController < ApplicationController
end
# 开启/关闭匿评消息通知
def send_message_anonymous_comment(homework, open)
def send_message_anonymous_comment(homework, m_status )
# status 标记匿评状态 1为关闭 0为开启
course = @homework.course
course.student.each do |st|
@homework.course_messages << CourseMessage.new(:user_id => st.user_id, :course_id => course.id, :viewed => false, :status => open ? true : false)
@homework.course_messages << CourseMessage.new(:user_id => st.student_id, :course_id => course.id, :viewed => false, :status => m_status)
end
end
#提示

View File

@ -50,35 +50,37 @@ class Mailer < ActionMailer::Base
# 作业匿评开启
def send_mail_anonymous_comment_open(homework_common)
course = homework_common.course
recipients ||= []
course.student.each do |student|
user = student.user
user = User.find(student.student_id)
@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}"
@token = Token.get_token_from_user(user, 'autologin')
@anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@anonymous_comment_close_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipient = user.mail
mail :to => recipient,
:subject => @subject
recipients << user.mail
end
mail :to => recipients,
:subject => @subject
end
# 作业匿评关闭
def send_mail_anonymous_comment_close(homework_common)
course = homework_common.course
recipients ||= []
course.student.each do |student|
user = student.user
user = User.find(student.student_id)
@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}"
@token = Token.get_token_from_user(user, 'autologin')
@anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@anonymous_comment_close_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipient = user.mail
mail :to => recipient,
:subject => @subject
recipients << user.mail
end
mail :to => recipients,
:subject => @subject
end
# author: alan

View File

@ -2,7 +2,7 @@
<ul style="list-style-type:none; margin:0; padding:0;">
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_content)%></strong></span>
<span style="float: left; width: 526px">
<p><%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @homework_endtime_name, @homework_endtime_url%> <span style="color: red; padding-left: 10px;">已经关闭了匿评!</span></p>
<p><%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> <span style="color: red; padding-left: 10px;">已经关闭了匿评!</span></p>
</span>
</li>
</ul>

View File

@ -2,7 +2,7 @@
<ul style="list-style-type:none; margin:0; padding:0;">
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_content)%></strong></span>
<span style="float: left; width: 526px">
<p><%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @homework_endtime_name, @homework_endtime_url%> <span style="color: red; padding-left: 10px;">已经开启匿评了!</span></p>
<p><%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> <span style="color: red; padding-left: 10px;">已经开启匿评了!</span></p>
</span>
</li>
</ul>

View File

@ -109,7 +109,7 @@
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<% if ma.course_message_type == "HomeworkCommon" && ma.status != 1 %>
<% if ma.course_message_type == "HomeworkCommon" && ma.status.nil? %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %></a></li>
<li class="homepageNewsPubType fl"><%=link_to ma.course_message.user, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %><span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布了作业:</span></li>
@ -152,6 +152,65 @@
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<!--作品开启匿评 待整合:时间紧-->
<% if ma.course_message_type == "HomeworkCommon" && ma.status == 2 %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %></a></li>
<li class="homepageNewsPubType fl"><%=link_to ma.course_message.user, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %><span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布的作业:</span></li>
<% if ma.viewed == 0 %>
<li class="homepageHomeworkContent fl">
<%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
</li>
<div style="display: none" class="message_title_red system_message_style">
<%= ma.course_message.name %>
</div>
<li class="homepageHomeworkContentWarn fl"> &nbsp;&nbsp; 开启匿评了!</li>
<% else %>
<li class="homepageNewsContent fl">
<%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))"%>
</li>
<div style="display: none" class="message_title_red system_message_style">
<%= ma.course_message.name %>
</div>
<% end %>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<!--作品关闭匿评-->
<% if ma.course_message_type == "HomeworkCommon" && ma.status == 3 %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %></a></li>
<li class="homepageNewsPubType fl"><%=link_to ma.course_message.user, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %><span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布的作业:</span></li>
<% if ma.viewed == 0 %>
<li class="homepageHomeworkContent fl">
<%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
</li>
<div style="display: none" class="message_title_red system_message_style">
<%= ma.course_message.name %>
</div>
<li class="homepageHomeworkContentWarn fl"> &nbsp;&nbsp; 匿评已经关闭!</li>
<% else %>
<li class="homepageNewsContent fl">
<%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))"%>
</li>
<div style="display: none" class="message_title_red system_message_style">
<%= ma.course_message.name %>
</div>
<% end %>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<% if ma.course_message_type == "Poll" %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %></a></li>

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150918135051) do
ActiveRecord::Schema.define(:version => 20150918134804) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -576,7 +576,6 @@ ActiveRecord::Schema.define(:version => 20150918135051) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "secret_key"
t.string "code"
end
create_table "forums", :force => true do |t|
@ -1331,7 +1330,7 @@ ActiveRecord::Schema.define(:version => 20150918135051) do
t.datetime "updated_at", :null => false
t.integer "late_penalty", :default => 0
t.integer "absence_penalty", :default => 0
t.float "system_score", :default => 0.0
t.integer "system_score"
t.boolean "is_test", :default => false
end