课程base优化
This commit is contained in:
parent
9cbe719c5e
commit
cb4b26762d
|
@ -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 = []
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
<% unless excellent_course_recommend(course).length == 0 %>
|
||||
<% exc_course = excellent_course_recommend(course) %>
|
||||
<% unless exc_course.length == 0 %>
|
||||
<ul class="courseR mb10">
|
||||
<h4 class="mb5" ><%= l(:label_homework_recommendation) %>:</h4>
|
||||
<% excellent_course_recommend(course).each do |e_course| %>
|
||||
<% e_course = Course.find(e_course) %>
|
||||
|
||||
<% exc_course.each do |e_course| %>
|
||||
<li class="mt15"> <%= image_tag(url_to_avatar(e_course), :width => "40", :height => "40", :class => "fl mr10 rankPortrait", :alt => "logo") %>
|
||||
<div class="fl">
|
||||
<p class="f12 mb5"><%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %><div class="cl"></div> </p>
|
||||
<p class="f12">
|
||||
<% if visable_attachemnts_incourse(e_course).count > 0 %>
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to visable_attachemnts_incourse(e_course).count, course_files_path(e_course), :class => "linkBlue2" %>)</span>
|
||||
<% if course_file_num > 0 %>
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to course_file_num, course_files_path(e_course), :class => "linkBlue2" %>)</span>
|
||||
<% end %>
|
||||
<% if e_course.homework_commons.where("publish_time <= '#{Date.today}'").count > 0 %>
|
||||
<span class="fl fontGrey4"><%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.where("publish_time <= '#{Date.today}'").count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>)</span>
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %>
|
||||
<% teacher_num = searchTeacherAndAssistant(@course).count %>
|
||||
<% teacher_num = TeacherAndAssistantCount(@course) %>
|
||||
<% student_num = studentCount(@course) %>
|
||||
<% course_file_num = visable_attachemnts_incourse(@course).count%>
|
||||
<div class="pr_info_logo fl mr10 mb5">
|
||||
<% if is_excellent_course(@course) %>
|
||||
<img src="/images/course/boutique.png" width="50" height="auto" alt="精品" class="boutiqueP" />
|
||||
<% end %>
|
||||
<!--<a href="#"><img src="images/courses/pic_courses.jpg" width="60" height="60" alt="logo" /></a>-->
|
||||
<%= image_tag(url_to_avatar(@course), :width => "60", :height => "60") %>
|
||||
</div>
|
||||
<div class="pr_info_id fl mb5 f14">ID:<%= @course.id%><%= @course.is_public == 0 ? "(私有)" : "(公开)" %>
|
||||
|
@ -16,55 +14,16 @@
|
|||
</div>
|
||||
<div class="pr_info_id fl f14">
|
||||
<% unless is_teacher %>
|
||||
<!--<a href="" class="pr_join_a f12">加入课程</a>-->
|
||||
<div id="join_in_course_header"><%= join_in_course_header(@course, User.current) %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<!--<div class="pr_info_id fl mb5 f14">
|
||||
ID:<%#= @course.id%>
|
||||
</div>
|
||||
<div class="pr_info_join fl">
|
||||
<%# if is_teacher%>
|
||||
<%#= link_to "<span class='pr_setting'></span>#{l(:button_configure)}".html_safe, {:controller => 'courses', :action => 'settings', :id => @course}, :class => "pr_join_a" %>
|
||||
<%#= set_course_time @course%>
|
||||
<%#= link_to "<span class='pr_copy'></span>#{l(:button_copy)}".html_safe, copy_course_course_path(@course.id), :class => "pr_join_a" %>
|
||||
<%# else%>
|
||||
<div id="join_in_course_header"><%#= join_in_course_header(@course, User.current) %></div>
|
||||
<%# end%>
|
||||
</div>-->
|
||||
<div class="cl"></div>
|
||||
|
||||
<!--<div >-->
|
||||
<!--<a class="pr_info_name fl c_dark fb break_word" href="http://<%#= Setting.host_course%>/courses/<%#= @course.id%>" target="_blank">-->
|
||||
<!--<%#= @course.name %>-->
|
||||
<!--</a>-->
|
||||
<!--<%# if @course.is_public == 0%>-->
|
||||
<!--<span class="img_private ">-->
|
||||
<!--<%#= l(:field_is_private)%>-->
|
||||
<!--</span>-->
|
||||
<!--<%# end %>-->
|
||||
<!--<%#if @course.tea_id == User.current.id && @course.outline == 0 %>-->
|
||||
<!--<span>-->
|
||||
<!--<a href="javascript:void(0)" onclick="course_outline('<%#= @course.id%>');">设置大纲</a>-->
|
||||
<!--</span>-->
|
||||
<!--<%# else%>-->
|
||||
<!--<span>-->
|
||||
<!--<a href="javascript:void(0)" onclick="course_outline('<%#= @course.id%>');">设置大纲</a>-->
|
||||
<!--</span>-->
|
||||
<!--<%# end %>-->
|
||||
<!--</div>-->
|
||||
<div >
|
||||
<a class="pr_info_name fl c_dark fb break_word" href="http://<%= Setting.host_course%>/courses/<%= @course.id%>" target="_blank"></a>
|
||||
<div>
|
||||
<a class="pr_info_name c_dark fb break_word fl" href="http://<%= Setting.host_course%>/courses/<%= @course.id%>" target="_blank">
|
||||
<%= @course.name %>
|
||||
</a>
|
||||
<%# if @course.is_public == 0%>
|
||||
<!--<span class="img_private "></span>-->
|
||||
<!--<span class="img_private mr5 fl">
|
||||
<%#= l(:field_is_private)%>
|
||||
</span>-->
|
||||
<%# end %>
|
||||
<span id="course_outline_bar">
|
||||
<%if User.current && @course.tea_id == User.current.id && (@course.outline == 0 || BlogComment.where(:id=>@course.outline).count == 0) %>
|
||||
<a href="javascript:void(0);" title="设置课程大纲" onclick="course_outline('<%= @course.id%>')" class="mr5 syllabusSetting fl"> </a>
|
||||
|
|
|
@ -55,7 +55,8 @@
|
|||
<div id="content">
|
||||
<div id="LSide" class="fl">
|
||||
<div class="project_info" style="position: relative" id="project_info_<%=@course.id %>">
|
||||
<%=render :partial=>'layouts/project_info' %>
|
||||
<% course_file_num = visable_attachemnts_incourse(@course).count %>
|
||||
<%=render :partial=>'layouts/project_info', :locals => {:course_file_num => course_file_num} %>
|
||||
</div><!--课程信息 end-->
|
||||
<div class="info_box">
|
||||
<ul>
|
||||
|
@ -168,7 +169,7 @@
|
|||
<div class="cl"></div>
|
||||
</div><!--项目标签 end-->
|
||||
<!--课程推荐-->
|
||||
<%= render :partial => 'courses/recommendation', :locals => {:course => @course} %>
|
||||
<%= render :partial => 'courses/recommendation', :locals => {:course => @course, :course_file_num => course_file_num} %>
|
||||
<div class="fontGrey5 mt10 ml10 mb10">访问计数 <%= @course.visits.to_i %></div>
|
||||
</div><!--LSide end-->
|
||||
|
||||
|
|
Loading…
Reference in New Issue