修改课程首页显示课程:

1.3-8月份为显示春季课程,9-2月份为显示秋季课程
1.当前用户未登录:显示系统中在当前年度、季度中人数最多的10个公开课程
2.当前用户以登录,或者选择指定学校:显示该用户所在学校/指定学校在当前年度、季度中人数最多的10门该用户可见的课程(包括该用户可见的私有课程),如果该学校课程数量不足,向用户推荐其他课程补充数量
This commit is contained in:
sw 2014-10-14 10:32:59 +08:00
parent 0121871183
commit 7529a944cf
3 changed files with 62 additions and 41 deletions

View File

@ -62,11 +62,12 @@ class WelcomeController < ApplicationController
def course
@course_page = FirstPage.where("page_type = 'course'").first
if params[:school_id]
@school_id = params[:school_id]
elsif User.current.logged? && User.current.user_extensions.try(:school)
@school_id = User.current.user_extensions.school.try(:id)
end
#if params[:school_id]
# @school_id = params[:school_id]
#elsif User.current.logged? && User.current.user_extensions.try(:school)
# @school_id = User.current.user_extensions.school.try(:id)
#end
@school_id = params[:school_id] || User.current.user_extensions.school.try(:id)
@logoLink ||= logolink()
end

View File

@ -136,31 +136,33 @@ module WelcomeHelper
#获取课程列表
# add by nwb
def find_miracle_course(sum=10, max_rate=7, school_id)
def find_miracle_course(sum=10, max_rate=7, school_id, time,term)
if User.current.user_extensions.nil? && User.current.user_extensions.school.nil? and school_id.nil?
Course.active.visible.
joins(:memberships).
where("courses.time = #{time} and courses.term = #{term}").
group('members.course_id').
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
else
if school_id.nil?
Course.active.visible.
joins(:memberships).
where("#{Course.table_name}.school_id = ?", User.current.user_extensions.school.id).
where("#{Course.table_name}.school_id = ? and courses.time = ? and courses.term = ?", User.current.user_extensions.school.id, time, term).
group('members.course_id').
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
reorder("COUNT(members.course_id) DESC").take sum
else
if school_id == "0"
Course.active.visible.
joins(:memberships).
where("courses.time = #{time} and courses.term = #{term}").
group('members.course_id').
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
reorder("COUNT(members.course_id) DESC").take sum
else
Course.active.visible.
joins(:memberships).
where("#{Course.table_name}.school_id = ?", school_id).
where("#{Course.table_name}.school_id = ? and courses.time = ? and courses.term = ?", school_id, time, term).
group('members.course_id').
reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum
reorder("COUNT(members.course_id) DESC").take sum
end
end
end
@ -229,16 +231,28 @@ module WelcomeHelper
end
# modif by nwb
def find_all_new_hot_course limit = 9 ,school_id = 0
def find_all_new_hot_course limit = 9 ,school_id = nil, year_now, course_term
#sort_project_by_hot_rails 1, 'course_ac_para DESC', limit
time_now = Time.new.strftime("%Y")
if school_id
courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <>
?", school_id).order("course_ac_para DESC").limit(limit).all
else
courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL
").order("course_ac_para DESC").limit(limit).all
end
#time_now = Time.new.strftime("%Y")
#if school_id
#courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <>
# ?", school_id).order("course_ac_para DESC").limit(limit).all
#else
# courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL
# ").order("course_ac_para DESC").limit(limit).all
# end
school_id.nil? ?
courses = Course.includes(:school, :members).visible.
joins(:memberships).
where("courses.time = ? and courses.term = ? and courses.school_id is not NULL", year_now, course_term).
group('members.course_id').
reorder("COUNT(members.course_id) DESC").limit(limit).all
:
courses = Course.includes(:school, :members).visible.
joins(:course_status).
where("courses.time = ? and courses.term = ? and courses.school_id <> ?",year_now, course_term, school_id).
group('members.course_id').
reorder("COUNT(members.course_id) DESC").limit(limit).all
courses
end

View File

