This commit is contained in:
nwb 2014-05-12 18:46:53 +08:00
commit 431b6603f1
6 changed files with 119 additions and 36 deletions

View File

@ -27,6 +27,11 @@ class SchoolController < ApplicationController
def upload_logo
end
#获取制定学校开设的课程数
def course_count school_id
School.find(school_id).courses.count
end
def index

View File

@ -108,5 +108,7 @@ module CoursesHelper
now > cTime
end
def find_by_extra_from_project extra
Course.find_by_extra(try(extra))
end
end

View File

@ -105,7 +105,31 @@ module WelcomeHelper
# c2 = c2 - c1
# (c1.take(max)+c2).take(sum)
end
#查找所有学校按每个学校开设课程数量降序排序
#page 分页查询开始条数的编号,从0开始
#limit 分页查询的数量
def find_maxmin_course_school page,limit
School.find_by_sql("SELECT *,(SELECT COUNT(*) FROM courses WHERE school_id = schools.id) AS a
FROM schools
ORDER BY a DESC LIMIT #{page},#{limit}")
#School.where(" id IN (SELECT school_id FROM courses GROUP BY school_id)").limit limit;
#School.order("#{School.course_count}").limit(limit).all
#@school = School.all.sort
#@school.each do |s|
# s.courses.count
#end
#result = []
#@school = School.all.to_ary
#i = 1
#for i in i < School.count
# j = i - 1
# for j in j > 0
# if @school[j].courses.count >
# end
#end
end
def find_miracle_project(sum, max_rate)
max = sum*(max_rate.to_f/10)
c1 = find_new_project(sum).to_a.dup

View File

@ -47,5 +47,4 @@ class Course < ActiveRecord::Base
return time
end
end
end

View File

@ -12,7 +12,8 @@
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (course.homeworks.count), {:controller => 'projects', :action => 'homework', :id => course.identifier} %></span>)
&nbsp;&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (course.news.count), {:controller => 'news', :action => 'index', :project_id => course.identifier} %></span>)
</td>
</span>
</td>
</tr>
<tr>
<td colspan="2" width="580" >

View File

