diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0c98b804e..9492bfbad 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -49,7 +49,7 @@ class ProjectsController < ApplicationController # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] - before_filter :authorize, :only => [:sort_project_demo, :show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen] + before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen] before_filter :authorize_global, :only => [:new, :create] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] #by young @@ -127,32 +127,39 @@ class ProjectsController < ApplicationController def index #Modified by nie @project_type = params[:project_type] - @limit = 10 - @project_count = Project.visible.where("project_type = ?", 0).count - @project_pages = Paginator.new @project_count, @limit, params['page'] - if params[:project_sort_type].present? - case params[:project_sort_type] - when '0' - @projects = @projects = Project.visible.where("project_type = ?", 0).order("created_on desc").offset(@project_pages.offset).limit(@limit).all - @s_type = 0 - when '1' - @projects = sort_project_demo project_type = 0, order_by="grade desc", @project_pages.offset, @limit - @s_type = 1 - when '2' - @projects = sort_project_demo project_type = 0, order_by="watchers_count desc", @project_pages.offset, @limit - @s_type = 2 - end + per_page_option = 10 + + @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_project) + + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] + + + case params[:project_sort_type] + when '0' + @projects = @projects_all.order("created_on desc") + @s_type = 0 + when '1' + @projects = @projects_all.order("grade desc") + @s_type = 1 + when '2' + @projects = @projects_all.order("watchers_count desc") + @s_type = 2 else - @projects = sort_project_demo project_type = 0, order_by="grade desc", @project_pages.offset, @limit - @s_type = 1 + @projects = @projects = @projects_all.order("grade desc") + @s_type = 1 end + @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + respond_to do |format| format.html { render :layout => 'base' - scope = Project - unless params[:closed] - scope = scope.active - end + # scope = Project + # unless params[:closed] + # scope = scope.active + # end } format.api { # @offset, @limit = api_offset_and_limit @@ -168,34 +175,34 @@ class ProjectsController < ApplicationController def course @project_type = params[:project_type] - @limit = 10; - @project_count = Project.visible.where("project_type = 1").count - @project_pages = Paginator.new @project_count, @limit, params['page'] - if params[:project_sort_type].present? - case params[:project_sort_type] - when '0' - @projects = Project.visible.where("project_type = ?", 1).order("created_on desc").offset(@project_pages.offset).limit(@limit).all - @s_type = 0 - when '1' - @projects = sort_project_demo 1, "course_ac_para desc", @project_pages.offset, @limit - @s_type = 1 - when '2' - @projects = sort_project_demo 1, "watchers_count desc", @project_pages.offset, @limit - @s_type = 2 - end + per_page_option = 10 + + @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) + + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] + + case params[:project_sort_type] + when '0' + @projects = @projects_all.order("created_on desc") + @s_type = 0 + when '1' + @projects = @projects_all.order("course_ac_para desc") + @s_type = 1 + when '2' + @projects = @projects_all.order("watchers_count desc") + @s_type = 2 else - # @projects = sort_project_demo 1, "course_ac_para desc", @project_pages.offset, @limit - @s_type = 0 - @projects = Project.visible.where("project_type = ?", 1).order("created_on desc").offset(@project_pages.offset).limit(@limit).all - # @s_type = 0 + @s_type = 0 + @projects = @projects_all.order("created_on desc") end + @projects = @projects.offset(@project_pages.offset).limit(@project_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 @@ -208,17 +215,8 @@ class ProjectsController < ApplicationController } end end - - def sort_project_demo project_type, order_by, offset, limit - #Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).offset(offset).limit(limit).all - Project.visible.find_by_sql(" - SELECT * - FROM projects AS p RIGHT OUTER JOIN ( - SELECT project_id,grade FROM project_statuses - WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} OFFSET #{offset}) AS t ON p.id = t.project_id ") - end - - def search + + def search #modified by nie @projects = Project.visible @projects = @projects.visible.where('project_type = ?', params[:project_type]).like(params[:name]) if params[:name].present? @@ -461,7 +459,7 @@ class ProjectsController < ApplicationController project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) if params[:project][:is_public] == '1' || @course_tag=="1" - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0) + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type) end @project.members << m @project.project_infos << project diff --git a/app/views/projects/course.html.erb b/app/views/projects/course.html.erb index 13672a6f1..d7a84f534 100644 --- a/app/views/projects/course.html.erb +++ b/app/views/projects/course.html.erb @@ -38,7 +38,7 @@