diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index e7490f5b0..cd6d5abbe 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -73,7 +73,7 @@ class ContestsController < ApplicationController end end - def show_contest + def show_contest @user = @contest.author @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 215dd3a58..6cbec8546 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,9 +1,19 @@ class CoursesController < ApplicationController include CoursesHelper - + + menu_item l(:label_sort_by_time), :only => :index + menu_item l(:label_sort_by_active), :only => :index + menu_item l(:label_sort_by_influence), :only => :index + + before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] + before_filter :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen,:view_homework_attaches,:course] + before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] + before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] + before_filter :require_login, :only => [:join, :unjoin] before_filter :allow_join, :only => [:join] - + + def join if User.current.logged? course = Project.find(params[:object_id]) @@ -59,4 +69,168 @@ class CoursesController < ApplicationController end end + + def course12 + @project_type = params[:project_type] + @school_id = params[:school_id] + per_page_option = 10 + if @school_id == "0" or @school_id.nil? + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + where("#{Project.table_name}.project_type = ? ", Project::ProjectType_course) + else + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + joins(:course_extra). + where("#{Project.table_name}.project_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) + end + + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] + + #gcm activity count + + @project_activity_count=Hash.new + #count initialize + @projects_all.each do |project| + @project_activity_count[project.id]=0 + end + + #@project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcm end + + + case params[:project_sort_type] + when '0' + @projects = @projects_all.order("created_on desc") + @s_type = 0 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '1' + @projects = @projects_all.order("course_ac_para desc") + @s_type = 1 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + when '2' + @projects = @projects_all.order("watchers_count desc") + @s_type = 2 + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + #gcm + when '3' + + #gcm + @project_activity_count=get_project_activity @projects_all,@project_activity_count + #gcmend + + @projects=handle_project @projects_all,@project_activity_count + @s_type = 3 + @projects = @projects[@project_pages.offset, @project_pages.per_page] + else + @s_type = 0 + @projects = @projects_all.order("created_on desc") + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + + #gcm + @project_activity_count=get_project_activity @projects,@project_activity_count + #gcmend + + end + + respond_to do |format| + format.html { + render :layout => 'base' + } + format.api { + # @offset, @limit = api_offset_and_limit + # @project_count = Project.visible.count + # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + } + format.atom { + projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") + } + end + end + + + def index + + per_page_option = 10 + + @courses_all = Course.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.couse_id") + + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] + +#gcm activity count + + @course_activity_count=Hash.new + + @courses_all.each do |course| + @course_activity_count[course.id]=0 + end + + @course_activity_count=get_course_activity @courses_all,@course_activity_count + +#gcm end + + case params[:course_sort_type] + when '0' + @courses = @courses_all.order("created_on desc") + @s_type = 0 + when '1' + @courses = @courses_all.order("grade desc") + @s_type = 1 + when '2' + @courses = @courses_all.order("watchers_count desc") + @s_type = 2 + + #gcm + when '3' + #@courses=desc_sort_course_by_avtivity(@course_activity_count_array,@course_all_array) + @courses=handle_course @courses_all,@course_activity_count + @s_type = 3 + @courses = @courses[@course_pages.offset, @course_pages.per_page] + + else + @courses = @courses = @courses_all.order("grade desc") + @s_type = 1 + end + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + respond_to do |format| + format.html { + render :layout => 'base' + # scope = Project + # unless params[:closed] + # scope = scope.active + # end + } + format.api { + # @offset, @limit = api_offset_and_limit + # @course_count = Project.visible.count + # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all + } + format.atom { + courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") + } + end + end + + end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7dc4b5556..f89023b7e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -170,6 +170,18 @@ module ApplicationHelper end end + def link_to_course(course, options={}, html_options = nil) + if course.archived? + h(course.name) + elsif options.key?(:action) + ActiveSupport::Deprecation.warn "#link_to_course with :action option is deprecated and will be removed in Redmine 3.0." + url = {:controller => 'courses', :action => 'show', :id => project}.merge(options) + link_to course.name, url, html_options + else + link_to course.name, course_path(course, options), html_options + end + end + # Generates a link to a project settings if active def link_to_project_settings(project, options={}, html_options=nil) if project.active? @@ -297,7 +309,41 @@ module ApplicationHelper @project = original_project end s.html_safe + end + + def render_course_nested_lists(courses) + s = '' + if courses.any? + ancestors = [] + original_course = @course + #modified by nie + courses.each do |course| + # set the project environment to please macros. + @course = course + if (ancestors.empty? || course.is_descendant_of?(ancestors.last)) + s << "
<%= l(:label_project_deposit) %> | +<%= l(:label_user_location) %> : | ++ <% if User.current.logged? %> + <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new', :course => 0, :project_type =>( @project_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %> + <% end %> + | +
+
+ <%= text_field_tag 'name', params[:name], :size => 30 %>
+ <%= hidden_field_tag 'project_type', params[:project_type] %>
+ <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
+
+ |
+
<%= link_to request.host()+"/projects", :controller => 'projects', :action => 'index', :project_type => 0 %> | +<%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_project_deposit), :controller => 'projects', :action => 'index', :project_type => 0 %> | +
+ <%= l(:label_my_projects) %> +
+<% end %> + +<% other_formats_links do |f| %> +<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> +<% end %> + +<% content_for :sidebar do %> + +<%= form_tag({}, :method => :get) do %> ++ <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> +
+<% end %> +<% end %> + +<% html_title(l(:label_project_plural)) -%> diff --git a/config/routes.rb b/config/routes.rb index c3239154c..4ccd4195d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -539,7 +539,7 @@ RedmineApp::Application.routes.draw do # add by nwb # 课程路由设置 - resources :course do + resources :courses do member do # 之前在项目 post 'finishcourse'