2015-02-04 11:57:37 +08:00
|
|
|
|
class CommentService
|
2015-03-19 14:41:31 +08:00
|
|
|
|
include ApiHelper
|
|
|
|
|
include Redmine::I18n
|
2015-02-04 11:57:37 +08:00
|
|
|
|
#评论
|
|
|
|
|
def news_comments params,current_user
|
|
|
|
|
@news = News.find(params[:id])
|
2015-02-04 14:39:46 +08:00
|
|
|
|
@course = @news.course
|
|
|
|
|
if @course.nil?
|
|
|
|
|
raise 'news in unknown course'
|
|
|
|
|
end
|
|
|
|
|
raise Unauthorized unless @news.commentable?(current_user)
|
|
|
|
|
if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course)))
|
|
|
|
|
raise '403'
|
|
|
|
|
end
|
2015-02-04 11:57:37 +08:00
|
|
|
|
@comment = Comment.new
|
2015-02-04 14:39:46 +08:00
|
|
|
|
@comment.send(:safe_attributes=,params[:comment],current_user)
|
2015-02-04 11:57:37 +08:00
|
|
|
|
@comment.author = current_user
|
|
|
|
|
@news.comments << @comment
|
|
|
|
|
@comment
|
|
|
|
|
end
|
2015-02-05 15:54:50 +08:00
|
|
|
|
|
|
|
|
|
#作业留言
|
|
|
|
|
def homework_message params,current_user
|
|
|
|
|
@bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
|
|
|
|
|
if params[:bid_message][:message].size>0
|
|
|
|
|
if params[:reference_content]
|
|
|
|
|
message = params[:bid_message][:message] + "\n" + params[:reference_content]
|
|
|
|
|
else
|
|
|
|
|
message = params[:bid_message][:message]
|
|
|
|
|
@m = message
|
|
|
|
|
end
|
|
|
|
|
refer_user_id = params[:bid_message][:reference_user_id].to_i
|
2015-02-05 16:11:35 +08:00
|
|
|
|
jfm = @bid.add_jour(current_user, message, refer_user_id)
|
2015-02-05 15:54:50 +08:00
|
|
|
|
end
|
|
|
|
|
#@user = @bid.author
|
|
|
|
|
#@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
|
|
|
|
#@jour = paginateHelper @jours,10
|
|
|
|
|
@bid.set_commit(@feedback_count)
|
2015-02-05 16:11:35 +08:00
|
|
|
|
jfm
|
2015-02-05 15:54:50 +08:00
|
|
|
|
end
|
2015-02-06 10:35:38 +08:00
|
|
|
|
#课程留言接口
|
|
|
|
|
def leave_course_message params,current_user
|
|
|
|
|
message = params[:new_form][:course_message]
|
|
|
|
|
feedback = Course.add_new_jour(current_user, message, params[:id])
|
|
|
|
|
feedback
|
|
|
|
|
end
|
2015-02-05 15:54:50 +08:00
|
|
|
|
|
2015-02-05 17:32:19 +08:00
|
|
|
|
#回复留言接口
|
|
|
|
|
def create_reply params,current_user
|
|
|
|
|
# 这里是创建回复所使用的方法,此方法只针对回复,每一个新的留言并不在此方法管理范围内。
|
|
|
|
|
# 由于多个地方用到了留言,而之前的表设计也有jour_type/jour_id这类信息
|
|
|
|
|
# 所以在方法 add_reply_adapter 中判断所有调用此方法的来源页面,
|
|
|
|
|
# 为了保证兼容以往所有的代码,保证以往的方法可以调用,在返回页面中都做了各式各样的判断。
|
|
|
|
|
# 页面保证 render new_respond/journal_reply
|
|
|
|
|
# 修改 add_reply_adapter 中可以确保留言创建成功
|
|
|
|
|
# 删除留言功能要调用destroy,也记得在destroy.js中修改
|
|
|
|
|
|
|
|
|
|
# deny api. api useless
|
|
|
|
|
parent_id = params[:reference_id]
|
|
|
|
|
author_id = current_user.id
|
|
|
|
|
reply_user_id = params[:reference_user_id]
|
|
|
|
|
reply_id = params[:reference_message_id] # 暂时不实现
|
|
|
|
|
content = params[:user_notes]
|
|
|
|
|
jour_type = params[:jour_type]
|
|
|
|
|
jour_id = params[:jour_id]
|
|
|
|
|
@show_name = params[:show_name] == "true"
|
|
|
|
|
options = {
|
|
|
|
|
:jour_id => jour_id,
|
|
|
|
|
:jour_type => jour_type,
|
|
|
|
|
:user_id => author_id,
|
|
|
|
|
:status => true,
|
|
|
|
|
:m_parent_id => parent_id,
|
|
|
|
|
:m_reply_id => reply_id,
|
|
|
|
|
:reply_id => reply_user_id,
|
|
|
|
|
:notes => content,
|
|
|
|
|
:is_readed => false}
|
|
|
|
|
@jfm = ::JournalsForMessage.new(options)
|
|
|
|
|
#@save_succ = true if @jfm.errors.empty?
|
|
|
|
|
@jfm.save
|
|
|
|
|
@jfm
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-05 10:09:19 +08:00
|
|
|
|
#发贴,用于意见反馈
|
|
|
|
|
def create_feedback params,current_user
|
|
|
|
|
@memo = Memo.new(params[:memo])
|
|
|
|
|
@memo.forum_id = "1"
|
|
|
|
|
@memo.author_id = current_user.id
|
|
|
|
|
@memo.save
|
2015-03-19 14:41:31 +08:00
|
|
|
|
message = "#{l(:label_commit_failed,:locale => get_user_language(current_user))}: #{@memo.errors.full_messages}" if @memo.new_record?
|
|
|
|
|
[@memo,message]
|
2015-03-05 10:09:19 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-03-07 16:19:55 +08:00
|
|
|
|
#课程留言列表
|
|
|
|
|
def course_messages params,current_user
|
|
|
|
|
@course = ::Course.find(params[:id])
|
|
|
|
|
if (current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course)))
|
2015-05-29 14:22:43 +08:00
|
|
|
|
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC').page(params[:page] ||= 1).per(10)
|
2015-03-07 16:19:55 +08:00
|
|
|
|
else
|
|
|
|
|
raise '403'
|
|
|
|
|
end
|
|
|
|
|
@jours
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-28 17:51:50 +08:00
|
|
|
|
def comment_detail params,current_user
|
|
|
|
|
if !params[:course_id].nil? && params[:course_id] != 0
|
|
|
|
|
course = Course.find(params[:course_id])
|
|
|
|
|
jour = course.journals_for_messages.where("id = ? ",params[:comment_parent_id])
|
|
|
|
|
jour
|
|
|
|
|
else
|
|
|
|
|
jour1 = JournalsForMessage.where("id = ? ",params[:comment_parent_id])
|
|
|
|
|
jour1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-04 11:57:37 +08:00
|
|
|
|
end
|