From e04e80d64d952ab145b9a856d73883e5eeaf066a Mon Sep 17 00:00:00 2001 From: cxt Date: Sat, 20 Feb 2016 16:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E8=B6=8A=E5=A4=9A=E4=B8=AA=E5=AD=A6?= =?UTF-8?q?=E6=9C=9F=E7=9A=84=E8=AF=BE=E7=A8=8B=E5=AD=A6=E6=9C=9F=E7=9A=84?= =?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/helpers/courses_helper.rb | 37 ++++++++++++++++++++++-- app/views/layouts/_user_courses.html.erb | 2 +- app/views/layouts/base_courses.html.erb | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 1e4cedf14..40ed4a21a 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -116,6 +116,34 @@ module CoursesHelper @course.journals_for_messages.where('m_parent_id IS NULL').count end + #当前学期 + def current_time_and_term course + str = "" + term = cur_course_term + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = course.time.to_s + course.term.to_s + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = course.time.to_s + course.term.to_s + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = course.end_time.to_s + course.end_term.to_s + else + str = Time.now.year.to_s + cur_course_term.to_s + end + str + end + + def set_term_value term + val = 0 + if term == "春季学期" + val = 1 + elsif term == "夏季学期" + val = 2 + elsif term == "秋季学期" + val = 3 + end + val + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count @@ -562,7 +590,7 @@ module CoursesHelper type = [] month = Time.now.month now_year = year.nil? ? Time.now.year : (Time.now.year <= year ? Time.now.year : year) - year = month < 3 && now_year >=Time.now.year ? now_year - 1 : now_year + year = month < 2 && now_year >=Time.now.year ? now_year - 1 : now_year for i in (year..year + 10) option = [] option << i @@ -592,8 +620,10 @@ module CoursesHelper def cur_course_term month = Time.now.month - if month >= 9 || month < 3 + if month >= 9 || month < 2 term = "秋季学期" + elsif (month >= 7 && Time.now.day >= 15) || month == 8 + term = "夏季学期" else term = "春季学期" end @@ -603,7 +633,7 @@ module CoursesHelper def course_in_current_or_next_term course is_current_term = false is_next_term = false - year_now = Time.now.month < 3 ? Time.now.year - 1:Time.now.year + year_now = Time.now.month < 2 ? Time.now.year - 1:Time.now.year if course.time == year_now && course.term == cur_course_term is_current_term = true end @@ -612,6 +642,7 @@ module CoursesHelper elsif cur_course_term == "春季学期" && course.time == year_now && course.term == "夏季学期" is_next_term = true elsif cur_course_term == "夏季学期" && course.time == year_now && course.term == "秋季学期" + is_next_term = true end is_current_term || is_next_term end diff --git a/app/views/layouts/_user_courses.html.erb b/app/views/layouts/_user_courses.html.erb index 1ba7e9483..7aa591aae 100644 --- a/app/views/layouts/_user_courses.html.erb +++ b/app/views/layouts/_user_courses.html.erb @@ -2,7 +2,7 @@
  • <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) %> <%= link_to course.name, course_path(course.id,:host=>Setting.host_course), :class => "coursesLineGrey hidden #{course_endTime_timeout?(course) ? 'c_dark_grey' : ''}", - :id => "show_course_#{course.id}",:title => (course.is_public? ? "公开课程:":"私有课程:")+course.name+"("+course.time.to_s+course.term+")"%> + :id => "show_course_#{course.id}",:title => (course.is_public? ? "公开课程:":"私有课程:")+course.name+"("+current_time_and_term(course)+")"%> <% count = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count %>