@ -78,29 +78,28 @@
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<h3><strong><%= l(:lable_hot_course)%></strong></h3>
<% if @school_id %>
<% school_course = find_miracle_course(10,7, @school_id) %>
<% else %>
<%school_course=[]%>
<% end %>
<% if (school_course.count == 0) %>
<span><%= render :partial => 'more_course', :locals => {:school_id => nil}%></span>
<% month_now = Time.now.strftime("%m").to_i %>
<% year_now = Time.new.strftime("%Y") %>
<!-- 3-8月份为查找春季课程9-2月份为查找秋季课程 -->
<% (month_now >= 3 && month_now < 9) ? course_term = "春季学期" : course_term = "秋季学期" %>
<% @school_id.nil? ? cur_school_course = [] : cur_school_course = find_miracle_course(10,7,@school_id, year_now, course_term) %>
<% if cur_school_course.count == 0 %>
<span><%= render :partial => 'more_course', :locals => {:school_id => nil}%></span>
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
<% if User.current.logged? %>
<li>
<%= render :partial => 'no_course_title', :locals => {:course_title => l(:label_school_no_course)} %>
</li>
<%= render :partial => 'course_list', :locals => {:course_list => find_all_new_hot_course(9, @school_id)} %>
<% else %>
<%= render :partial => 'course_list', :locals => {:course_list => find_all_new_hot_course(10, @school_id)} %>
<% end %>
<% User.current.logged? ? course_count = 9 : course_count = 10 %>
<%= render :partial => 'course_list', :locals => {:course_list => find_all_new_hot_course(course_count, @school_id, year_now, course_term)} %>
</ul>
</div>
<% else %>
<% if school_course.count < 9 %>
<% if cur_school_course.count < 9 %>
<span>
<%= render :partial => 'more_course', :locals => {:school_id => nil}%>
</span>
@ -111,12 +110,12 @@
<% end %>
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
<%= render :partial => 'course_list', :locals => {:course_list => school_course} %>
<% if school_course.count < 9 %>
<%= render :partial => 'course_list', :locals => {:course_list => cur_school_course} %>
<% if cur_school_course.count < 9 %>
<li>
<%= render :partial => 'no_course_title', :locals => {:course_title => l(:label_school_less_course)} %>
</li>
<%= render :partial => 'course_list', :locals => {:course_list => find_all_new_hot_course(9 - school_course.count, @school_id)} %>
<%= render :partial => 'course_list', :locals => {:course_list => find_all_new_hot_course(9-cur_school_course.count, @school_id, year_now, course_term)} %>
<% end %>
</ul>
</div>
@ -136,19 +135,26 @@
<% find_new_forum_topics(10).each do |topic| %>
<li class="message-brief-intro" style="min-height: 65px; line-height:2em; ">
<div style="display: inline-block; width: 100%;">
<span class="memo_activity text_nowrap" style="color:gray; display: inline-block; margin-bottom:6px; background: url('/images/list-icon.png') no-repeat scroll ;background-position: left center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to '['+topic.forum.name + ']', forum_path(topic.forum), :class => 'memo_Bar_title' %><%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url, :class => "gray", :style => "font-size: 10pt !important;" %>
<span class="memo_activity text_nowrap" title="<%= topic.subject%>"
style="color:gray; display: inline-block; margin-bottom:6px; background: url('/images/list-icon.png') no-repeat scroll ;background-position: left center;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to '['+topic.forum.name + ']', forum_path(topic.forum), :class => 'memo_Bar_title' %>
<%= link_to topic.subject, topic.event_url, :class => "gray", :style => "font-size: 10pt !important;" %>
</span>
<div class='memo_activity memo_attr'>
<span class='memo_timestamp'>
<%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %>
</span>
<span class="memo_author">
<%= l(:label_question_sponsor)%> <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %>
<span class="memo_author" title="<%= topic.author.login%>">
<%= l(:label_question_sponsor)%>
<%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %>
</span>
<span class="memo_last_person">
<%= l(:label_final_reply)%><% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %><%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%><% end %>
<span class="memo_last_person" title="<%= topic.last_reply.author.login unless (topic.last_reply.nil? || topic.last_reply.author.nil?)%>">
<%= l(:label_final_reply)%>
<% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %>
<%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%>
<% end %>
</span>
<span class="memo_reply">
<%= l(:label_reply)%>(<%= link_to topic.try(:replies_count), topic.event_url %>)