2013-08-01 10:33:49 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class WelcomeController < ApplicationController
|
2014-07-11 11:41:54 +08:00
|
|
|
include ApplicationHelper
|
2014-07-16 14:22:12 +08:00
|
|
|
include WelcomeHelper
|
2014-08-05 16:39:33 +08:00
|
|
|
helper :project_score
|
2013-08-01 10:33:49 +08:00
|
|
|
caches_action :robots
|
2014-08-15 14:30:01 +08:00
|
|
|
before_filter :find_first_page, :only => [:index]
|
2014-04-25 16:08:00 +08:00
|
|
|
# before_filter :fake, :only => [:index, :course]
|
2014-06-13 12:02:29 +08:00
|
|
|
before_filter :entry_select, :only => [:index]
|
2013-08-11 15:27:34 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def index
|
2014-08-15 14:30:01 +08:00
|
|
|
#@first_page = FirstPage.where("page_type = 'project'").first
|
2014-07-30 15:26:55 +08:00
|
|
|
#@show_course = @first_page.show_course
|
2014-07-16 15:24:56 +08:00
|
|
|
if @first_page.nil? || @first_page.sort_type.nil?
|
2014-08-13 11:17:22 +08:00
|
|
|
@projects = find_miracle_project(10, 3,"score desc")
|
2014-07-16 15:24:56 +08:00
|
|
|
else
|
|
|
|
case @first_page.sort_type
|
|
|
|
when 0
|
2014-07-25 09:19:29 +08:00
|
|
|
@projects = find_miracle_project(10, 3,"created_on desc")
|
|
|
|
#@projects = @projects_all.order("created_on desc")
|
2014-07-16 15:24:56 +08:00
|
|
|
when 1
|
2014-08-13 11:17:22 +08:00
|
|
|
@projects = find_miracle_project(10, 3,"score desc")
|
2014-07-25 09:19:29 +08:00
|
|
|
#@projects = @projects_all.order("grade desc")
|
2014-07-16 15:24:56 +08:00
|
|
|
when 2
|
2014-07-25 09:19:29 +08:00
|
|
|
@projects = find_miracle_project(10, 3,"watchers_count desc")
|
|
|
|
#@projects = @projects_all.order("watchers_count desc")
|
2014-07-16 14:22:12 +08:00
|
|
|
|
2014-07-16 15:24:56 +08:00
|
|
|
#gcm
|
|
|
|
#when '3'
|
2014-07-16 14:22:12 +08:00
|
|
|
#@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array)
|
2014-07-16 15:24:56 +08:00
|
|
|
# @projects=handle_project @projects_all,@project_activity_count
|
|
|
|
# @s_type = 3
|
|
|
|
# @projects = @projects[@project_pages.offset, @project_pages.per_page]
|
2014-07-16 14:22:12 +08:00
|
|
|
|
2014-07-16 15:24:56 +08:00
|
|
|
else
|
2014-08-13 11:17:22 +08:00
|
|
|
@projects = @projects_all.order("score desc")
|
2014-07-16 15:24:56 +08:00
|
|
|
end
|
2014-07-16 14:22:12 +08:00
|
|
|
end
|
2014-07-16 15:24:56 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def robots
|
|
|
|
@projects = Project.all_public.active
|
|
|
|
render :layout => false, :content_type => 'text/plain'
|
|
|
|
end
|
2013-09-29 19:46:59 +08:00
|
|
|
|
2014-02-22 09:44:14 +08:00
|
|
|
def course
|
2014-07-11 11:41:54 +08:00
|
|
|
@course_page = FirstPage.where("page_type = 'course'").first
|
2014-07-03 17:28:13 +08:00
|
|
|
if params[:school_id]
|
|
|
|
@school_id = params[:school_id]
|
2014-07-04 09:10:17 +08:00
|
|
|
elsif User.current.logged? && User.current.user_extensions.school
|
2014-07-04 11:30:41 +08:00
|
|
|
@school_id = User.current.user_extensions.school.try(:id)
|
2014-07-03 17:28:13 +08:00
|
|
|
end
|
2014-06-03 11:19:20 +08:00
|
|
|
@logoLink ||= logolink()
|
2014-02-22 09:44:14 +08:00
|
|
|
end
|
2014-03-31 10:56:29 +08:00
|
|
|
|
2014-04-28 10:48:09 +08:00
|
|
|
|
|
|
|
|
2014-04-29 09:49:51 +08:00
|
|
|
def logolink()
|
2014-07-11 11:41:54 +08:00
|
|
|
@course_page = FirstPage.where("page_type = 'course'").first
|
|
|
|
logo = get_avatar?(@course_page)
|
2014-04-29 09:49:51 +08:00
|
|
|
id = params[:school_id]
|
2014-04-28 10:48:09 +08:00
|
|
|
logo_link = ""
|
2014-08-15 14:30:01 +08:00
|
|
|
if id.nil? && (User.current.user_extensions.nil? || User.current.user_extensions.school.nil?)
|
2014-07-11 11:41:54 +08:00
|
|
|
if logo
|
|
|
|
logo_link = url_to_avatar(@course_page)
|
|
|
|
else
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
end
|
|
|
|
|
2014-04-28 10:48:09 +08:00
|
|
|
else
|
2014-04-29 09:49:51 +08:00
|
|
|
if id == "0"
|
2014-07-11 11:41:54 +08:00
|
|
|
if logo
|
|
|
|
logo_link = url_to_avatar(@course_page)
|
|
|
|
else
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
end
|
2014-04-28 10:48:09 +08:00
|
|
|
else
|
|
|
|
if id.nil?
|
|
|
|
if School.find(User.current.user_extensions.school.id).logo_link.nil?
|
|
|
|
logo_link = '/images/transparent.png'
|
|
|
|
else
|
|
|
|
logo_link = School.find(User.current.user_extensions.school.id).logo_link
|
|
|
|
end
|
|
|
|
else
|
|
|
|
logo_link = School.find(id).logo_link
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return logo_link
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-03-31 10:56:29 +08:00
|
|
|
def contest
|
2014-07-11 11:41:54 +08:00
|
|
|
@contest_page = FirstPage.where("page_type = 'contest'").first
|
2014-07-25 11:51:52 +08:00
|
|
|
@contestNotification = ContestNotification.all.first
|
2014-03-31 10:56:29 +08:00
|
|
|
end
|
2014-03-01 10:14:01 +08:00
|
|
|
|
2014-03-25 16:53:11 +08:00
|
|
|
def search
|
|
|
|
search_condition = params[:q]
|
|
|
|
search_type = params[:search_type].to_sym unless search_condition.blank?
|
|
|
|
|
2014-07-21 16:19:45 +08:00
|
|
|
if search_type.nil? && params[:contests_search] && params[:name] != ""
|
|
|
|
search_type = :contests
|
|
|
|
search_condition = params[:name]
|
|
|
|
end
|
|
|
|
|
2014-03-25 16:53:11 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html{
|
|
|
|
case search_type
|
|
|
|
when :projects
|
|
|
|
redirect_to projects_search_path(:name => search_condition,
|
|
|
|
:project_type => Project::ProjectType_project)
|
|
|
|
when :courses
|
2014-07-03 15:24:06 +08:00
|
|
|
redirect_to courses_search_path(:name => search_condition)
|
2014-07-21 15:45:00 +08:00
|
|
|
when :contests
|
2014-07-21 16:19:45 +08:00
|
|
|
redirect_to contests_path(:name => search_condition)
|
2014-03-25 16:53:11 +08:00
|
|
|
when :users
|
|
|
|
redirect_to users_search_path(:name => search_condition)
|
|
|
|
when :users_teacher
|
|
|
|
redirect_to users_search_path(:name => search_condition, :role => :teacher)
|
|
|
|
when :users_student
|
|
|
|
redirect_to users_search_path(:name => search_condition, :role => :student)
|
|
|
|
else
|
2014-07-05 14:43:15 +08:00
|
|
|
#redirect_to home_path, :alert => l(:label_sumbit_empty)
|
|
|
|
(redirect_to home_path, :notice => l(:label_sumbit_empty);return) #if params[:name].blank?
|
2014-03-25 16:53:11 +08:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-01 10:14:01 +08:00
|
|
|
private
|
2014-07-21 17:21:09 +08:00
|
|
|
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
|
2014-06-13 12:02:29 +08:00
|
|
|
def entry_select
|
2014-08-15 14:30:01 +08:00
|
|
|
#@first_page = FirstPage.where("page_type = 'project'").first
|
|
|
|
url = request.original_url.gsub('/','')
|
2014-08-25 09:15:38 +08:00
|
|
|
if url.include?(Setting.host_course.gsub('/',''))
|
2014-07-30 15:26:55 +08:00
|
|
|
if @first_page.show_course == 1
|
|
|
|
course
|
|
|
|
render :course
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2014-06-13 12:02:29 +08:00
|
|
|
return 0
|
2014-08-25 09:15:38 +08:00
|
|
|
elsif url.include?(Setting.host_contest.gsub('/',''))
|
2014-07-30 15:26:55 +08:00
|
|
|
if @first_page.show_contest == 1
|
|
|
|
contest
|
|
|
|
render :contest
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2014-06-13 12:02:29 +08:00
|
|
|
return 0
|
2014-08-25 09:15:38 +08:00
|
|
|
elsif url.include?(Setting.host_user.gsub('/',''))
|
2014-06-13 12:02:29 +08:00
|
|
|
redirect_to(:controller => "users", :action => "index")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-06-03 11:19:20 +08:00
|
|
|
# def render(*args)
|
|
|
|
# _fake if @fake_filter
|
|
|
|
# super
|
|
|
|
# end
|
2014-04-04 21:30:40 +08:00
|
|
|
|
2014-06-03 11:19:20 +08:00
|
|
|
# private
|
2014-04-04 21:30:40 +08:00
|
|
|
|
2014-06-03 11:19:20 +08:00
|
|
|
# def fake
|
|
|
|
# @fake_filter = true
|
|
|
|
# end
|
2014-04-08 14:53:11 +08:00
|
|
|
|
2014-06-03 11:19:20 +08:00
|
|
|
# # 骗子方法
|
|
|
|
# def _fake
|
|
|
|
# instance_variables.map { |variable|
|
|
|
|
# if variable.to_s =~ /Count$/
|
|
|
|
# self.instance_variable_set(variable.to_sym,
|
|
|
|
# ("1" + (self.instance_variable_get(variable.to_sym).to_s)).to_i)
|
|
|
|
# end
|
|
|
|
# }
|
|
|
|
# end
|
2014-04-04 21:30:40 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|