diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index dd0b776b..f16dbd97 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,6 +30,11 @@ class WelcomeController < ApplicationController end def course + if params[:school_id] + @school_id = params[:school_id] + else + @school_id = User.current.user_extensions.school.id + end @logoLink ||= logolink() end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 00867d9f..ea72e818 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -67,6 +67,30 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + + # add by nwb + # 关注课程 + def new_course_watcher_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Contest))) + css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + end + # added by fq, modify nyan # Somebody may use option params def join_in_course(course, user, options=[]) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index f753052c..0054b003 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -233,8 +233,9 @@ module WelcomeHelper def find_all_new_hot_course limit = 9 ,school_id = 0 #sort_project_by_hot_rails 1, 'course_ac_para DESC', limit time_now = Time.new.strftime("%Y"); - Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> + courses = Course.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 + courses end def find_all_hot_bid diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index ca7f0bb7..970d9c17 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -39,24 +39,24 @@
- <% if params[:school_id].nil? and User.current.user_extensions.school.nil? %> + <% if @school_id.nil? and User.current.user_extensions.school.nil? %> <% else%> - <% if params[:school_id] == "0" %> + <% if @school_id == "0" %> <% else %> - <% if params[:school_id].nil? %> + <% if @school_id.nil? %> <%= link_to School.find(User.current.user_extensions.school.id).name, options={:action => 'course',:school_id => User.current.user_extensions.school.id}, html_options={:class => 'font_welcome_school',:method => 'get'}%>
<% else %> - <%= link_to School.find(params[:school_id]).name ,options={:action => 'course',:school_id => params[:school_id]}, html_options={:class => 'font_welcome_school',:method => 'get'}%> + <%= link_to School.find(@school_id).name ,options={:action => 'course',:school_id => @school_id}, html_options={:class => 'font_welcome_school',:method => 'get'}%>
<% end %> <% end %> <% end %>
<%= l(:label_welcome_trustie) %><%= l(:label_welcome_trustie_course) %> - <% if params[:school_id].nil? and User.current.user_extensions.school.nil? %> + <% if @school_id.nil? and User.current.user_extensions.school.nil? %> , <%= l(:label_welcome_trustie_course_description) %> <% else %> - <% if params[:school_id] == "0" %> + <% if @school_id == "0" %> , <%= l(:label_welcome_trustie_course_description) %> <% end %> <% end %> @@ -73,7 +73,7 @@

新开课程

- <% school_course = find_miracle_course(10, 7,params[:school_id]) %> + <% school_course = find_miracle_course(10, 7,@school_id) %> <% if(school_course.count == 0) %> <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => nil} %>
@@ -86,7 +86,7 @@ 该学校未开设任何课程,您可以查看其他学校课程

- <% find_all_new_hot_course(9,params[:school_id]).map do |project| %> + <% find_all_new_hot_course(9,@school_id).map do |project| %>
  • >
    <%= image_tag(get_course_avatar(project), :class => "avatar-4") %> @@ -94,7 +94,7 @@
    - <% course = Course.find_by_extra(project.identifier)%> + <% course = Course.find_by_extra(project.extra)%> <% if(course.school == nil) %>               <% else %> @@ -116,13 +116,6 @@ -
    - <% if !course_endTime_timeout?(project)%> -
    - <%= new_watcher_link(project, User.current)%> -
    - <% end %> -
  • <% end %> @@ -134,7 +127,7 @@ <% else %> - <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => params[:school_id]} %> + <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => @school_id} %> <% end %>
    @@ -181,7 +174,7 @@ 该学校开设课程较少,您可以查看其他学校课程

    - <% find_all_new_hot_course(9 - school_course.count,params[:school_id]).map do |project| %> + <% find_all_new_hot_course(9 - school_course.count,@school_id).map do |project| %>
  • >
    <%= image_tag(get_course_avatar(project), :class => "avatar-4") %> diff --git a/db/migrate/20140703085204_clear_course_data.rb b/db/migrate/20140703085204_clear_course_data.rb new file mode 100644 index 00000000..1592257b --- /dev/null +++ b/db/migrate/20140703085204_clear_course_data.rb @@ -0,0 +1,11 @@ +class ClearCourseData < ActiveRecord::Migration + def up + # 清理课程表垃圾数据 + # 之前删除项目未删除课程的数据 + sql = 'delete from courses where name is null and extra not in (select identifier from projects)' + execute(sql) + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 476c0b23..fecaa500 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140701075839) do +ActiveRecord::Schema.define(:version => 20140703085204) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false