课程推荐
This commit is contained in:
parent
610b54b27c
commit
18c3c23d2c
|
@ -12,19 +12,38 @@ module CoursesHelper
|
|||
#AllPeople = StudentRoles+TeacherRoles
|
||||
## return people count
|
||||
|
||||
|
||||
# 推荐的精品课程
|
||||
def excellent_course_recommend course
|
||||
q = "%#{course.name.strip}%"
|
||||
result = find_excelletn_course(q, course)
|
||||
def excellent_course_recommend new_course
|
||||
q = "%#{new_course.name.strip}%"
|
||||
result = find_excelletn_course(q, new_course)
|
||||
end
|
||||
|
||||
# 查询符合条件的精品课程
|
||||
def find_excelletn_course keywords, course
|
||||
# 用新课程名去匹配精品课程中按课程名和Tag名
|
||||
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}%'or c.name like '%#{keywords}%')"
|
||||
resultSetTag = Course.find_by_sql(sql).select{|e_course| e_course.is_public ==1 unless User.current.member_of_course?(e_course)}.first(3)
|
||||
resultSetTag
|
||||
# 用新课程名去匹配精品课程中按课程名和Tag名
|
||||
def find_excelletn_course keywords, current_course
|
||||
# 获取tag匹配结果ID
|
||||
a_tags = []
|
||||
# kc = keywords.to_a
|
||||
Course.visible.where("is_excellent =?", 2).each do |ec|
|
||||
if ec.tags.any?{|value| current_course.name.include?(value.to_s)}
|
||||
#if ec.tags.find_all{|ect| kc.include? ect}.length != 0
|
||||
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 unless current_course.id != c.id
|
||||
end
|
||||
a_courses << a_tags unless a_tags.length == 0
|
||||
# 过滤条件:精品课程、本身不在搜索范围
|
||||
e_courses = Course.where("is_excellent =? and id in (?)",1,a_courses.uniq).where("id !=?",current_course.id)
|
||||
e_courses
|
||||
end
|
||||
|
||||
# 判断精品课程是否可见,非课程成员无法查看私有课程
|
||||
|
|
|
@ -72,7 +72,7 @@ class Course < ActiveRecord::Base
|
|||
before_save :self_validate
|
||||
# 公开课程变成私有课程,所有资源都变成私有
|
||||
after_update :update_files_public,:update_course_ealasticsearch_index,:update_activity
|
||||
after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index
|
||||
after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index, :add_course_ead
|
||||
before_destroy :delete_all_members,:delete_course_ealasticsearch_index
|
||||
|
||||
safe_attributes 'extra',
|
||||
|
@ -145,6 +145,26 @@ class Course < ActiveRecord::Base
|
|||
)
|
||||
end
|
||||
|
||||
def self.e_search(query)
|
||||
__elasticsearch__.search(
|
||||
{
|
||||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['name', 'description^0.5']
|
||||
}
|
||||
},
|
||||
sort: {
|
||||
_score:{order: "desc" },
|
||||
updated_at:{order:"desc"}
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def visible?(user=User.current)
|
||||
user.allowed_to?(:view_course, self)
|
||||
end
|
||||
|
@ -385,6 +405,14 @@ class Course < ActiveRecord::Base
|
|||
self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false)
|
||||
end
|
||||
|
||||
# 发布新课导语
|
||||
def add_course_ead
|
||||
name = Redmine::Configuration['course_message_lead_subject']
|
||||
content = Redmine::Configuration['course_message_lead_content']
|
||||
# message的status状态为0为正常,为1表示创建课程时发送的message
|
||||
Message.create(:subject => name, :content => content, :board_id => self.boards.first.id, :author_id => self.tea_id , :sticky => true, :status => true )
|
||||
end
|
||||
|
||||
#项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题
|
||||
#def name
|
||||
# read_attribute('name') || Project.find_by_identifier(self.extra).try(:name)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<% unless excellent_course_recommend(course).count == 0 %>
|
||||
<ul class="courseR mb10">
|
||||
<p class="fontGrey2 f14"><%= l(:label_homework_recommendation) %></p>
|
||||
<% excellent_course_recommend(course).each do |c_course| %>
|
||||
<li class="mt15"> <%= image_tag(url_to_avatar(c_course), :width => "40", :height => "40", :class => "fl mr10 rankPortrait", :alt => "logo") %>
|
||||
<% excellent_course_recommend(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"><a href="javascript:void:(0);" class="hidden fl w170"><%=link_to c_course.name, course_path(c_course) %> </a></p>
|
||||
<p class="f12 mb5"><%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %></p>
|
||||
<p class="f12">
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to c_course.attachments.count, course_files_path(c_course), :class => "linkBlue2" %>)</span>
|
||||
<span class="fl fontGrey4"><%= l(:label_homework_commont) %>(<%= link_to c_course.homework_commons.count, homework_common_index_path(c_course), :class => "linkBlue2" %>)</span></p>
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to e_course.attachments.count, course_files_path(e_course), :class => "linkBlue2" %>)</span>
|
||||
<span class="fl fontGrey4"><%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.count, homework_common_index_path(e_course), :class => "linkBlue2" %>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
|
|
|
@ -141,6 +141,7 @@ h4{ font-size:14px; color:#3b3b3b;}
|
|||
.w100{width: 100px;}
|
||||
.w210{ width:210px;}
|
||||
.w150{ width:150px;}
|
||||
.w170{width:170px;}
|
||||
.w230{width:230px !important;}
|
||||
.w235{ width:235px !important;}
|
||||
.w280{ width:280px;}
|
||||
|
|
Loading…
Reference in New Issue