精品课程推荐
This commit is contained in:
parent
f52b0c1cc6
commit
ef0a2a54c5
|
@ -54,6 +54,11 @@ module ApplicationHelper
|
|||
course.is_excellent? ? true : false
|
||||
end
|
||||
|
||||
# 判断课程对成员是否可见
|
||||
def visible_course?(course)
|
||||
(course.is_delete? or (!course.is_public? && !User.current.member_of_course?(course))) ? false : true
|
||||
end
|
||||
|
||||
# 获取项目/课程总分
|
||||
# 发布缺陷 4分 回复缺陷 1分 提交一次 4分 讨论帖子 2分 回复帖子 1分 发布新闻 1分
|
||||
def static_project_score obj
|
||||
|
|
|
@ -11,6 +11,32 @@ module CoursesHelper
|
|||
#StudentRoles = [5, 10]
|
||||
#AllPeople = StudentRoles+TeacherRoles
|
||||
## return people count
|
||||
|
||||
# 推荐的精品课程
|
||||
def excellent_course_recommend course
|
||||
q = "%#{course.name.strip}%"
|
||||
result = find_excelletn_course(q, course)
|
||||
end
|
||||
|
||||
# 查询符合条件的精品课程
|
||||
def find_excelletn_course keywords, course
|
||||
# 用新课程名去匹配精品课程中按课程名和Tag名
|
||||
if !course.is_public? && !User.current.member_of_course?(course)
|
||||
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)
|
||||
else
|
||||
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}%') ORDER BY c.updated_at desc limit 0,5;"
|
||||
resultSetTag = Course.visible.find_by_sql(sql)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 判断精品课程是否可见,非课程成员无法查看私有课程
|
||||
def visible_excellent_course obj
|
||||
# if course.is_pu
|
||||
end
|
||||
|
||||
# 返回x项目成员数量,即roles表中定义的所有成员
|
||||
def projectCount project
|
||||
|
|
|
@ -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',
|
||||
|
@ -384,6 +384,12 @@ class Course < ActiveRecord::Base
|
|||
def act_as_course_message
|
||||
self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false)
|
||||
end
|
||||
|
||||
# 发布新课导语
|
||||
def add_course_ead
|
||||
|
||||
end
|
||||
|
||||
#项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题
|
||||
#def name
|
||||
# read_attribute('name') || Project.find_by_identifier(self.extra).try(:name)
|
||||
|
@ -405,6 +411,7 @@ class Course < ActiveRecord::Base
|
|||
self.__elasticsearch__.index_document
|
||||
end
|
||||
end
|
||||
|
||||
def update_course_ealasticsearch_index
|
||||
if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
|
||||
begin
|
||||
|
@ -428,13 +435,17 @@ class Course < ActiveRecord::Base
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
#动态的更新
|
||||
def update_activity
|
||||
update_course_activity(self.class, self.id)
|
||||
update_user_activity(self.class, self.id)
|
||||
update_org_activity(self.class, self.id)
|
||||
end
|
||||
|
||||
end
|
||||
#动态的更新
|
||||
def update_activity
|
||||
update_course_activity(self.class, self.id)
|
||||
update_user_activity(self.class, self.id)
|
||||
update_org_activity(self.class, self.id)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Delete the previous articles index in Elasticsearch
|
||||
# Course.__elasticsearch__.client.indices.delete index: Course.index_name rescue nil
|
||||
|
|
|
@ -1,41 +1,18 @@
|
|||
<ul class="courseR">
|
||||
<p class="fontGrey2 f14"><%= l(:label_homework_recommendation) %></p>
|
||||
<li class="mt15"> <%= image_tag(url_to_avatar(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 course.name, course_path(course) %> </a></p>
|
||||
<p class="f12">
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<a href="javascript:void:(0);" class="linkBlue2"><%= course.attachments.count %></a>)</span>
|
||||
<span class="fl fontGrey4"><%= l(:label_homework_commont) %>(<a href="javascript:void:(0);" class="linkBlue2"><%= course.homework_commons.count %></a>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class="mt15"> <img src="images/courses/pic_courses.jpg" width="40" height="40" alt="logo" class="fl mr10 rankPortrait" />
|
||||
<div class="fl">
|
||||
<p class="f12 mb5"><a href="javascript:void:(0);" class="hidden fl w170">前端技术II(2015秋季学期)</a></p>
|
||||
<p class="f12"><span class="fl mr15 fontGrey4">资源(<a href="javascript:void:(0);" class="linkBlue2">29</a>)</span><span class="fl fontGrey4">作业(<a href="javascript:void:(0);" class="linkBlue2">8</a>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class="mt15"> <img src="images/courses/pic_courses.jpg" width="40" height="40" alt="logo" class="fl mr10 rankPortrait" />
|
||||
<div class="fl">
|
||||
<p class="f12 mb5"><a href="javascript:void:(0);" class="hidden fl w170">数据库(2015秋季学期)</a></p>
|
||||
<p class="f12"><span class="fl mr15 fontGrey4">资源(<a href="javascript:void:(0);" class="linkBlue2">29</a>)</span><span class="fl fontGrey4">作业(<a href="javascript:void:(0);" class="linkBlue2">8</a>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class="mt15"> <img src="images/courses/pic_courses.jpg" width="40" height="40" alt="logo" class="fl mr10 rankPortrait" />
|
||||
<div class="fl">
|
||||
<p class="f12 mb5"><a href="javascript:void:(0);" class="hidden fl w170">离散数学(2015秋季学期)</a></p>
|
||||
<p class="f12"><span class="fl mr15 fontGrey4">资源(<a href="javascript:void:(0);" class="linkBlue2">29</a>)</span><span class="fl fontGrey4">作业(<a href="javascript:void:(0);" class="linkBlue2">8</a>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class="mt15"> <img src="images/courses/pic_courses.jpg" width="40" height="40" alt="logo" class="fl mr10 rankPortrait" />
|
||||
<div class="fl">
|
||||
<p class="f12 mb5"><a href="javascript:void:(0);" class="hidden fl w170">组成原理(2015秋季学期)</a></p>
|
||||
<p class="f12"><span class="fl mr15 fontGrey4">资源(<a href="javascript:void:(0);" class="linkBlue2">29</a>)</span><span class="fl fontGrey4">作业(<a href="javascript:void:(0);" class="linkBlue2">8</a>)</span></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<% 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") %>
|
||||
<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">
|
||||
<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>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
class DefineExcellentCourse < ActiveRecord::Migration
|
||||
def up
|
||||
arr = [302,192,370,394,183,361,117,218,379,178,418,203,342,403,225]
|
||||
for i in 0..arr.length-1
|
||||
begin
|
||||
puts arr[i]
|
||||
course = Course.find(arr[i])
|
||||
course.update_attribute(:is_excellent, true)
|
||||
rescue
|
||||
logger.error("Course is not found!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue