From 8e2288a362824a6ce38a6ac7c98fbd8116139fed Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Thu, 5 Jun 2014 15:57:40 +0800
Subject: [PATCH] =?UTF-8?q?1.=E5=B0=81=E8=A3=85=E8=8E=B7=E5=8F=96=E4=BD=9C?=
=?UTF-8?q?=E4=B8=9A=E5=B9=B3=E5=9D=87=E8=AF=84=E5=88=86=E6=96=B9=E6=B3=95?=
=?UTF-8?q?=202.=E4=BC=98=E5=8C=96=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E7=95=8C=E9=9D=A2=E6=95=88=E7=8E=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/bids_controller.rb | 2 +-
app/helpers/courses_helper.rb | 11 +++++++++++
app/views/bids/_homework_list.html.erb | 19 ++-----------------
app/views/layouts/base_homework.html.erb | 16 ++++++++--------
4 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index c0df0699c..923225606 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -412,7 +412,7 @@ class BidsController < ApplicationController
#增加作业按评分排序,
@homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id) AS score
- FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC")
+ FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC",:include => [:attachments])
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index fb0a269e6..326ea8739 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -168,4 +168,15 @@ module CoursesHelper
seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count
seem_count > 0
end
+
+ #获取指定作业的平均评分
+ def homework_score homework
+ stars_reates = homework.rates(:quality)
+ sum = 0
+ stars_reates.each do |star_reates|
+ sum = sum + star_reates.stars
+ end
+ stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
+ format("%.2f", sum * 1.0 / stars_reates_count)
+ end
end
diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb
index 48f1c150d..a7d65ea43 100644
--- a/app/views/bids/_homework_list.html.erb
+++ b/app/views/bids/_homework_list.html.erb
@@ -43,14 +43,6 @@
<% else %>
<% homework_filename = attachment.filename %>
<% end %>
-
<% end %>
<% else %>
<% homework_filename = homework.name %>
@@ -83,13 +75,7 @@
作业评分:
- <% stars_reates = homework.rates(:quality) %>
- <% sum = 0 %>
- <% stars_reates.each do |star_reates| %>
- <% sum = sum + star_reates.stars %>
- <% end %>
- <% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %>
- <%= format("%.2f", sum * 1.0 / stars_reates_count) %>
+ <%= homework_score homework %>
|
<% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %>
@@ -104,8 +90,7 @@
<% end %>
|
- <% if (User.current == homework.user) || (!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 =?',3,7, 9)).size >0) %>
+ <% if (User.current == homework.user) || is_teacher %>
<%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
<%= link_to(l(:label_bid_respond_delete), homework,
method: :delete, :confirm => l(:text_are_you_sure)) %>
diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb
index 81a8b0861..62c7d482d 100644
--- a/app/views/layouts/base_homework.html.erb
+++ b/app/views/layouts/base_homework.html.erb
@@ -22,27 +22,27 @@
<% course = Course.find_by_extra(project.identifier) %>
-
- <%= render :partial => 'layouts/base_header'%>
+
+ <%= render :partial => 'layouts/base_header'%>
-
+
高校课程实践社区 |
<%= l(:label_user_location) %> : |
-
+
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%> |
- <%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> >
- <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> >
+ | <%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> >
+ <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> >
<%=link_to(@bid.name, respond_path(@bid)) %> |
-
+
-
+
|