发送消息
This commit is contained in:
parent
adb246f9ad
commit
6553559929
|
@ -316,6 +316,9 @@ class ExerciseController < ApplicationController
|
||||||
@exercise.exercise_status = 2
|
@exercise.exercise_status = 2
|
||||||
@exercise.publish_time = Time.now
|
@exercise.publish_time = Time.now
|
||||||
if @exercise.save
|
if @exercise.save
|
||||||
|
@exercise.course.members.each do |m|
|
||||||
|
@exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2)
|
||||||
|
end
|
||||||
#redirect_to exercise_index_url(:course_id=> @course.id)
|
#redirect_to exercise_index_url(:course_id=> @course.id)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
|
@ -331,6 +334,7 @@ class ExerciseController < ApplicationController
|
||||||
@exercise.exercise_questions.each do |exercise_question|
|
@exercise.exercise_questions.each do |exercise_question|
|
||||||
exercise_question.exercise_answers.destroy_all
|
exercise_question.exercise_answers.destroy_all
|
||||||
end
|
end
|
||||||
|
@exercise.course_messages.destroy_all
|
||||||
@exercise.exercise_users.destroy_all
|
@exercise.exercise_users.destroy_all
|
||||||
@exercise.exercise_status = 1
|
@exercise.exercise_status = 1
|
||||||
@exercise.publish_time = nil
|
@exercise.publish_time = nil
|
||||||
|
|
|
@ -92,7 +92,7 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# 用户消息
|
# 用户消息
|
||||||
# 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复
|
# 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验
|
||||||
# issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment)
|
# issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment)
|
||||||
def user_messages
|
def user_messages
|
||||||
if !User.current.logged?
|
if !User.current.logged?
|
||||||
|
@ -128,7 +128,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
#课程相关消息
|
#课程相关消息
|
||||||
when 'homework'
|
when 'homework'
|
||||||
@message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') 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).order("created_at desc")
|
||||||
when 'course_message'
|
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).order("created_at desc")
|
||||||
when 'course_news'
|
when 'course_news'
|
||||||
|
|
|
@ -6,4 +6,18 @@ class Exercise < ActiveRecord::Base
|
||||||
has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number"
|
has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number"
|
||||||
has_many :exercise_users, :dependent => :destroy
|
has_many :exercise_users, :dependent => :destroy
|
||||||
has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过
|
has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过
|
||||||
|
# 课程消息
|
||||||
|
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||||
|
after_create :acts_as_course_message
|
||||||
|
def acts_as_course_message
|
||||||
|
if self.course
|
||||||
|
if self.exercise_status == 2 #未发布
|
||||||
|
#self.course.members.each do |m|
|
||||||
|
self.course_messages << CourseMessage.create(:user_id => User.current.id, :course_id => self.course_id, :viewed => false,:status=>2)
|
||||||
|
#end
|
||||||
|
# else
|
||||||
|
# self.course_messages.destroy_all 这里的destory_all值得商榷。因为我这里是通过status来控制不同的status的
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -612,4 +612,74 @@
|
||||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<!--老师发布测验 发给学生看-->
|
||||||
|
<% if ma.course_message_type == "Exercise" && 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">
|
||||||
|
<span><%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师",
|
||||||
|
user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %></span><span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布了课程测验 :</span></li>
|
||||||
|
<li class="homepageNewsContent fl">
|
||||||
|
<%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => 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">
|
||||||
|
<p>
|
||||||
|
<%= User.current.lastname + User.current.firstname %><%= User.current.allowed_to?(:as_teacher,ma.course_message.course) ? '老师':'同学'%>您好!
|
||||||
|
<%= User.current.eql?(ma.course_message.user)?"您":(ma.course_message.user.lastname + ma.course_message.user.firstname+"老师") %>发布了课程测验 ,测验详情如下:
|
||||||
|
</p>
|
||||||
|
<ul class="ul_normal_color">
|
||||||
|
<li>课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.time.to_s + '年'+ ma.course_message.course.term %>)</li>
|
||||||
|
<li>测验标题:<%= ma.course_message.exercise_name %></li>
|
||||||
|
<!--<li>测验描述:<%#= ma.course_message.exercise_description %></li>-->
|
||||||
|
<!--<li>测验状态:<%#= ma.course_message.exercise_status == 1 ? '未发布':'已发布'%></li>-->
|
||||||
|
<!--<%# if ma.course_message.publish_time %>-->
|
||||||
|
<!--<li>发布时间:<%#= ma.course_message.publish_time.to_s.gsub("+0800","").to_datetime.strftime("%Y-%m-%d %H:%M:%S") %></li>-->
|
||||||
|
<!--<%# end %>-->
|
||||||
|
<li>截止时间:<%= ma.course_message.end_time.to_s.gsub("+0800","").to_datetime.strftime("%Y-%m-%d %H:%M:%S") %></li>
|
||||||
|
<li>答题时间:<%= ma.course_message.time == 0 ? '不限时' : ma.course_message.time.to_s + '分钟' %></li>
|
||||||
|
<% if !User.current.allowed_to?(:as_teacher,ma.course_message.course)%>
|
||||||
|
<p>请记得在截止时间前完成测验噢,辛苦啦!</p>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
|
<% if ma.course_message_type == "Exercise" && 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">
|
||||||
|
<span> <%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师",
|
||||||
|
user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %></span><span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布的测验:</span></li>
|
||||||
|
<li class="homepageHomeworkContent fl">
|
||||||
|
<%= link_to "测验题目:" + ma.course_message.exercise_name, exercise_path(:id => 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">
|
||||||
|
<p>
|
||||||
|
<%= User.current.lastname + User.current.firstname %><%= User.current.allowed_to?(:as_teacher,ma.course_message.course) ? '老师':'同学'%>您好!
|
||||||
|
<%= User.current.eql?(ma.course_message.user)?"您":(ma.course_message.user.lastname + ma.course_message.user.firstname+"老师") %>发布的课程测验截止时间快到了,测验详情如下:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul class="ul_normal_color">
|
||||||
|
<li>课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.time.to_s + '年'+ ma.course_message.course.term %>)</li>
|
||||||
|
<li>测验标题:<%= ma.course_message.exercise_name %></li>
|
||||||
|
<li>截止时间:<%= ma.course_message.end_time.to_s.gsub("+0800","").to_datetime.strftime("%Y-%m-%d %H:%M:%S") %></li>
|
||||||
|
<li>答题时间:<%= ma.course_message.time == 0 ? '无限制' : ma.course_message.time.to_s + '分钟' %></li>
|
||||||
|
<p>请及时完成课程测验,辛苦啦!</p>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<li class="homepageHomeworkContentWarn fl">截止时间快到啦 </li>
|
||||||
|
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -0,0 +1,22 @@
|
||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
namespace :exercise_deadline_warn do
|
||||||
|
desc "exercise deadline warn"
|
||||||
|
task :deadline_warn => :environment do
|
||||||
|
exercises = Exercise.where("date_format(end_time,'%Y-%m-%d')= '#{Date.today}'") #截止日期都是当天 23.59分,所以年月日相等的一定是今晚会截止的测验
|
||||||
|
exercises.each do |exercise|
|
||||||
|
if exercise.exercise_status == 2 #发布的作业才能告给学生发截止消息
|
||||||
|
course = exercise.course
|
||||||
|
course.members.each do |m|
|
||||||
|
#CourseMessage status 1 未发布 status 2 已发布 status 3 已发布快截止了
|
||||||
|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) unless m.user.allowed_to?(:as_teacher,m)
|
||||||
|
end
|
||||||
|
# if homework.course_acts.size == 0
|
||||||
|
# homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
|
||||||
|
# end
|
||||||
|
# 邮件通知
|
||||||
|
#Mailer.run.homework_added(homework)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
namespace :exercise_publishtime do
|
||||||
|
desc "start publish exercise"
|
||||||
|
task :publish => :environment do
|
||||||
|
exercises = Exercise.where("date_format(publish_time,'%Y-%m-%d')= '#{Date.today}'")
|
||||||
|
exercises.each do |exercise|
|
||||||
|
if exercise.exercise_status == 1 #未发布
|
||||||
|
exercise.update_column('exercise_status', 2) #改为发布
|
||||||
|
course = exercise.course
|
||||||
|
course.members.each do |m|
|
||||||
|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
|
||||||
|
end
|
||||||
|
# if homework.course_acts.size == 0
|
||||||
|
# homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
|
||||||
|
# end
|
||||||
|
# 邮件通知
|
||||||
|
#Mailer.run.homework_added(homework)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue