socialforge/app/controllers/homework_attach_controller.rb

179 lines
5.8 KiB
Ruby
Raw Normal View History

2014-05-16 11:02:25 +08:00
class HomeworkAttachController < ApplicationController
###############################
def index
@homeworks = HomeworkAttach.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @homeworks }
end
end
2014-05-21 14:10:11 +08:00
def add_users users
if users != nil && users.count > 0
users.each do |user|
@homework.homework_users.build(:user_id => user.id)
@homework.save
end
end
end
def create
2014-05-21 14:10:11 +08:00
if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
user_id = params[:user_id]
bid_id = params[:bid_id]
sta = 0
name = params[:new_form][:name]
description = params[:new_form][:description]
options = {
:user_id => user_id,
:state => sta,
:name => name,
:description => description,
:bid_id => bid_id
}
2014-05-21 14:10:11 +08:00
@homework = HomeworkAttach.new(options)
@homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework)
@homework.save
respond_to do |format|
if @homework.save
format.html { redirect_to @homework, notice: 'Post was successfully created.' }
format.json { render json: @homework, status: :created, location: @homework }
else
format.html { render action: "new" }
format.json { render json: @homework.errors, status: :unprocessable_entity }
end
end
end
end
def new
@homework = HomeworkAttach.new
2014-05-21 14:10:11 +08:00
@bid = Bid.find(params[:id])
respond_to do |format|
format.html # new.html.erb
format.json { render json: @homework }
end
end
def edit
@homework = HomeworkAttach.find(params[:id])
end
def update
@homework = HomeworkAttach.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:homework])
format.html { redirect_to @homework, notice: 'Homework was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @homework.errors, status: :unprocessable_entity }
end
end
end
def destroy
2014-05-21 14:10:11 +08:00
@homework = HomeworkAttach.find(params([:id]))
@homework.destroy
respond_to do |format|
format.html {render @homework}
format.json {render json: @homework}
end
end
2014-05-16 11:02:25 +08:00
#显示作业信息
def show
@homework = HomeworkAttach.find(params[:id])
# 打分统计
stars_reates = @homework.
rates(:quality)
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
stars_status = stars_reates.select("stars, count(*) as scount").
group("stars")
@stars_status_map = Hash.new(0.0)
stars_status.each do |star_status|
percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f
percent_m = format("%.2f", percent)
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
percent_m.to_s + "%"
end
@limit = 10
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
2014-05-16 11:02:25 +08:00
end
#删除留言
def destroy_jour
@journal_destroyed = JournalsForMessage.delete_message(params[:object_id])
#@homework = HomeworkAttach.find(params[:id])
#@jours = @homework.journals_for_messages.order("created_on DESC")
#@limit = 10
#@feedback_count = @jours.count
#@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
#@offset ||= @feedback_pages.offset
#@jour = @jours[@offset, @limit]
respond_to do |format|
format.js
end
end
#添加留言
def addjours
@homework = HomeworkAttach.find(params[:jour_id])
@add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
2014-05-22 20:01:26 +08:00
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
respond_to do |format|
format.js
end
2014-05-16 11:02:25 +08:00
end
#获取指定作业的平均得分
def score
#stars_reates = @homework.rates(:quality)
#percent = 0
#stars_reates.each do |star_reates|
# percent = percent + star_reates.stars
#end
#stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
#result = percent * 1.0 / stars_reates_count
#result
end
#添加回复
def add_jour_reply
parent_id = params[:reference_id]
author_id = User.current.id
reply_user_id = params[:reference_user_id]
reply_id = params[:reference_message_id] # 暂时不实现
content = params[:user_notes]
options = {:user_id => author_id,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
@jfm = JournalsForMessage.new(options)
@jfm.save
respond_to do |format|
format.js{
@save_succ = true if @jfm.errors.empty?
}
end
end
2014-05-16 11:02:25 +08:00
end