diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index f39c7708..5b46986a 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -12,6 +12,34 @@ class CompetitionTeamsController < ApplicationController @team_user = User.current end + def show + return render_404 if @competition.identifier != 'gcc-course-2019' + + @team_user_ids = @team.team_members.pluck(:user_id) + + shixuns = Shixun.where(user_id: @team_user_ids, status: 2) + shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2') + shixuns = shixuns.joins('left join myshixuns on myshixuns.shixun_id = shixuns.id and exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + shixuns = shixuns.select('shixuns.id, shixuns.identifier, shixuns.user_id, shixuns.myshixuns_count, shixuns.name, shixuns.fork_from, sum(forked_shixuns.myshixuns_count) forked_myshixun_count') + @shixuns = shixuns.group('shixuns.id').order('shixuns.myshixuns_count desc').includes(:creator) + @myshixun_count_map = Myshixun.where(shixun_id: @shixuns.map(&:id)) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('shixun_id').count + + # todo:使用新版course_members + course_ids = Course.joins('join members on members.course_id = courses.id') + .joins('join member_roles on member_roles.member_id = members.id and member_roles.role_id in (3,7,9)') + .where(members: { user_id: @team_user_ids }).pluck(:id) + courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()') + @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') + .group('courses.id').order('shixun_homework_count desc') + + @course_myshixun_map = Myshixun.joins(student_works: :homework_common) + .where(homework_commons: { course_id: @courses.map(&:id) }) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('homework_commons.course_id').count + end + def search_teacher if params[:team] && params[:team] != "" @team = @competition.competition_teams.where(:id => params[:team]).first diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index 0e9fb376..a868cbf0 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -4,7 +4,7 @@ class CompetitionsController < ApplicationController :edit_md_content, :update_md_content, :new_competition_stage, :new_stage_section, :update_competition_stage] before_filter :find_inform, :only => [:edit_inform, :update_inform] - before_filter :require_login, :only => [:enroll_portal] + before_filter :require_login, :only => [:enroll_portal, :publish] skip_before_filter :verify_authenticity_token, :only => [:edit_rule] layout 'base_competition' @@ -25,7 +25,7 @@ class CompetitionsController < ApplicationController end def index - @competitions = Competition.where(:status => 1).reorder("online_time desc") + @competitions = Competition.where('status = 1 or published_at is not null').reorder("published_at desc, online_time desc") respond_to do |format| format.html { render :layout => "base_edu"} format.js @@ -438,10 +438,10 @@ class CompetitionsController < ApplicationController def online_switch if @competition.present? if @competition.status - @competition.update_attributes(:status => 0) + @competition.update_attributes(status: false, published_at: nil) @btn_html = "上架" else - @competition.update_attributes(:status => 1, :online_time => Time.now) + @competition.update_attributes(status: true, online_time: Time.now, published_at: nil) @btn_html = "下架" end end @@ -601,6 +601,12 @@ class CompetitionsController < ApplicationController @competition.competition_stage_sections.where(:id => params[:section_id]).destroy_all end + def publish + return render_403 unless admin_or_business? + + @competition.update_column(:published_at, Time.now) + end + private def chart_exp_score_mo myshixuns, s_time, e_time diff --git a/app/views/competition_teams/_competition_team_form.html.erb b/app/views/competition_teams/_competition_team_form.html.erb index fbba4618..c68cc3b2 100644 --- a/app/views/competition_teams/_competition_team_form.html.erb +++ b/app/views/competition_teams/_competition_team_form.html.erb @@ -24,13 +24,12 @@
+ 战队详情 + <%= link_to '返回', enroll_competition_path(@competition), class: 'color-grey-9 fr' %> +
+实训项目
+创建者 | +名称 | +学习人数 | +fork版的学习人数 | +有效作品数 | +经验值 | +
---|---|---|---|---|---|
<%= shixun.creator.show_real_name %> | ++ <%= link_to shixun_path(shixun), target: '_blank' do %> + <%= shixun.name %> + <% end %> + <% if shixun.fork_from.blank? %> + 原创 + <% end %> + | +<%= shixun.myshixuns_count.to_i.zero? ? '--' : shixun.myshixuns_count.to_i %> | +<%= shixun['forked_myshixun_count'].to_i.zero? ? '--' : shixun['forked_myshixun_count'].to_i %> | +<%= @myshixun_count_map.fetch(shixun.id, '--') %> | +-- | +
合计 | +<%= @shixuns.size %> | +<%= total_myshixun_count %> | +<%= total_forked_myshixun_count %> | +<%= @myshixun_count_map.values.reduce(:+) %> | +-- | +
翻转课堂
+创建者 | +名称 | +学生数量 | +发布的实训作业数量 | +有效作品数 | +经验值 | +
---|---|---|---|---|---|
<%= course.teachers.where(user_id: @team_user_ids).first.user.show_real_name %> | ++ <%= link_to course_path(course), target: '_blank' do %> + <%= course.name %> + <% end %> + | +<%= course.members_count %> | +<%= course['shixun_homework_count'].presence || '--' %> | +<%= @course_myshixun_map.fetch(course.id, '--') %> | +-- | +
合计 | +<%= @courses.size %> | +<%= total_members_count %> | +<%= total_shixun_homework_count %> | +<%= @course_myshixun_map.values.reduce(:+) %> | +-- | +
- 战队详情 - 返回 -
-实训项目
-创建者 | -名称 | -学习人数 | -fork版的学习人数 | -有效作品数 | -经验值 | -
---|---|---|---|---|---|
张三 | -- MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) - 原创 - | -1545 | -1246 | -111 | -54987 | -
合计 | -6 | -12万 | -11 | -22 | -33 | -
翻转课堂
-创建者 | -名称 | -学生数量 | -发布的实训作业数量 | -有效作品数 | -经验值 | -
---|---|---|---|---|---|
张三 | -- MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) - | -1545 | -1246 | -111 | -54987 | -
合计 | -6 | -12万 | -11 | -22 | -33 | -