From cb4b26762d222e4910b0c1b7e4c95592c64a5f97 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 25 Mar 2016 09:56:45 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E8=AF=BE=E7=A8=8Bbase=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 45 ++++++++-------------- app/views/courses/_recommendation.html.erb | 15 ++++---- app/views/layouts/_project_info.html.erb | 45 +--------------------- app/views/layouts/base_courses.html.erb | 5 ++- 4 files changed, 27 insertions(+), 83 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 37c7deb4c..138f88d53 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -24,40 +24,20 @@ module CoursesHelper def find_excelletn_course keywords, current_course # 获取tag匹配结果ID a_tags = [] - # kc = keywords.to_a - Course.visible.where("is_excellent =? and is_public =?", 1, 1).each do |ec| + Course.where("is_excellent =? and is_public =?", 1, 1).includes(:tags).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end end - # sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and - # ts.taggable_type = 'Course' and t.name like '%#{keywords}%'" - # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)} - # 通过elastic结果获取精品课程 - a_courses = [] - #courses = Course.search(keywords) - #courses.each do |c| - # a_courses << c.id - #end - a_courses << a_tags unless a_tags.length == 0 # 课程本身不能搜索显示自己 - excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id} - limit = 5 - excellent_ids.length.to_i + excellent_ids = a_tags.uniq.delete_if{|i| i == current_course.id} sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id - and c.is_excellent =1 and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" - default_ecourse_ids = Course.find_by_sql(sql).flatten - # REDO:时间紧,待优化 - default_ids =[] - default_ecourse_ids.each do |de| - default_ids << de.id - end - default_ids = default_ids - excellent_ids - #default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten - arr_result = excellent_ids << default_ids - arr_result = arr_result.flatten.first(5) - return arr_result - # 过滤条件:精品课程、本身不在搜索范围 - #e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id) + and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" + default_ids = Course.find_by_sql(sql).flatten.map { |c| c.id } + excellent_ids << default_ids.flatten + arr_result = excellent_ids.flatten.uniq.first(5) + excellent_courses = Course.find(arr_result) + return excellent_courses end # 判断精品课程是否可见,非课程成员无法查看私有课程 @@ -258,7 +238,7 @@ module CoursesHelper # 学生人数计算 # add by nwb def studentCount course - course ? course.student.count.to_s : 0#course.student.count + course ? course.student.count.to_i : 0#course.student.count end #课程成员数计算 @@ -293,12 +273,17 @@ module CoursesHelper def searchTeacherAndAssistant project #searchPeopleByRoles(project, TeacherRoles) members = [] - project.members.each do |m| + project.members.includes(:user).each do |m| members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) end members end + def TeacherAndAssistantCount course + students_count = course.student.count + number = course.members.count - students_count + end + def search_student_in_group(project, course_group_id) #searchPeopleByRoles(project, StudentRoles) members = [] diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index a0c659493..63803a5b9 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -1,22 +1,21 @@ -<% unless excellent_course_recommend(course).length == 0 %> +<% exc_course = excellent_course_recommend(course) %> +<% unless exc_course.length == 0 %>