@ -1,6 +1,7 @@
<%= stylesheet_link_tag 'welcome' %>
<%= javascript_include_tag 'welcome' %>
<script type="text/javascript" language="javascript">
<script type="text/javascript" language="javascript" xmlns="http://www.w3.org/1999/html"
xmlns="http://www.w3.org/1999/html">
$(function(){
$("#main").find("a").attr("target", "_blank");
@ -60,49 +61,100 @@
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<h3><strong>新开课程</strong></h3>
<span><%= link_to "更多>>", {:controller => 'projects', :action => 'course', :project_type => 1, :school_id => params[:school_id]} %></span>
<div class="d-p-projectlist-box">
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
</ul>
<ul class="d-p-projectlist">
<% find_miracle_course(10, 7,params[:school_id]).map do |project| %>
<li class='<%= cycle("odd", "even") %>' title=<%=project.description.to_s%>>
<div class='avatar'>
<%= image_tag(get_course_avatar(project), :class => "avatar-4") %>
</div>
<!-- 上左下右 -->
<div class='desc_item text_nowrap' >
[<%= get_course_term project %>]
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%>
(<%= link_to "#{studentCount(project)}人", project_member_path(project, :role => 2) ,:course =>'1' %>)
<% files_count = (project.attachments.count.to_i+Version.joins(:project).where("projects.id=#{project.id}").count.to_i).to_s %>
(<%=link_to "#{files_count}份", project_files_path(project) %>资料)
</div>
<div class='desc_item' >
<% if(find_miracle_course(10, 7,params[:school_id]).map.count == 0) %>
<h1></h1>
<p id="errorExplanation">
该学校未开设任何课程,您可以查看其他学校课程
</p>
<h1></h1>
<% find_all_hot_course(9).map do |project| %>
<li class='<%= cycle("odd", "even") %>' title=<%=project.description.to_s%>>
<div class='avatar'>
<%= image_tag(get_course_avatar(project), :class => "avatar-4") %>
</div>
<!-- 上左下右 -->
<div class='desc_item text_nowrap' >
[<%= get_course_term project %>]
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%>
(<%= link_to "#{studentCount(project)}人", project_member_path(project, :role => 2) ,:course =>'1' %>)
<% files_count = (project.attachments.count.to_i+Version.joins(:project).where("projects.id=#{project.id}").count.to_i).to_s %>
(<%=link_to "#{files_count}份", project_files_path(project) %>资料)
</div>
<div class='desc_item' >
<span class=''>
<% course = Course.find_by_extra(project.identifier)%>
<% if(course.school == nil) %>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<% else %>
<%= course.school.name.try(:gsub, /(.+)$/, '\1:') %>
<% end %>
</span>
<span class='font_bolder'>
<%= link_to(course.try(:teacher).try(:name), user_path(course.teacher)) %>
<%#=course.try(:teacher).try(:name)%>
</span>
</div>
<!-- <div class='desc_item' style="">
<span class='font_lighter' title=<%#=project.description.to_s%>><%#=project.description.truncate(25, omission: '...')%></span>
</div> -->
<div class='join_course_link'>
<% if !course_endTime_timeout?(project)%>
<div >
<%= join_in_course(project, User.current)%>
</div>
<% end %>
</div>
</li>
<% end %>
<% else %>
<% find_miracle_course(10, 7,params[:school_id]).map do |project| %>
<li class='<%= cycle("odd", "even") %>' title=<%=project.description.to_s%>>
<div class='avatar'>
<%= image_tag(get_course_avatar(project), :class => "avatar-4") %>
</div>
<!-- 上左下右 -->
<div class='desc_item text_nowrap' >
[<%= get_course_term project %>]
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%>
(<%= link_to "#{studentCount(project)}人", project_member_path(project, :role => 2) ,:course =>'1' %>)
<% files_count = (project.attachments.count.to_i+Version.joins(:project).where("projects.id=#{project.id}").count.to_i).to_s %>
(<%=link_to "#{files_count}份", project_files_path(project) %>资料)
</div>
<div class='desc_item' >
<span class=''>
<% course = Course.find_by_extra(project.identifier) %>
<%= course.school.name.try(:gsub, /(.+)$/, '\1:') %>
<%= course.school.name.try(:gsub, /(.+)$/, '\1:') %>
</span>
<span class='font_bolder'>
<%= link_to(course.try(:teacher).try(:name), user_path(course.teacher)) %>
<%#=course.try(:teacher).try(:name)%>
<%#=course.try(:teacher).try(:name)%>
</span>
</div>
<!-- <div class='desc_item' style="">
</div>
<!-- <div class='desc_item' style="">
<span class='font_lighter' title=<%#=project.description.to_s%>><%#=project.description.truncate(25, omission: '...')%></span>
</div> -->
<div class='join_course_link'>
<% if !course_endTime_timeout?(project)%>
<div >
<%= join_in_course(project, User.current)%>
</div>
<% end %>
</div>
</li>
<% end; reset_cycle %>
<div class='join_course_link'>
<% if !course_endTime_timeout?(project)%>
<div >
<%= join_in_course(project, User.current)%>
</div>
<% end %>
</div>
</li>
<% end; reset_cycle %>
<% end %>
</ul>
</div>
</div>
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject" style="float: right;">
<h3 style="padding-bottom:px ;margin-left: 5px; color: #e8770d;">
<h3 style="padding-bottom:0px ;margin-left: 5px; color: #e8770d;">
<strong>问题和反馈动态</strong>
<%= link_to "我要提问" , newbie_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%>
<%= link_to "我要反馈" , suggestion_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE" }%>
@ -117,11 +169,11 @@
<%= 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>
<br>
<span style="margin-left: 24px; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;"><%= l(:field_updated_on) %><%=time_tag_welcome(topic_last_time topic)%>前</span>
<span style="margin-left: 24px; color: rgb(172, 174, 177); white-space: nowrap; font-size:9pt !important;;"><%= l(:field_updated_on) %><%=time_tag_welcome(topic_last_time topic)%>前</span>
<span style="margin-left: 8px; margin-bottom: 0px; color: rgb(172, 174, 177) !important; white-space: nowrap;">
由&nbsp;<%= link_to topic.author ? topic.author : 'Anonymous', user_path(topic.author_id), :style => "font-size: 9pt !important; color: rgb(17, 102, 173);" %>&nbsp;发表
</span>
<span style="float: right; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;">回复(<%= link_to (topic.parent ? topic.parent.replies_count : topic.replies_count), topic.event_url %>)</span>
<span style="float: right; color: rgb(172, 174, 177); white-space: nowrap; font-size:9pt !important;;">回复(<%= link_to (topic.parent ? topic.parent.replies_count : topic.replies_count), topic.event_url %>)</span>
</div>
</li>
<% end %>