diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 9ef935cf7..5b405a27a 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -2,14 +2,49 @@ class SchoolController < ApplicationController before_filter :require_admin, :only => :upload_logo - def upload_logo + def upload + uploaded_io = params[:logo] + school_id = 0 + schools = School.where("name = ?", params[:school]) + schools.each do |s| + school_id = s.id + end + + unless uploaded_io.nil? + File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file| + file.write(uploaded_io.read) + end + + s1 = School.find(school_id) + s1.logo_link = '/images/school/'+school_id.to_s+'.png' + s1.save + + + end + end + + def upload_logo + end def index end + + def get_province + @provinces = School.find_by_sql("select distinct province from schools") + + options = "" + + @provinces.each do |p| + options << "" + end + + render :text => options + + end def get_options @school = School.where("province = ?", params[:province]) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 9cc940bdd..281f6216d 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -8,6 +8,30 @@ class SoftapplicationsController < ApplicationController def index @softapplications = Softapplication.all + #new added fenyefunction + @limit = 5 + @softapplication_count = @softapplications.count + @softapplication_pages = Paginator.new @softapplication_count, @limit, params['page'] + @offset ||= @softapplication_pages.offset + #@softapplications = @softapplications[@offset,@limit] + #new added end + + #new added sort + if params[:softapplication_sort_type].present? + case params[:softapplication_sort_type] + when '0' + @softapplications = @softapplications[@offset, @limit] + @s_state = 0 + when '1' + @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] + @s_state = 1 + end + else + @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] + @s_state = 1 + end + #new added end + respond_to do |format| format.html # index.html.erb format.json { render json: @softapplications } @@ -16,8 +40,25 @@ class SoftapplicationsController < ApplicationController # GET /softapplications/1 # GET /softapplications/1.json + + def percent_of(num, percent) + num.to_f / percent.to_f * 100.0 + end + def show @softapplication = Softapplication.find(params[:id]) + # 打分统计 + stars_reates = @softapplication. + rates(:quality) + stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + stars_status = stars_reates.select("stars, count(*) as scount"). + group("stars") + + @stars_status_map = Hash.new(0.0) + stars_status.each do |star_status| + @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + percent_of(star_status.scount, stars_reates_count).to_s + "%" + end @jours = @softapplication.journals_for_messages.order('created_on DESC') @image_results = [] @softapplication.attachments.each do |f| diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 5e8eef074..c662c44f7 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -39,8 +39,36 @@ class WelcomeController < ApplicationController @courseCount = Project.course_entities.count @teacherCount = User.teacher.count @studentCount = User.student.count + @logoLink = logolink() end + + + def logolink() + id = params[:school_id] + logo_link = "" + if id.nil? and User.current.user_extensions.school.nil? + logo_link = '/images/transparent.png' + else + if id == "0" + logo_link = '/images/transparent.png' + 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 + + def contest end diff --git a/app/helpers/softapplications_helper.rb b/app/helpers/softapplications_helper.rb index e3cb6410d..fe78e9875 100644 --- a/app/helpers/softapplications_helper.rb +++ b/app/helpers/softapplications_helper.rb @@ -1,2 +1,18 @@ module SoftapplicationsHelper + def sort_softapplication(state) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '1'})) + content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '0'}, :class=>"selected"), :class=>"selected") + + when 1 + content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '1'}, :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '0'})) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end end + + diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 5b455a01b..43ee05db8 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -54,57 +54,111 @@ module UserScoreHelper watcher_count = Watcher.where("watchable_type = 'principal' AND watchable_id = ?", user.id).count end + + + def calculate_skill_count(user) - praise_count = 0 - tread_count = 0 + praise_count_l0 = 0 + praise_count_l1 = 0 + praise_count_l2 = 0 + tread_count_l0 = 0 + tread_count_l1 = 0 + tread_count_l2 = 0 issues = Issue.where('author_id = ?', user.id) issues.each do |i| - ptcs = PraiseTreadCache.where('object_id = ?', i.id) - ptcs.each do |p| - praise_count = praise_count + p.praise_num - tread_count = tread_count + p.tread_num + pts = PraiseTread.where('praise_tread_object_id = ?', i.id) + pts.each do |p| + templevel = calculate_level(User.find(p.user_id)) + + if templevel.to_i == 0 + if p.praise_or_tread == 1 + praise_count_l0 = praise_count_l0 + 1 + else + tread_count_l0 = tread_count_l0 + 1 + end + end + if templevel.to_i == 1 + if p.praise_or_tread == 1 + praise_count_l1 = praise_count_l1 + 1 + else + tread_count_l1 = tread_count_l1 + 1 + end + end + if templevel.to_i == 2 + if p.praise_or_tread == 1 + praise_count_l2 = praise_count_l2 + 1 + else + tread_count_l2 + tread_count_l2 + 1 + end + end end end + + + bids = Bid.where('author_id = ?', user.id) bids.each do |b| - ptcs = PraiseTreadCache.where('object_id = ?', b.id) + ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id) ptcs.each do |p| - praise_count = praise_count + p.praise_num - tread_count = tread_count + p.tread_num + templevel = calculate_level(User.find(p.user_id)) + + if templevel.to_i == 0 + if p.praise_or_tread == 1 + praise_count_l0 = praise_count_l0 + 1 + else + tread_count_l0 = tread_count_l0 + 1 + end + end + if templevel.to_i == 1 + if p.praise_or_tread == 1 + praise_count_l1 = praise_count_l1 + 1 + else + tread_count_l1 = tread_count_l1 + 1 + end + end + if templevel.to_i == 2 + if p.praise_or_tread == 1 + praise_count_l2 = praise_count_l2 + 1 + else + tread_count_l2 + tread_count_l2 + 1 + end + end end end contests = Contest.where('author_id = ?', user.id) contests.each do |c| - ptcs = PraiseTreadCache.where('object_id = ?', c.id) + ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id) ptcs.each do |p| - praise_count = praise_count + p.praise_num - tread_count = tread_count + p.tread_num + templevel = calculate_level(User.find(p.user_id)) + + if templevel.to_i == 0 + if p.praise_or_tread == 1 + praise_count_l0 = praise_count_l0 + 1 + else + tread_count_l0 = tread_count_l0 + 1 + end + end + if templevel.to_i == 1 + if p.praise_or_tread == 1 + praise_count_l1 = praise_count_l1 + 1 + else + tread_count_l1 = tread_count_l1 + 1 + end + end + if templevel.to_i == 2 + if p.praise_or_tread == 1 + praise_count_l2 = praise_count_l2 + 1 + else + tread_count_l2 + tread_count_l2 + 1 + end + end end end - level = calculate_level(user) - - skill_score = 0 - - if level == 0 - skill_score = praise_count - 0.5 * tread_count - end - if level == 1 - skill_score = 2 * praise_count - 1.5 * tread_count - end - if level == 2 - skill_socre = 3 * praise_count - 2.5 * tread_count - end - if level == 3 - skill_socre = 4 * praise_count - 3.5 * tread_count - end - if level == 4 - skill_socre = 5 * praise_count - 4.5 * tread_count - end # case level # when 0 skill_score = praise_count - 0.5 * tread_count @@ -114,12 +168,19 @@ module UserScoreHelper # when 4 skill_socre = 5 * praise_count - 4.5 * tread_count # end - + skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f + - 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count - skill_score = skill_score - 0.5 * tread_user_count - + skill_score = skill_score.to_f - tread_user_count.to_f + + + + + + + return skill_score @@ -135,7 +196,7 @@ module UserScoreHelper issues.each do |i| ptcs = PraiseTreadCache.where('object_id = ?', i.id) ptcs.each do |p| - if p.praise_num > max_praise_num + if p.praise_num.to_i > max_praise_num.to_i max_praise_num = p.praise_num end end @@ -145,7 +206,7 @@ module UserScoreHelper bids.each do |b| ptcs = PraiseTreadCache.where('object_id = ?', b.id) ptcs.each do |p| - if p.praise_num > max_praise_num + if p.praise_num.to_i > max_praise_num.to_i max_praise_num = p.praise_num end end @@ -155,7 +216,7 @@ module UserScoreHelper contests.each do |c| ptcs = PraiseTreadCache.where('object_id = ?', c.id) ptcs.each do |p| - if p.praise_num > max_praise_num + if p.praise_num.to_i > max_praise_num.to_i max_praise_num = p.praise_num end end diff --git a/app/views/contests/_list_softapplications.html.erb b/app/views/contests/_list_softapplications.html.erb index eb179718a..9b99b675c 100644 --- a/app/views/contests/_list_softapplications.html.erb +++ b/app/views/contests/_list_softapplications.html.erb @@ -14,7 +14,7 @@ 简介: - <%= c_softapplication.softapplication.description %> + <%= c_softapplication.softapplication.description.truncate(90, omission: '...') %>
diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 98befd091..7552b9941 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,4 +1,132 @@ + + <%=(@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>资源共享区 @@ -88,9 +216,7 @@
<% @preTags = %w|预设A 预设B 预设C 预设D 预设E 预设Z | %> -
<%#需要交由浏览器异步刷新,或者一次连表查询,n+1 查询问题搞不定%> - <%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"}%> -
+ <%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"}%>
diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index faff9e13c..9df56ee2f 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -1,6 +1,6 @@
-