From acc3f6dadf38cc18a28fc05abb39bf35cf282046 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 2 Jul 2015 16:04:26 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=BF=9F=E4=BA=A4=E6=89=A3=E5=88=86=E3=80=81?= =?UTF-8?q?=E7=BC=BA=E8=AF=84=E6=89=A3=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_common_helper.rb | 2 +- app/views/homework_common/_homework_common_form.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/homework_common_helper.rb b/app/helpers/homework_common_helper.rb index b9940f4be..465df62da 100644 --- a/app/helpers/homework_common_helper.rb +++ b/app/helpers/homework_common_helper.rb @@ -15,7 +15,7 @@ module HomeworkCommonHelper #教辅评分比例下拉框 def ta_proportion_option type = [] - i = 10 + i = 0 while i <= 100 option = [] option << i.to_s + "%" diff --git a/app/views/homework_common/_homework_common_form.html.erb b/app/views/homework_common/_homework_common_form.html.erb index fa45397f0..21ed8900c 100644 --- a/app/views/homework_common/_homework_common_form.html.erb +++ b/app/views/homework_common/_homework_common_form.html.erb @@ -47,7 +47,7 @@
基本规则设置(总分为100分)
学生漏评1个作品将扣 2 分
+学生漏评1个作品将扣 <%= homework.homework_detail_manual.absence_penalty%> 分
From 981ad6e743d0b086d576f4934a25a044a166ab29 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 3 Jul 2015 11:49:02 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E7=BC=BA=E8=AF=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 954ab733f..596d5ba51 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -257,7 +257,7 @@ class StudentWorkController < ApplicationController work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" @stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM( SELECT * , - (SELECT evaluation_num FROM homework_detail_manuals WHERE homework_detail_manuals.homework_common_id = #{@homework.id}) AS all_count, + (SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count, (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count FROM `student_works` WHERE homework_common_id = #{@homework.id} From fe55258349e6cdee4c906e16b604ea203da34a7f Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 3 Jul 2015 12:22:33 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8C=BF=E8=AF=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E8=A7=A3=E9=87=8A=20api=20=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E5=8C=BF=E8=AF=84=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 13 ++++++++ app/api/mobile/entities/homework.rb | 5 ++- app/helpers/api_helper.rb | 30 +++++++++++++++++- app/services/courses_service.rb | 47 ++++++++++++++++++++++++++--- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 0d34cecaf..3d05ab3f3 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -336,6 +336,19 @@ module Mobile student_works = cs.student_work_list params,current_user present :data,student_works.all,with:Mobile::Entities::StudentWork end + + desc '开启匿评' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + requires :homework_id,type:Integer,desc:'作业id' + end + get ':course_id/start_anonymous_comment' do + cs = CoursesService.new + status = cs.start_anonymous_comment params,current_user + present :data,status + present :status,0 + end end end end diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index 2ea9404b8..e78689bfb 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -28,6 +28,8 @@ module Mobile get_homework_status f when :homework_times f.course.homework_commons.index(f) + 1 + when :homework_status_desc + homework_status_desc f end end end @@ -80,7 +82,8 @@ module Mobile expose :submit_student_list ,using: Mobile::Entities::User do |f,opt| get_submit_sutdent_list f end - homework_expose :homework_status + homework_expose :homework_status #作业的状态 + homework_expose :homework_status_desc #状态的解释 end end diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 916383b05..6c17f8566 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -89,6 +89,29 @@ module ApiHelper homework_status end + #获取作业的是否可以匿评的描述 + def homework_status_desc homework + if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业 + if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + link = "启动匿评".html_safe + elsif homework.student_works.count >= 2 #作业份数大于2 + case homework.homework_detail_manual.comment_status + when 1 + link = '启动匿评' + when 2 + link = '关闭匿评' + when 3 + link = " 匿评结束" + end + else + link = "学生提交作业数大于2时才可以启动匿评" + end + else + link = "未开启匿评作业不可以启动匿评" + end + link + end + #获取 def get_submit_sutdent_list homework studentlist = [] @@ -104,6 +127,11 @@ module ApiHelper #计算作业的截止日期,剩余日期 def show_homework_deadline homework - "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + day = 0 + if (day = (Date.parse(homework.end_time.to_s) - Date.parse(Time.now.to_s)).to_i) > 0 + "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + else + "已截止,但可补交" + end end end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index b77703a37..81cf339dd 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -651,9 +651,9 @@ class CoursesService return end if current_user == @user || current_user.admin? - membership = @user.coursememberships.page(1).per(10) + membership = @user.coursememberships.page(1).per(15) else - membership = @user.coursememberships.page(1).per(10).all(:conditions => Course.visible_condition(current_user)) + membership = @user.coursememberships.page(1).per(15).all(:conditions => Course.visible_condition(current_user)) end if membership.nil? || membership.count == 0 raise l(:label_no_courses, :locale => get_user_language(current_user)) @@ -669,10 +669,11 @@ class CoursesService dynamics_count = 0 # 课程学霸 学生总分数排名靠前的5个人 homework_count = course.homework_commons.count - unless homework_count == 0 - sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,6" - latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> User.find_by_sql(sql)} + better_students = User.find_by_sql(sql) + if homework_count != 0 && !better_students.empty? + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> better_students} dynamics_count += 1 end # 课程通知 @@ -754,5 +755,41 @@ class CoursesService student_works end + # 开启匿评 + #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 + def start_anonymous_comment params,current_user + homework = HomeworkCommon.find(params[:homework_id]) + return {:status=>4} unless current_user.admin? || current_user.allowed_to?(:as_teacher,Course.find(params[:course_id])) + return {:status=>5} if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + homework_detail_manual = homework.homework_detail_manual + if homework_detail_manual.comment_status == 1 + student_works = homework.student_works + if student_works && student_works.size >=2 + student_works.each_with_index do |work, index| + user = work.user + n = homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + homework_detail_manual.update_column('comment_status', 2) + statue = 1 + else + statue = 2 + end + else + statue = 3 + end + {:status => statue} + end + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1 .. index + n] + end + end From 0a0f5d98dbe413900f5006d137565404c6832353 Mon Sep 17 00:00:00 2001 From: yutao <283765470@qq.com> Date: Fri, 3 Jul 2015 15:03:53 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=20?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=20=E4=B8=8E=E6=88=91=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity_notifys_controller.rb | 1 + app/controllers/comments_controller.rb | 14 +++++++++++++ app/controllers/news_controller.rb | 15 +++++++++++++ app/models/comment.rb | 21 +++++++++++++++++++ app/models/news.rb | 15 +++++++++++++ 5 files changed, 66 insertions(+) diff --git a/app/controllers/activity_notifys_controller.rb b/app/controllers/activity_notifys_controller.rb index 01e4260ea..ad9818fcc 100644 --- a/app/controllers/activity_notifys_controller.rb +++ b/app/controllers/activity_notifys_controller.rb @@ -6,6 +6,7 @@ class ActivityNotifysController < ApplicationController # accept_rss_auth :index, :show helper :activities + helper :attachments def index query = nil if @course diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d226000c0..c10f8bc84 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -34,6 +34,20 @@ class CommentsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@comment.id,OwnerTypeHelper::COMMENT end + # ض̬ļ¼add start + if( @comment.id && @news.course ) + if(@news.author_id != User.current.id) + notify = ActivityNotify.new() + notify.activity_container_id = @news.course.id + notify.activity_container_type = 'Course' + notify.activity_id = @comment.id + notify.activity_type = 'Comment' + notify.notify_to = @news.author_id + notify.is_read = 0 + notify.save() + end + end + # ض̬ļ¼add end flash[:notice] = l(:label_comment_added) end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index f71a77ca7..56b4a30fc 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -141,6 +141,21 @@ class NewsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS end + # ض̬ļ¼add start + teachers = searchTeacherAndAssistant(@course) + for teacher in teachers + if(teacher.user_id != User.current.id) + notify = ActivityNotify.new() + notify.activity_container_id = @course.id + notify.activity_container_type = 'Course' + notify.activity_id = @news.id + notify.activity_type = 'News' + notify.notify_to = teacher.user_id + notify.is_read = 0 + notify.save() + end + end + # ض̬ļ¼add end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) redirect_to course_news_index_url(@course) diff --git a/app/models/comment.rb b/app/models/comment.rb index bdb642d3c..a4842a23f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,6 +19,14 @@ class Comment < ActiveRecord::Base include Redmine::SafeAttributes include ApplicationHelper has_many_kindeditor_assets :assets, :dependent => :destroy + + has_many :ActivityNotifies,:as => :activity, :dependent => :destroy + acts_as_event :datetime => :updated_on, + :description => :comments, + :type => 'news', + :title=>Proc.new {|o| "RE: #{o.commented.title}" }, + :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.commented.id} } + belongs_to :commented, :polymorphic => true, :counter_cache => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments @@ -38,4 +46,17 @@ class Comment < ActiveRecord::Base def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::COMMENT end + + def set_notify_id(notify_id) + @notify_id= notify_id + end + def get_notify_id() + return @notify_id + end + def set_notify_is_read(notify_is_read) + @notify_is_read = notify_is_read + end + def get_notify_is_read() + return @notify_is_read + end end diff --git a/app/models/news.rb b/app/models/news.rb index 7e809cbfd..7d33d760e 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -30,6 +30,8 @@ class News < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # end + has_many :ActivityNotifies,:as => :activity, :dependent => :destroy + validates_presence_of :title, :description validates_length_of :title, :maximum => 60 validates_length_of :summary, :maximum => 255 @@ -85,6 +87,19 @@ class News < ActiveRecord::Base #description end + def set_notify_id(notify_id) + @notify_id= notify_id + end + def get_notify_id() + return @notify_id + end + def set_notify_is_read(notify_is_read) + @notify_is_read = notify_is_read + end + def get_notify_is_read() + return @notify_is_read + end + private def add_author_as_watcher From d882a3c5eea306a54e220eb232a7fd15d29614df Mon Sep 17 00:00:00 2001 From: yutao <283765470@qq.com> Date: Fri, 3 Jul 2015 15:20:53 +0800 Subject: [PATCH 15/16] =?UTF-8?q?bug#2948:=E5=9C=A8=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=92=8C=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E8=A2=AB=E7=95=99=E8=A8=80=E7=9A=84=E4=BA=BA=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E8=83=BD=E7=9C=8B=E5=88=B0=E7=95=99=E8=A8=80=E4=BA=BA?= =?UTF-8?q?=E7=9A=84=E6=98=B5=E7=A7=B0=E5=92=8C=E7=9C=9F=E5=AE=9E=E5=A7=93?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/_history.html.erb | 2 +- app/views/users/_history.html.erb | 2 +- app/views/words/_journal_reply_items.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index e9639f4f0..043bac947 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -9,7 +9,7 @@<%=journal.notes.html_safe%>
diff --git a/app/views/words/_journal_reply_items.html.erb b/app/views/words/_journal_reply_items.html.erb index f93254218..5e9d6ef46 100644 --- a/app/views/words/_journal_reply_items.html.erb +++ b/app/views/words/_journal_reply_items.html.erb @@ -13,10 +13,10 @@