diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index 4bc6cd87..15f9ef8f 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -67,12 +67,12 @@ class CollegesController < ApplicationController user_extensions.`school_id`=#{@school.id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count) @teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count, - (SELECT count(c.id) FROM courses c, members m, member_roles mr WHERE c.id != 1309 and m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) and c.school_id = #{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count + (SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) and c.school_id = #{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count FROM `users`, user_extensions ue where users.id=ue.user_id and ue.identity=0 and ue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") # ).order("publish_shixun_count desc, experience desc").limit(10) @teachers = @teachers.map do |teacher| - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE c.id != 1309 and m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}") + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}") course_count = course_ids.size homeworks = HomeworkCommon.where(:homework_type => 4, :course_id => course_ids.map(&:id)) un_shixun_work_count = homeworks.where("publish_time > '#{Time.now}' or publish_time is null").count diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index c285fba7..2bbbd6ef 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -32,9 +32,8 @@ class CompetitionTeamsController < ApplicationController # todo:使用新版course_members course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01')) - .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) + .joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)') + .where(course_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').having('shixun_homework_count > 0') diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b830776b..19bf3039 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController course_ids = course_ids.present? ? course_ids.join(",") : -1 @courses = Course.where("courses.is_delete = 0 and courses.is_hidden = 0 #{course_ids == -1 ? "" : "and courses.id in (#{course_ids})"}").select("courses.id, courses.tea_id, courses.name, courses.is_public, courses.members_count, courses.homework_commons_count,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("courses.id = 1309 desc, a desc") elsif @order == "mine" - my_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9,10) AND m.user_id=#{@user.id} AND c.is_delete = 0") + my_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id AND m.role in (1,2,3,4) AND m.user_id=#{@user.id} AND c.is_delete = 0") course_ids = course_ids.present? ? my_course_ids.map(&:id) & course_ids : my_course_ids.map(&:id) course_ids = course_ids.size > 0 ? course_ids.join(",") : "-1" @courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_hidden = 0 and c.id in (#{course_ids}) order by c.id = 1309 desc, #{order_str} desc") @@ -894,7 +894,7 @@ class CoursesController < ApplicationController # @teacher_count = TeacherAndAssistantCount @course if @course.try(:id) != 1309 || User.current.admin? || User.current.try(:id) == 15582 - @teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7,9]).count + @teacher_count = @course.course_members.includes(:roles, :user).where("roles.id" => [3,7,9]).count else @teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7]).count end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 156ae951..98b58614 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1133,6 +1133,12 @@ end render :json => {:status => 1} end + def update_competition_text + text = CompetitionTextConfig.find(params[:id]) + text.update_attributes(name: params[:name], description: params[:description]) + render :json => {:status => 1} + end + def delete_competition_text ctc = CompetitionTextConfig.find params[:id] ctc.destroy @@ -2944,20 +2950,20 @@ end course_group = CourseGroup.where(:course_id => course.id, :name => group_name).first || CourseGroup.create(:name => group_name, :course_id => course.id) if group_name - member = course.members.where(:user_id => user.id).first + member = course.course_members.where(:user_id => user.id, :role => 4).first # 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班 - if member.present? && member.member_roles.pluck(:role_id).include?(10) && member.course_group_id != course_group.try(:id).to_i + if member.present? && member.course_group_id != course_group.try(:id).to_i member.update_column("course_group_id", course_group.try(:id).to_i) member_count += 1 elsif !member.present? - member = Member.new(:role_ids => [member_role], :user_id => user.id) - if member_role == 10 - StudentsForCourse.create(:student_id => user.id, :course_id => course.id) - end + member = CourseMember.new(:role => 4, :user_id => user.id) + # if member_role == 10 + # StudentsForCourse.create(:student_id => user.id, :course_id => course.id) + # end Tiding.create(:user_id => user.id, :trigger_user_id => course.tea_id, :container_id => course.id, :container_type => 'TeacherJoinCourse', :belong_container_id => course.id, :belong_container_type => "Course", :tiding_type => "System", :extra => member_role) member.course_group_id = course_group.try(:id).to_i - course.members << member + course.course_members << member member_count += 1 end @@ -4262,7 +4268,7 @@ end teacher_name = course.teacher ? course.teacher.show_real_name : "" sheet1[count_row,0] = course.id sheet1[count_row,1] = course.name - sheet1[count_row,2] = course.members.count + sheet1[count_row,2] = course.course_members_count sheet1[count_row,3] = course.attachments.count sheet1[count_row,4] = course.homework_commons.where(:homework_type => 1).count sheet1[count_row,5] = course.homework_commons.where(:homework_type => 4).count diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 744b1d1f..3fd3759a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2438,14 +2438,14 @@ class UsersController < ApplicationController case @type when "a_course" student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND sfc.student_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") - manage_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") + manage_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") course_ids = student_course_ids.map(&:id) + manage_course_ids.map(&:id) @objects = Course.where(:id => course_ids.uniq).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("updated_at #{order}") when "l_course" - student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND sfc.student_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") + student_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id and m.role = 4 AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") @objects = Course.where(:id => student_course_ids.map(&:id)).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("updated_at #{order}") when "p_course" - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{@user.id} AND c.is_delete = 0 AND c.is_end in #{status}") @objects = Course.where(:id => course_ids.map(&:id)).includes(:attachments, :teacher => [:user_extensions => [:school]]).order("id = 1309 desc, updated_at #{order}") when "a_shixun" shixun_ids = @user.shixun_members.map(&:shixun_id) + @user.myshixuns.map(&:shixun_id) diff --git a/app/models/competition_text_config.rb b/app/models/competition_text_config.rb index 25ddb28e..436818bf 100644 --- a/app/models/competition_text_config.rb +++ b/app/models/competition_text_config.rb @@ -1,4 +1,4 @@ class CompetitionTextConfig < ActiveRecord::Base - # attr_accessible :title, :body + attr_accessible :name, :description, :competition_id belongs_to :competition end diff --git a/app/models/course.rb b/app/models/course.rb index c6c6d3df..5068e38e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -33,6 +33,8 @@ class Course < ActiveRecord::Base belongs_to :syllabus belongs_to :course_list # has_many :bid + has_many :course_members, dependent: :destroy + has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" has_many :memberships, :class_name => 'Member' has_many :member_principals, :class_name => 'Member', @@ -290,12 +292,16 @@ class Course < ActiveRecord::Base # 课堂的老师不包括助教 def course_teachers - self.members.select{|m| m.roles.to_s.include?("Manager") || m.roles.to_s.include?("Teacher")} + self.course_members.where(:role => [1, 2]) end # 课堂的老师包括助教 def teachers - self.members.includes(:roles).where("roles.id" => [3,7,9]) + self.course_members.where(:role => [1, 2, 3]) + end + + def students + self.course_members.where(:role => [4]) end def self.visible_condition(user, options={}) diff --git a/app/models/course_group.rb b/app/models/course_group.rb index 9c80c85a..c5b66d87 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -1,6 +1,7 @@ class CourseGroup < ActiveRecord::Base # attr_accessible :title, :body belongs_to :course + has_many :course_members has_many :members has_many :memberships, :class_name => 'Member' has_many :member_principals, :class_name => 'Member', diff --git a/app/models/course_member.rb b/app/models/course_member.rb new file mode 100644 index 00000000..8de272a4 --- /dev/null +++ b/app/models/course_member.rb @@ -0,0 +1,7 @@ +class CourseMember < ActiveRecord::Base + # attr_accessible :title, :body + + belongs_to :course, counter_cache: true + belongs_to :user + belongs_to :course_group, counter_cache: true +end diff --git a/app/models/message.rb b/app/models/message.rb index 392bab48..9e516acb 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -54,6 +54,7 @@ class Message < ActiveRecord::Base belongs_to :reply, :class_name => 'Message', :foreign_key => 'reply_id' #has_one :message_detail, :dependent => :destroy + has_one :message_detail, dependent: :destroy #转发表 has_many :forwards, :as => :from, :dependent => :destroy @@ -102,7 +103,7 @@ class Message < ActiveRecord::Base } - safe_attributes 'subject', 'content', 'reply_id', 'root_id', 'visits' + safe_attributes 'subject', 'reply_id', 'root_id', 'visits' safe_attributes 'board_id','locked', 'sticky', :if => lambda {|message, user| if message.project @@ -115,7 +116,7 @@ class Message < ActiveRecord::Base } def description - self.content + message_detail.try(:content) end # def content diff --git a/app/models/message_detail.rb b/app/models/message_detail.rb new file mode 100644 index 00000000..a12a2b8f --- /dev/null +++ b/app/models/message_detail.rb @@ -0,0 +1,4 @@ +class MessageDetail < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :message, :touch => true +end diff --git a/app/models/tiding.rb b/app/models/tiding.rb index 177946d8..7204abc5 100644 --- a/app/models/tiding.rb +++ b/app/models/tiding.rb @@ -254,7 +254,7 @@ class Tiding < ActiveRecord::Base elsif self.tiding_type == "Comment" container.present? ? ("评论了你" + (container.parent.present? ? "的回复:" : "发布的项目issue:") + message_content(container.notes)) : "" else - "更新了Issue:#{container.issue.subject}" + container.present? ? "更新了Issue:#{container.try(:issue).try(:subject)}" : "" end when 'Issue' "指派了Issue给你:" + container.subject diff --git a/app/models/user.rb b/app/models/user.rb index 0e034d32..dbb77124 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,6 +97,8 @@ class User < Principal has_many :homework_evaluations, :dependent => :destroy has_many :syllabuses, :dependent => :destroy has_many :syllabus_members, :dependent => :destroy + + has_many :course_members, :dependent => :destroy #问卷相关关关系 has_many :poll_users, :dependent => :destroy has_many :poll_votes, :dependent => :destroy @@ -1125,7 +1127,7 @@ class User < Principal end def member_of_course?(course) - courses.to_a.include?(course) || User.current.business? + course.course_members.exists?(user_id: self.id) || User.current.business? end def member_of_contest?(contest) diff --git a/app/services/users_service.rb b/app/services/users_service.rb index d60de29c..6df15d2a 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -313,8 +313,8 @@ class UsersService limit = params[:limit]||5 page = params[:page].to_i offset = (page-1) * limit - courses = Course.find_by_sql("SELECT c.* FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND - mr.role_id in (3,7,9,10) AND + courses = Course.find_by_sql("SELECT c.* FROM courses c, course_members m WHERE m.course_id = c.id AND + m.role in (1,2,3,4) AND m.user_id=#{current_user.id} AND c.is_delete = 0 order by id desc limit #{limit} offset #{offset} ") # 如果还没有课程则显示示例课堂 courses = Course.where(:id => 1309) if courses.count == 0 diff --git a/app/views/competitions/_qg_second_opensource.html.erb b/app/views/competitions/_qg_second_opensource.html.erb index b7e878e9..ddaad572 100644 --- a/app/views/competitions/_qg_second_opensource.html.erb +++ b/app/views/competitions/_qg_second_opensource.html.erb @@ -4,54 +4,59 @@
<% index += 1 %> -<% @competition.competition_stages.each_with_index do |stage, i| %> -
- <% - first_section = stage.competition_stage_sections[0] - second_section = stage.competition_stage_sections[1] - %> -
- +
+
+

+ <%= @competition.competition_text_configs.first.try(:description) %> +

+
+
+<% index += 1 %> + +<% + first_stage = @competition.competition_stages.first + first_section = first_stage.competition_stage_sections.first + first_entry = first_section.competition_entries.first + is_start = Time.now > first_section.start_time + competition_url = User.current.logged? ? "#{first_entry.url}?eid=#{User.current.id}" : "#{first_entry.url}" + btn_url = is_start ? "#{competition_url}" : "javascript:void(0);" +%> +
+
+
<% index += 1 %> -<% end %>
<% index += 1 %>
<% index += 1 %>
+<% index += 1 %> +